From bbf92dcdeaaf8bd8ab43fdd167f0709bb8840eb6 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 2 Nov 2021 14:34:20 +0100 Subject: [PATCH] refactor(web/blog): Configurable blog name and footer Required for actually using this generically for the TVL blog. Change-Id: I92d8d10341f9ab4f92c90f7976be261b3255a0f0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3768 Tested-by: BuildkiteCI Reviewed-by: sterni --- users/tazjin/blog/default.nix | 16 +++++++++++++++- web/blog/default.nix | 8 +++----- web/blog/fragments.nix | 30 +++++++++++------------------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/users/tazjin/blog/default.nix b/users/tazjin/blog/default.nix index fd2f38839..c65b5cb50 100644 --- a/users/tazjin/blog/default.nix +++ b/users/tazjin/blog/default.nix @@ -4,6 +4,20 @@ with depot.nix.yants; let inherit (builtins) hasAttr filter; + + blogConfig = { + name = "tazjin's blog"; + + footer = '' + +

ಠ_ಠ

+ ''; + }; + inherit (depot.web.blog) post includePost renderPost; posts = filter includePost (list post (import ./posts.nix)); @@ -12,7 +26,7 @@ let mkdir -p $out ${lib.concatStringsSep "\n" (map (post: - "cp ${renderPost post} $out/${post.key}.html" + "cp ${renderPost blogConfig post} $out/${post.key}.html" ) posts)} ''; diff --git a/web/blog/default.nix b/web/blog/default.nix index 05367588e..a93762dfe 100644 --- a/web/blog/default.nix +++ b/web/blog/default.nix @@ -9,7 +9,7 @@ with depot.nix.yants; let # Type definition for a single blog post. post = struct "blog-post" { - key = string; # + key = string; title = string; date = int; @@ -31,11 +31,9 @@ let oldKey = option string; }; - posts = list post (import ./posts.nix); fragments = import ./fragments.nix args; - - includePost = post: !(fragments.isDraft post) && !(fragments.isUnlisted post); in { - inherit post includePost; + inherit post; inherit (fragments) renderPost; + includePost = post: !(fragments.isDraft post) && !(fragments.isUnlisted post); } diff --git a/web/blog/fragments.nix b/web/blog/fragments.nix index eb46a09fd..56e603905 100644 --- a/web/blog/fragments.nix +++ b/web/blog/fragments.nix @@ -4,9 +4,6 @@ # # An entire post is rendered by `renderPost`, which assembles the # fragments together in a runCommand execution. -# -# The post index is generated by //users/tazjin/homepage, not by this -# code. { depot, lib, pkgs, ... }: let @@ -20,33 +17,28 @@ let escape = replaceStrings [ "<" ">" "&" "'" ] [ "<" ">" "&" "'" ]; - header = title: '' + header = name: title: '' - + - tazjin's blog: ${escape title} + ${escape name}: ${escape title}
-

tazjin's interblag

+

${escape name}


''; - footer = '' + footer = content: ''
''; @@ -54,7 +46,7 @@ let draftWarning = writeText "draft.html" ''

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


''; @@ -62,13 +54,13 @@ let unlistedWarning = writeText "unlisted.html" ''

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


''; - renderPost = post: runCommandNoCC "${post.key}.html" {} '' - cat ${writeText "header.html" (header post.title)} > $out + 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 @@ -97,5 +89,5 @@ let cat ${writeText "footer.html" footer} >> $out ''; in { - inherit renderPost isDraft isUnlisted; + inherit isDraft isUnlisted renderPost; }