Current section

Files

Jump to
inlay src inlay@tiktok.erl
Raw

src/inlay@tiktok.erl

-module(inlay@tiktok).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/inlay/tiktok.gleam").
-export([detect/1, render/2]).
-file("src/inlay/tiktok.gleam", 45).
-spec detect_tiktok(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect_tiktok(Url) ->
case gleam@uri:path_segments(erlang:element(6, Url)) of
[Username, <<"video"/utf8>>, Id] ->
{some, {tik_tok_video, Username, Id}};
_ ->
none
end.
-file("src/inlay/tiktok.gleam", 8).
-spec detect(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect(Url) ->
case erlang:element(4, Url) of
{some, <<"tiktok.com"/utf8>>} ->
detect_tiktok(Url);
{some, <<"www.tiktok.com"/utf8>>} ->
detect_tiktok(Url);
_ ->
none
end.
-file("src/inlay/tiktok.gleam", 15).
-spec render(inlay@embed:embed(), inlay@embed:config()) -> {ok,
lustre@vdom@vnode:element(any())} |
{error, nil}.
render(Embed, _) ->
case Embed of
{tik_tok_video, Username, Id} ->
Cite_url = <<<<<<"https://www.tiktok.com/"/utf8, Username/binary>>/binary,
"/video/"/utf8>>/binary,
Id/binary>>,
{ok,
lustre@element@html:'div'(
[],
[lustre@element@html:blockquote(
[lustre@attribute:class(<<"tiktok-embed"/utf8>>),
lustre@attribute:attribute(
<<"cite"/utf8>>,
Cite_url
),
lustre@attribute:attribute(
<<"data-video-id"/utf8>>,
Id
)],
[lustre@element@html:a(
[lustre@attribute:href(Cite_url)],
[lustre@element:text(Cite_url)]
)]
),
lustre@element@html:script(
[lustre@attribute:src(
<<"https://www.tiktok.com/embed.js"/utf8>>
),
lustre@attribute:attribute(
<<"async"/utf8>>,
<<"true"/utf8>>
)],
<<""/utf8>>
)]
)};
_ ->
{error, nil}
end.