about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-08-10T21·48+0100
committertazjin <mail@tazj.in>2020-08-10T23·24+0000
commit452b8c7e2338670826aab4f822b7d8ed1099cc81 (patch)
tree90ee74b8e0883425e2c96323676c284ca53d6f18
parent916dba43e7d1dcfdde8e07117d138737f71ec036 (diff)
refactor(tazjin/blog): Extract post rendering to utility function r/1635
To use cheddar for both the feed & web views, the rendering function
is extracted a level up - this prevents duplicate renderer calls.

Change-Id: I31812c5c3f905f2f84914c6a8ab7c14602227be1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1710
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
-rw-r--r--users/tazjin/blog/fragments.nix3
-rw-r--r--users/tazjin/renderMarkdown.nix9
2 files changed, 11 insertions, 1 deletions
diff --git a/users/tazjin/blog/fragments.nix b/users/tazjin/blog/fragments.nix
index 978dfa2a23df..18f1c4e4c236 100644
--- a/users/tazjin/blog/fragments.nix
+++ b/users/tazjin/blog/fragments.nix
@@ -12,6 +12,7 @@
 let
   inherit (builtins) filter map hasAttr replaceStrings toFile;
   inherit (depot.third_party) runCommandNoCC writeText;
+  inherit (depot.users.tazjin) renderMarkdown;
 
   # Generate a post list for all listed, non-draft posts.
   isDraft = post: (hasAttr "draft" post) && post.draft;
@@ -87,7 +88,7 @@ let
     }
 
     # Write the actual post through cheddar's about-filter mechanism
-    cat ${post.content} | ${depot.tools.cheddar}/bin/cheddar --about-filter ${post.content} >> $out
+    cat ${renderMarkdown post.content} >> $out
     echo '</article>' >> $out
 
     cat ${toFile "footer.html" footer} >> $out
diff --git a/users/tazjin/renderMarkdown.nix b/users/tazjin/renderMarkdown.nix
new file mode 100644
index 000000000000..58f29c30e0f3
--- /dev/null
+++ b/users/tazjin/renderMarkdown.nix
@@ -0,0 +1,9 @@
+# Render a Markdown file to HTML.
+{ depot, ... }:
+
+with depot.nix.yants;
+
+defun [ path drv ] (file: depot.third_party.runCommandNoCC "${file}.rendered.html" {} ''
+  cat ${file} | ${depot.tools.cheddar}/bin/cheddar --about-filter ${file} > $out
+'')
+