Current section

Files

Jump to
webls src webls@rss.erl
Raw

src/webls@rss.erl

-module(webls@rss).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([to_string/1]).
-export_type([rss_channel/0, rss_item/0]).
-type rss_channel() :: {rss_channel,
binary(),
binary(),
binary(),
list(rss_item())}.
-type rss_item() :: {rss_item,
binary(),
binary(),
binary(),
birl:time(),
gleam@option:option(binary()),
{binary(), gleam@option:option(boolean())}}.
-spec rss_item_to_string(rss_item()) -> binary().
rss_item_to_string(Item) ->
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<item>\n"/utf8, "<title>"/utf8>>/binary,
(erlang:element(
2,
Item
))/binary>>/binary,
"</title>\n"/utf8>>/binary,
"<link>"/utf8>>/binary,
(erlang:element(3, Item))/binary>>/binary,
"</link>\n"/utf8>>/binary,
"<description>"/utf8>>/binary,
(erlang:element(4, Item))/binary>>/binary,
"</description>\n"/utf8>>/binary,
"<pubDate>"/utf8>>/binary,
(begin
_pipe = erlang:element(5, Item),
birl:to_iso8601(_pipe)
end)/binary>>/binary,
"</pubDate>\n"/utf8>>/binary,
(case erlang:element(6, Item) of
{some, Author} ->
<<<<"<author>"/utf8, Author/binary>>/binary,
"</author>\n"/utf8>>;
_ ->
<<""/utf8>>
end)/binary>>/binary,
(case erlang:element(7, Item) of
{Guid, {some, Is_permalink}} ->
<<<<<<<<"<guid isPermaLink=\""/utf8, (case Is_permalink of
true ->
<<"true"/utf8>>;
false ->
<<"false"/utf8>>
end)/binary>>/binary, "\">"/utf8>>/binary, Guid/binary>>/binary, "</guid>\n"/utf8>>;
_ ->
<<""/utf8>>
end)/binary>>/binary,
"</item>"/utf8>>.
-spec channel_to_string(rss_channel()) -> binary().
channel_to_string(Channel) ->
Channel_items = begin
_pipe = erlang:element(5, Channel),
_pipe@2 = gleam@list:map(_pipe, fun(Rss_item) -> _pipe@1 = Rss_item,
rss_item_to_string(_pipe@1) end),
_pipe@3 = gleam@list:reduce(
_pipe@2,
fun(Acc, Rss_item_string) ->
<<<<Acc/binary, "\n"/utf8>>/binary, Rss_item_string/binary>>
end
),
gleam@result:unwrap(_pipe@3, <<""/utf8>>)
end,
<<<<<<<<<<<<<<<<<<<<<<"\n<channel>\n"/utf8, "<title>"/utf8>>/binary,
(erlang:element(2, Channel))/binary>>/binary,
"</title>\n"/utf8>>/binary,
"<description>"/utf8>>/binary,
(erlang:element(3, Channel))/binary>>/binary,
"</description>\n"/utf8>>/binary,
"<link>"/utf8>>/binary,
(erlang:element(4, Channel))/binary>>/binary,
"</link>\n"/utf8>>/binary,
Channel_items/binary>>/binary,
"</channel>"/utf8>>.
-spec to_string(list(rss_channel())) -> binary().
to_string(Channels) ->
Channel_content = begin
_pipe = Channels,
_pipe@2 = gleam@list:map(_pipe, fun(Channel) -> _pipe@1 = Channel,
channel_to_string(_pipe@1) end),
_pipe@3 = gleam@list:reduce(
_pipe@2,
fun(Acc, Channel_string) ->
<<<<Acc/binary, "\n"/utf8>>/binary, Channel_string/binary>>
end
),
gleam@result:unwrap(_pipe@3, <<""/utf8>>)
end,
<<<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rss version=\"2.0\">"/utf8,
Channel_content/binary>>/binary,
"\n</rss>"/utf8>>.