# This file defines various fragments of the blog, such as the header
# and footer, as functions that receive arguments to be templated into
# them.
#
# An entire post is rendered by `renderPost`, which assembles the
# fragments together in a runCommand execution.
{ depot, lib, pkgs, ... }:
let
inherit (builtins) filter map hasAttr replaceStrings;
inherit (pkgs) runCommandNoCC writeText;
inherit (depot.nix) renderMarkdown;
staticUrl = "https://static.tvl.fyi/${depot.web.static.drvHash}";
# Generate a post list for all listed, non-draft posts.
isDraft = post: (hasAttr "draft" post) && post.draft;
isUnlisted = post: (hasAttr "listed" post) && !post.listed;
escape = replaceStrings [ "<" ">" "&" "'" ] [ "<" ">" "&" "'" ];
header = name: title: ''
Note: This post is unlisted! Please do not share
the link to it without asking first.
'';
renderPost = { name, footer, ... }: post: runCommandNoCC "${post.key}.html" { } ''
cat ${writeText "header.html" (header name post.title)} > $out
# Write the post title & date
echo '
${escape post.title}
' >> $out
echo '' >> $out
${
# Add a warning to draft/unlisted posts to make it clear that
# people should not share the post.
if (isDraft post) then "cat ${draftWarning} >> $out"
else if (isUnlisted post) then "cat ${unlistedWarning} >> $out"
else "# Your ads could be here?"
}
# Write the actual post through cheddar's about-filter mechanism
cat ${renderMarkdown post.content} >> $out
echo '' >> $out
cat ${writeText "footer.html" (fullFooter footer)} >> $out
'';
in
{
inherit isDraft isUnlisted renderPost;
}