Current section

Files

Jump to
inlay src inlay@twitch.erl
Raw

src/inlay@twitch.erl

-module(inlay@twitch).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/inlay/twitch.gleam").
-export([detect/1, render/2]).
-file("src/inlay/twitch.gleam", 48).
-spec detect_twitch(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect_twitch(Url) ->
case gleam@uri:path_segments(erlang:element(6, Url)) of
[<<"videos"/utf8>>, Id] ->
{some, {twitch_video, Id}};
[Name] ->
{some, {twitch_channel, Name}};
_ ->
none
end.
-file("src/inlay/twitch.gleam", 8).
-spec detect(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect(Url) ->
case erlang:element(4, Url) of
{some, <<"twitch.tv"/utf8>>} ->
detect_twitch(Url);
{some, <<"www.twitch.tv"/utf8>>} ->
detect_twitch(Url);
_ ->
none
end.
-file("src/inlay/twitch.gleam", 15).
-spec render(inlay@embed:embed(), inlay@embed:config()) -> {ok,
lustre@vdom@vnode:element(any())} |
{error, nil}.
render(Embed, Config) ->
Parent = case erlang:element(9, Config) of
{some, {twitch_config, P, _}} ->
P;
none ->
<<"localhost"/utf8>>
end,
Aspect_ratio = case erlang:element(9, Config) of
{some, {twitch_config, _, {some, R}}} ->
R;
_ ->
<<"56.25%"/utf8>>
end,
case Embed of
{twitch_channel, Name} ->
Src = <<<<<<"https://player.twitch.tv/?channel="/utf8, Name/binary>>/binary,
"&parent="/utf8>>/binary,
Parent/binary>>,
{ok,
inlay@iframe:responsive(
Src,
Aspect_ratio,
[lustre@attribute:attribute(
<<"allowfullscreen"/utf8>>,
<<"true"/utf8>>
)]
)};
{twitch_video, Id} ->
Src@1 = <<<<<<"https://player.twitch.tv/?video="/utf8, Id/binary>>/binary,
"&parent="/utf8>>/binary,
Parent/binary>>,
{ok,
inlay@iframe:responsive(
Src@1,
Aspect_ratio,
[lustre@attribute:attribute(
<<"allowfullscreen"/utf8>>,
<<"true"/utf8>>
)]
)};
_ ->
{error, nil}
end.