# 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 overview is rendered by 'postList'. { pkgs, lib, ... }: let inherit (builtins) filter map hasAttr replaceStrings toFile; inherit (pkgs.third_party) runCommandNoCC writeText; escape = replaceStrings [ "<" ">" "&" "'" ] [ "<" ">" "&" "'" ]; header = title: '' tazjin's blog${lib.optionalString (title != "") ( ": " + (escape title) )}

tazjin's blog


''; footer = ''
''; 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 # Write the actual post through cheddar's about-filter mechanism cat ${post.content} | ${pkgs.tools.cheddar}/bin/cheddar --about-filter ${post.content} >> $out echo '
' >> $out cat ${toFile "footer.html" footer} >> $out ''; # Generate a post list for all listed, non-draft posts. isDraft = post: (hasAttr "draft" post) && post.draft; isUnlisted = post: (hasAttr "listed" post) && !post.listed; includePost = post: !(isDraft post) && !(isUnlisted post); indexEntry= post: "
  • a blog post
  • "; blogIndex = posts: writeText "blog-index.html" (lib.concatStrings ( [ (header "") "" footer ])); in { inherit blogIndex renderPost; }