Current section

Files

Jump to
inlay src inlay@ted.erl
Raw

src/inlay@ted.erl

-module(inlay@ted).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/inlay/ted.gleam").
-export([detect/1, render/2]).
-file("src/inlay/ted.gleam", 37).
-spec detect_talk(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect_talk(Url) ->
case gleam@uri:path_segments(erlang:element(6, Url)) of
[<<"talks"/utf8>>, Slug] ->
{some, {ted_talk, Slug}};
_ ->
none
end.
-file("src/inlay/ted.gleam", 8).
-spec detect(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect(Url) ->
case erlang:element(4, Url) of
{some, <<"www.ted.com"/utf8>>} ->
detect_talk(Url);
{some, <<"ted.com"/utf8>>} ->
detect_talk(Url);
_ ->
none
end.
-file("src/inlay/ted.gleam", 15).
-spec render(inlay@embed:embed(), inlay@embed:config()) -> {ok,
lustre@vdom@vnode:element(any())} |
{error, nil}.
render(Embed, Config) ->
case Embed of
{ted_talk, Slug} ->
Src = <<"https://embed.ted.com/talks/"/utf8, Slug/binary>>,
Aspect_ratio = case erlang:element(11, Config) of
{some, {ted_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>>,
<<"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"/utf8>>
)]
)};
_ ->
{error, nil}
end.