# 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. # # The post index is generated by //web/homepage, not by this code. { depot, lib, ... }: let inherit (builtins) filter map hasAttr replaceStrings toFile; inherit (depot.third_party) runCommandNoCC writeText; # 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 = title: '' tazjin's blog: ${escape title}

tazjin's interblag


''; footer = ''
''; draftWarning = toFile "draft.html" ''

Note: This post is a draft! Please do not share the link to it without asking me first.


''; unlistedWarning = toFile "unlisted.html" ''

Note: This post is unlisted! Please do not share the link to it without asking me first.


''; renderPost = post: runCommandNoCC "${post.key}.html" {} '' cat ${toFile "header.html" (header 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 ${post.content} | ${depot.tools.cheddar}/bin/cheddar --about-filter ${post.content} >> $out echo '
' >> $out cat ${toFile "footer.html" footer} >> $out ''; in { inherit renderPost isDraft isUnlisted; }