2021-12-27 14:38:35 +01:00
|
|
|
{ depot, lib, pkgs, ... }:
|
2020-03-09 16:14:49 +01:00
|
|
|
|
2021-12-27 14:38:35 +01:00
|
|
|
with depot.nix.yants;
|
|
|
|
|
|
|
|
let
|
2021-12-27 16:52:53 +01:00
|
|
|
inherit (builtins) hasAttr filter readFile;
|
2021-12-27 14:38:35 +01:00
|
|
|
inherit (depot.web.blog) post includePost renderPost;
|
2021-12-30 20:34:44 +01:00
|
|
|
inherit (depot.users.wpcarro.website) domain renderTemplate withBrand;
|
2022-01-09 04:09:48 +01:00
|
|
|
inherit (lib.lists) sort;
|
2021-12-27 14:38:35 +01:00
|
|
|
|
|
|
|
config = {
|
2021-12-30 20:34:44 +01:00
|
|
|
name = "bill and his blog";
|
|
|
|
baseUrl = "https://${domain}/blog";
|
2021-12-28 01:06:08 +01:00
|
|
|
footer = "";
|
2021-12-27 14:38:35 +01:00
|
|
|
};
|
|
|
|
|
2022-01-09 04:09:48 +01:00
|
|
|
posts = sort (x: y: x.date > y.date)
|
|
|
|
(filter includePost (list post (import ./posts.nix)));
|
2021-12-27 14:38:35 +01:00
|
|
|
|
2022-09-26 19:33:05 +02:00
|
|
|
rendered = pkgs.runCommand "blog-posts" { } ''
|
2020-03-09 16:14:49 +01:00
|
|
|
mkdir -p $out
|
2021-12-27 14:38:35 +01:00
|
|
|
|
|
|
|
${lib.concatStringsSep "\n" (map (post:
|
|
|
|
"cp ${renderPost config post} $out/${post.key}.html"
|
|
|
|
) posts)}
|
2020-03-09 16:14:49 +01:00
|
|
|
'';
|
2021-12-27 14:38:35 +01:00
|
|
|
|
2022-09-26 19:33:05 +02:00
|
|
|
formatDate = date: readFile (pkgs.runCommand "date" { } ''
|
2021-12-27 16:52:53 +01:00
|
|
|
date --date='@${toString date}' '+%B %e, %Y' > $out
|
|
|
|
'');
|
|
|
|
|
2021-12-30 20:34:44 +01:00
|
|
|
postsHtml = renderTemplate ./fragments/posts.html {
|
2021-12-28 01:06:08 +01:00
|
|
|
postsHtml = lib.concatStringsSep "\n" (map toPostHtml posts);
|
2021-12-30 20:34:44 +01:00
|
|
|
};
|
2021-12-28 01:06:08 +01:00
|
|
|
|
2021-12-30 20:34:44 +01:00
|
|
|
toPostHtml = post: readFile (renderTemplate ./fragments/post.html {
|
2021-12-28 01:17:20 +01:00
|
|
|
postUrl = "${config.baseUrl}/posts/${post.key}.html";
|
2021-12-28 01:06:08 +01:00
|
|
|
postTitle = post.title;
|
|
|
|
postDate = formatDate post.date;
|
|
|
|
});
|
2021-12-30 20:34:44 +01:00
|
|
|
in
|
2022-09-26 19:33:05 +02:00
|
|
|
pkgs.runCommand "blog" { } ''
|
2021-12-28 01:17:20 +01:00
|
|
|
mkdir -p $out
|
2021-12-30 20:34:44 +01:00
|
|
|
cp ${withBrand (readFile postsHtml)} $out/index.html
|
2021-12-28 01:17:20 +01:00
|
|
|
cp -r ${rendered} $out/posts
|
|
|
|
''
|