Current section
Files
Jump to
Current section
Files
src/inlay@provider@ted.erl
-module(inlay@provider@ted).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/inlay/provider/ted.gleam").
-export([render/2, detect/1]).
-file("src/inlay/provider/ted.gleam", 15).
-spec render(inlay@embed:embed(), inlay@embed:config()) -> lustre@vdom@vnode:element(any()).
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,
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>>
)]
);
_ ->
erlang:error(#{gleam_error => panic,
message => <<"unreachable"/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"inlay/provider/ted"/utf8>>,
function => <<"render"/utf8>>,
line => 31})
end.
-file("src/inlay/provider/ted.gleam", 35).
-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/provider/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.