Current section
Files
Jump to
Current section
Files
src/inlay@provider@soundcloud.erl
-module(inlay@provider@soundcloud).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/inlay/provider/soundcloud.gleam").
-export([render/2, detect/1]).
-file("src/inlay/provider/soundcloud.gleam", 16).
-spec render(inlay@embed:embed(), inlay@embed:config()) -> lustre@vdom@vnode:element(any()).
render(Embed, Config) ->
case Embed of
{sound_cloud_track, Path} ->
{Width, Height} = case erlang:element(12, Config) of
{some, {sound_cloud_config, W, H}} ->
{gleam@option:unwrap(W, 300), gleam@option:unwrap(H, 166)};
none ->
{300, 166}
end,
Encoded_url = gleam_stdlib:percent_encode(
<<"https://soundcloud.com"/utf8, Path/binary>>
),
Src = <<"https://w.soundcloud.com/player/?url="/utf8,
Encoded_url/binary>>,
lustre@element@html:'div'(
[],
[lustre@element@html:iframe(
[lustre@attribute:src(Src),
lustre@attribute:width(Width),
lustre@attribute:height(Height),
lustre@attribute:attribute(
<<"frameborder"/utf8>>,
<<"0"/utf8>>
),
lustre@attribute:attribute(
<<"allow"/utf8>>,
<<"autoplay"/utf8>>
),
lustre@attribute:attribute(
<<"loading"/utf8>>,
<<"lazy"/utf8>>
)]
)]
);
_ ->
erlang:error(#{gleam_error => panic,
message => <<"unreachable"/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"inlay/provider/soundcloud"/utf8>>,
function => <<"render"/utf8>>,
line => 39})
end.
-file("src/inlay/provider/soundcloud.gleam", 43).
-spec detect_soundcloud(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect_soundcloud(Url) ->
case gleam@uri:path_segments(erlang:element(6, Url)) of
[_, _] ->
{some, {sound_cloud_track, erlang:element(6, Url)}};
[_, <<"sets"/utf8>>, _] ->
{some, {sound_cloud_track, erlang:element(6, Url)}};
_ ->
none
end.
-file("src/inlay/provider/soundcloud.gleam", 8).
-spec detect(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect(Url) ->
case erlang:element(4, Url) of
{some, <<"soundcloud.com"/utf8>>} ->
detect_soundcloud(Url);
{some, <<"www.soundcloud.com"/utf8>>} ->
detect_soundcloud(Url);
_ ->
none
end.