Packages
arctic
2.0.0
11.0.10
11.0.9
11.0.8
11.0.7
11.0.6
11.0.6-z6
11.0.6-z5
11.0.6-z4
11.0.6-z3
11.0.6-z2
11.0.6-z1
11.0.6-gamma
11.0.6-delta
11.0.6-beta
11.0.6-alpha
11.0.5
11.0.4
11.0.3
11.0.2
11.0.1
11.0.0
11.0.0-alpha5
11.0.0-alpha4
11.0.0-alpha3
11.0.0-alpha2
11.0.0-alpha
10.0.1
10.0.0
10.0.0-alpha2
10.0.0-alpha
9.0.5
9.0.4
9.0.3
9.0.2
9.0.0
8.0.0
7.0.0
6.0.0
5.0.0
4.0.0
3.0.0
2.0.0
1.0.1
1.0.0
A friendly web framework for fast response times and a lightweight or serverless backend, written in Gleam!
Current section
Files
Jump to
Current section
Files
src/build@build.erl
-module(build@build).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([build/2]).
-export_type([processed_collection/0]).
-type processed_collection() :: {processed_collection,
arctic:collection(),
list(arctic:page())}.
-spec read_collection(arctic:collection()) -> {ok, list(arctic:page())} |
{error, snag:snag()}.
read_collection(Collection) ->
gleam@result:'try'(
begin
_pipe = simplifile:get_files(erlang:element(2, Collection)),
gleam@result:map_error(
_pipe,
fun(Err) ->
snag:new(
<<<<<<<<"couldn't get files in `"/utf8,
(erlang:element(2, Collection))/binary>>/binary,
"` ("/utf8>>/binary,
(simplifile:describe_error(Err))/binary>>/binary,
")"/utf8>>
)
end
)
end,
fun(Paths) ->
_pipe@1 = gleam@list:try_fold(
Paths,
[],
fun(So_far, Path) ->
gleam@result:'try'(
gleam@result:map_error(
simplifile:read(Path),
fun(Err@1) ->
snag:new(
<<<<<<<<"could not load file `"/utf8,
Path/binary>>/binary,
"` ("/utf8>>/binary,
(simplifile:describe_error(Err@1))/binary>>/binary,
")"/utf8>>
)
end
),
fun(Content) ->
gleam@result:'try'(
(erlang:element(3, Collection))(Content),
fun(P) -> {ok, [P | So_far]} end
)
end
)
end
),
gleam@result:map(_pipe@1, fun lists:reverse/1)
end
).
-spec process(list(arctic:collection())) -> {ok, list(processed_collection())} |
{error, snag:snag()}.
process(Collections) ->
gleam@list:try_fold(
Collections,
[],
fun(Rest, Collection) ->
gleam@result:'try'(
read_collection(Collection),
fun(Pages_unsorted) ->
Pages = gleam@list:sort(
Pages_unsorted,
fun(P, Q) -> (erlang:element(3, P))(Q) end
),
{ok, [{processed_collection, Collection, Pages} | Rest]}
end
)
end
).
-spec build(arctic:config(), list(arctic:collection())) -> {ok, nil} |
{error, snag:snag()}.
build(Config, Collections) ->
gleam@result:'try'(
process(Collections),
fun(Processed_collections) ->
gleam@result:'try'(
begin
_pipe = lustre@ssg:new(<<"site"/utf8>>),
_pipe@1 = lustre@ssg:use_index_routes(_pipe),
_pipe@2 = lustre@ssg:add_static_route(
_pipe@1,
<<"/"/utf8>>,
(erlang:element(2, Config))(Collections)
),
_pipe@3 = gleam@list:fold(
erlang:element(3, Config),
_pipe@2,
fun(Ssg_config, Page) ->
lustre@ssg:add_static_route(
Ssg_config,
<<"/"/utf8, (erlang:element(2, Page))/binary>>,
erlang:element(3, Page)
)
end
),
gleam@list:try_fold(
Processed_collections,
_pipe@3,
fun(Ssg_config@1, Processed) ->
Ssg_config2 = case erlang:element(
4,
erlang:element(2, Processed)
) of
{some, Render} ->
lustre@ssg:add_static_route(
Ssg_config@1,
<<"/"/utf8,
(erlang:element(
2,
erlang:element(2, Processed)
))/binary>>,
Render(erlang:element(3, Processed))
);
none ->
Ssg_config@1
end,
_pipe@4 = gleam@list:fold(
erlang:element(3, Processed),
Ssg_config2,
fun(S, P) ->
lustre@ssg:add_static_route(
S,
<<<<<<"/"/utf8,
(erlang:element(
2,
erlang:element(
2,
Processed
)
))/binary>>/binary,
"/"/utf8>>/binary,
(erlang:element(2, P))/binary>>,
erlang:element(4, P)
)
end
),
{ok, _pipe@4}
end
)
end,
fun(Ssg_config@2) ->
gleam@result:'try'(
begin
_pipe@5 = lustre@ssg:build(Ssg_config@2),
gleam@result:map_error(
_pipe@5,
fun(Err) -> case Err of
{cannot_create_temp_directory, File_err} ->
snag:new(
<<<<"couldn't create temp directory ("/utf8,
(simplifile:describe_error(
File_err
))/binary>>/binary,
")"/utf8>>
);
{cannot_write_static_asset,
File_err@1,
Path} ->
snag:new(
<<<<<<<<"couldn't put asset at `"/utf8,
Path/binary>>/binary,
"` ("/utf8>>/binary,
(simplifile:describe_error(
File_err@1
))/binary>>/binary,
")"/utf8>>
);
{cannot_generate_route,
File_err@2,
Path@1} ->
snag:new(
<<<<<<<<"couldn't generate `"/utf8,
Path@1/binary>>/binary,
"` ("/utf8>>/binary,
(simplifile:describe_error(
File_err@2
))/binary>>/binary,
")"/utf8>>
);
{cannot_write_to_output_dir, File_err@3} ->
snag:new(
<<<<"couldn't move from temp directory to output directory ("/utf8,
(simplifile:describe_error(
File_err@3
))/binary>>/binary,
")"/utf8>>
);
{cannot_cleanup_temp_dir, File_err@4} ->
snag:new(
<<<<"couldn't remove temp directory ("/utf8,
(simplifile:describe_error(
File_err@4
))/binary>>/binary,
")"/utf8>>
)
end end
)
end,
fun(_) ->
gleam@result:'try'(
begin
_pipe@6 = simplifile:create_directory(
<<"site/public"/utf8>>
),
gleam@result:map_error(
_pipe@6,
fun(Err@1) ->
snag:new(
<<<<"couldn't create directory `site/public` ("/utf8,
(simplifile:describe_error(
Err@1
))/binary>>/binary,
")"/utf8>>
)
end
)
end,
fun(_) ->
gleam@result:'try'(
begin
_pipe@7 = simplifile:copy_directory(
<<"public"/utf8>>,
<<"site/public"/utf8>>
),
gleam@result:map_error(
_pipe@7,
fun(Err@2) ->
snag:new(
<<<<"couldn't copy `public` to `site/public` ("/utf8,
(simplifile:describe_error(
Err@2
))/binary>>/binary,
")"/utf8>>
)
end
)
end,
fun(_) ->
gleam@result:'try'(
begin
_pipe@8 = simplifile:create_file(
<<"site/public/feed.rss"/utf8>>
),
gleam@result:map_error(
_pipe@8,
fun(Err@3) ->
snag:new(
<<<<"couldn't create file `site/public/feed.rss` ("/utf8,
(simplifile:describe_error(
Err@3
))/binary>>/binary,
")"/utf8>>
)
end
)
end,
fun(_) ->
gleam@list:try_each(
Processed_collections,
fun(Processed@1) ->
case erlang:element(
5,
erlang:element(
2,
Processed@1
)
) of
{some, Render@1} ->
_pipe@9 = simplifile:write(
<<"site/public/feed.rss"/utf8>>,
Render@1(
erlang:element(
3,
Processed@1
)
)
),
gleam@result:map_error(
_pipe@9,
fun(
Err@4
) ->
snag:new(
<<<<"couldn't write to `site/public/feed.rss` ("/utf8,
(simplifile:describe_error(
Err@4
))/binary>>/binary,
")"/utf8>>
)
end
);
none ->
{ok, nil}
end
end
)
end
)
end
)
end
)
end
)
end
)
end
).