Current section

Files

Jump to
webls src webls@robots.erl
Raw

src/webls@robots.erl

-module(webls@robots).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([to_string/1]).
-export_type([robots_config/0, robot/0]).
-type robots_config() :: {robots_config, binary(), list(robot())}.
-type robot() :: {robot, binary(), list(binary()), list(binary())}.
-spec robot_to_string(robot()) -> binary().
robot_to_string(Robot) ->
<<<<<<<<"User-agent: "/utf8, (erlang:element(2, Robot))/binary>>/binary,
"\n"/utf8>>/binary,
(begin
_pipe = erlang:element(3, Robot),
_pipe@1 = gleam@list:map(
_pipe,
fun(Route) -> <<"Allow: "/utf8, Route/binary>> end
),
_pipe@2 = gleam@list:reduce(
_pipe@1,
fun(Acc, Line) ->
<<<<Acc/binary, "\n"/utf8>>/binary, Line/binary>>
end
),
gleam@result:unwrap(_pipe@2, <<""/utf8>>)
end)/binary>>/binary,
(begin
_pipe@3 = erlang:element(4, Robot),
_pipe@4 = gleam@list:map(
_pipe@3,
fun(Route@1) -> <<"Disallow: "/utf8, Route@1/binary>> end
),
_pipe@5 = gleam@list:reduce(
_pipe@4,
fun(Acc@1, Line@1) ->
<<<<Acc@1/binary, "\n"/utf8>>/binary, Line@1/binary>>
end
),
gleam@result:unwrap(_pipe@5, <<""/utf8>>)
end)/binary>>.
-spec to_string(robots_config()) -> binary().
to_string(Config) ->
<<<<<<"Sitemap: "/utf8, (erlang:element(2, Config))/binary>>/binary,
"\n\n"/utf8>>/binary,
(begin
_pipe = erlang:element(3, Config),
_pipe@2 = gleam@list:map(_pipe, fun(Robot) -> _pipe@1 = Robot,
robot_to_string(_pipe@1) end),
_pipe@3 = gleam@list:reduce(
_pipe@2,
fun(Acc, Line) ->
<<<<Acc/binary, "\n\n"/utf8>>/binary, Line/binary>>
end
),
gleam@result:unwrap(_pipe@3, <<""/utf8>>)
end)/binary>>.