Current section

Files

Jump to
inlay src inlay@instagram.erl
Raw

src/inlay@instagram.erl

-module(inlay@instagram).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/inlay/instagram.gleam").
-export([detect/1, render/2]).
-file("src/inlay/instagram.gleam", 50).
-spec detect_instagram(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect_instagram(Url) ->
case gleam@uri:path_segments(erlang:element(6, Url)) of
[<<"p"/utf8>>, Id] ->
{some, {instagram_post, post, Id}};
[<<"p"/utf8>>, Id@1, <<""/utf8>>] ->
{some, {instagram_post, post, Id@1}};
[<<"reel"/utf8>>, Id@2] ->
{some, {instagram_post, reel, Id@2}};
[<<"reel"/utf8>>, Id@3, <<""/utf8>>] ->
{some, {instagram_post, reel, Id@3}};
[<<"tv"/utf8>>, Id@4] ->
{some, {instagram_post, t_v, Id@4}};
[<<"tv"/utf8>>, Id@5, <<""/utf8>>] ->
{some, {instagram_post, t_v, Id@5}};
_ ->
none
end.
-file("src/inlay/instagram.gleam", 8).
-spec detect(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()).
detect(Url) ->
case erlang:element(4, Url) of
{some, <<"instagram.com"/utf8>>} ->
detect_instagram(Url);
{some, <<"www.instagram.com"/utf8>>} ->
detect_instagram(Url);
_ ->
none
end.
-file("src/inlay/instagram.gleam", 15).
-spec render(inlay@embed:embed(), inlay@embed:config()) -> {ok,
lustre@vdom@vnode:element(any())} |
{error, nil}.
render(Embed, _) ->
case Embed of
{instagram_post, Post_type, Id} ->
Type_segment = case Post_type of
post ->
<<"p"/utf8>>;
reel ->
<<"reel"/utf8>>;
t_v ->
<<"tv"/utf8>>
end,
Permalink = <<<<<<<<"https://www.instagram.com/"/utf8,
Type_segment/binary>>/binary,
"/"/utf8>>/binary,
Id/binary>>/binary,
"/"/utf8>>,
{ok,
lustre@element@html:'div'(
[],
[lustre@element@html:blockquote(
[lustre@attribute:class(<<"instagram-media"/utf8>>),
lustre@attribute:attribute(
<<"data-instgrm-permalink"/utf8>>,
Permalink
)],
[lustre@element@html:a(
[lustre@attribute:href(Permalink)],
[lustre@element:text(Permalink)]
)]
),
lustre@element@html:script(
[lustre@attribute:src(
<<"https://www.instagram.com/embed.js"/utf8>>
),
lustre@attribute:attribute(
<<"async"/utf8>>,
<<"true"/utf8>>
)],
<<""/utf8>>
)]
)};
_ ->
{error, nil}
end.