Current section
Files
Jump to
Current section
Files
src/webls@robots.erl
-module(webls@robots).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/webls/robots.gleam").
-export([to_string/1, config/1, with_config_robots/2, with_config_robot/2, robot/1, with_robot_allowed_routes/2, with_robot_allowed_route/2, with_robot_disallowed_routes/2, with_robot_disallowed_route/2]).
-export_type([robots_config/0, robot/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type robots_config() :: {robots_config, binary(), list(robot())}.
-type robot() :: {robot, binary(), list(binary()), list(binary())}.
-file("src/webls/robots.gleam", 16).
-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,
"\n"/utf8>>/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>>.
-file("src/webls/robots.gleam", 6).
-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>>.
-file("src/webls/robots.gleam", 34).
?DOC(" Creates a robots config with a sitemap url\n").
-spec config(binary()) -> robots_config().
config(Sitemap_url) ->
{robots_config, Sitemap_url, []}.
-file("src/webls/robots.gleam", 39).
?DOC(" Adds a list of robots to the robots config\n").
-spec with_config_robots(robots_config(), list(robot())) -> robots_config().
with_config_robots(Config, Robots) ->
{robots_config,
erlang:element(2, Config),
lists:append([erlang:element(3, Config), Robots])}.
-file("src/webls/robots.gleam", 47).
?DOC(" Adds a robot to the robots config\n").
-spec with_config_robot(robots_config(), robot()) -> robots_config().
with_config_robot(Config, Robot) ->
{robots_config,
erlang:element(2, Config),
[Robot | erlang:element(3, Config)]}.
-file("src/webls/robots.gleam", 52).
?DOC(" Creates a robot policy\n").
-spec robot(binary()) -> robot().
robot(User_agent) ->
{robot, User_agent, [], []}.
-file("src/webls/robots.gleam", 57).
?DOC(" Adds a list of allowed routes to the robot policy\n").
-spec with_robot_allowed_routes(robot(), list(binary())) -> robot().
with_robot_allowed_routes(Robot, Routes) ->
{robot,
erlang:element(2, Robot),
lists:append([erlang:element(3, Robot), Routes]),
erlang:element(4, Robot)}.
-file("src/webls/robots.gleam", 62).
?DOC(" Adds a allowed route to the robot policy\n").
-spec with_robot_allowed_route(robot(), binary()) -> robot().
with_robot_allowed_route(Robot, Route) ->
{robot,
erlang:element(2, Robot),
[Route | erlang:element(3, Robot)],
erlang:element(4, Robot)}.
-file("src/webls/robots.gleam", 67).
?DOC(" Adds a list of disallowed routes to the robot policy\n").
-spec with_robot_disallowed_routes(robot(), list(binary())) -> robot().
with_robot_disallowed_routes(Robot, Routes) ->
{robot,
erlang:element(2, Robot),
erlang:element(3, Robot),
lists:append([erlang:element(4, Robot), Routes])}.
-file("src/webls/robots.gleam", 75).
?DOC(" Adds a disallowed route to the robot policy\n").
-spec with_robot_disallowed_route(robot(), binary()) -> robot().
with_robot_disallowed_route(Robot, Route) ->
{robot,
erlang:element(2, Robot),
erlang:element(3, Robot),
[Route | erlang:element(4, Robot)]}.