From 15b871806b5ceb0a1c6f563e02c1ef79ee761412 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 8 Feb 2020 13:33:13 +0000 Subject: feat(web/blog): Add Nix-based static blog generator This introduces a derivation which builds an instance of nginx statically serving my blog posts, though as of now no indexes are being generated and no XML feed is available. This is just the initial draft of this setup and not yet what shall be yielded in the end. --- web/blog/fragments.nix | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 web/blog/fragments.nix (limited to 'web/blog/fragments.nix') diff --git a/web/blog/fragments.nix b/web/blog/fragments.nix new file mode 100644 index 000000000000..2c9127b7f713 --- /dev/null +++ b/web/blog/fragments.nix @@ -0,0 +1,81 @@ +# 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 actual post + echo '

${escape post.title}

' >> $out + echo '' >> $out + 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; +} -- cgit 1.4.1