Current section

Files

Jump to
inlay src inlay@vimeo.erl
Raw

src/inlay@vimeo.erl

-module(inlay@vimeo).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/inlay/vimeo.gleam").
-export([detect/1, render/2]).
-file("src/inlay/vimeo.gleam", 48).
-spec detect_vimeo(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect_vimeo(Url) ->
case gleam@uri:path_segments(erlang:element(6, Url)) of
[Id] ->
{some, {vimeo_video, Id, none}};
[Id@1, Hash] ->
{some, {vimeo_video, Id@1, {some, Hash}}};
_ ->
none
end.
-file("src/inlay/vimeo.gleam", 8).
-spec detect(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect(Url) ->
case erlang:element(4, Url) of
{some, <<"vimeo.com"/utf8>>} ->
detect_vimeo(Url);
{some, <<"www.vimeo.com"/utf8>>} ->
detect_vimeo(Url);
_ ->
none
end.
-file("src/inlay/vimeo.gleam", 15).
-spec render(inlay@embed:embed(), inlay@embed:config()) -> {ok,
lustre@vdom@vnode:element(any())} |
{error, nil}.
render(Embed, Config) ->
case Embed of
{vimeo_video, Id, Privacy_hash} ->
Base = <<"https://player.vimeo.com/video/"/utf8, Id/binary>>,
Dnt = case erlang:element(3, Config) of
{some, {vimeo_config, true, _}} ->
true;
_ ->
false
end,
Params = case {Dnt, Privacy_hash} of
{true, {some, H}} ->
<<"?dnt=1&h="/utf8, H/binary>>;
{true, none} ->
<<"?dnt=1"/utf8>>;
{false, {some, H@1}} ->
<<"?h="/utf8, H@1/binary>>;
{false, none} ->
<<""/utf8>>
end,
Src = <<Base/binary, Params/binary>>,
Aspect_ratio = case erlang:element(3, Config) of
{some, {vimeo_config, _, {some, R}}} ->
R;
_ ->
<<"56.25%"/utf8>>
end,
{ok,
inlay@iframe:responsive(
Src,
Aspect_ratio,
[lustre@attribute:attribute(
<<"allowfullscreen"/utf8>>,
<<"true"/utf8>>
),
lustre@attribute:attribute(
<<"allow"/utf8>>,
<<"autoplay; fullscreen; picture-in-picture"/utf8>>
)]
)};
_ ->
{error, nil}
end.