feat(tvl/template): support markdown via cheddar

Since the template already was a derivation we can just reimplement a
specialized writeText which runs cheddar on parts of its input to avoid
import from derivation.

Change-Id: I0cffd0e86fd23a749599174260d04269379f4b5f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3114
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
sterni 2021-05-12 16:41:51 +02:00
parent 513e733f8a
commit 25ff41452b

View file

@ -11,12 +11,14 @@
}@args: }@args:
let let
inherit (pkgs) writeText lib; inherit (pkgs) runCommandNoCC lib;
inherit (depot.tools) cheddar;
baseUrl = lib.optionalString useUrls "https://tvl.fyi"; baseUrl = lib.optionalString useUrls "https://tvl.fyi";
in in
writeText "index.html" ('' runCommandNoCC "index.html" {
headerPart = ''
<!DOCTYPE html> <!DOCTYPE html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
@ -25,16 +27,18 @@ writeText "index.html" (''
<link rel="stylesheet" type="text/css" href="${baseUrl}/static/tazjin.css" media="all"> <link rel="stylesheet" type="text/css" href="${baseUrl}/static/tazjin.css" media="all">
<link rel="icon" type="image/webp" href="${baseUrl}/static/favicon.webp"> <link rel="icon" type="image/webp" href="${baseUrl}/static/favicon.webp">
<title>${title}</title> <title>${title}</title>
'' + lib.optionalString (args ? extraHead) extraHead + '' '' + lib.optionalString (args ? extraHead) extraHead + ''
</head> </head>
<body class="light"> <body class="light">
<header> <header>
<h1><a class="blog-title" href="/">${title}</a> </h1> <h1><a class="blog-title" href="/">${title}</a> </h1>
<hr> <hr>
</header> </header>
'';
${content} inherit content;
footerPart = ''
<hr> <hr>
<footer> <footer>
<p class="footer"> <p class="footer">
@ -51,4 +55,10 @@ writeText "index.html" (''
<p class="lod">_</p> <p class="lod">_</p>
</footer> </footer>
</body> </body>
'') '';
passAsFile = [ "headerPart" "content" "footerPart" ];
} ''
${cheddar}/bin/cheddar --about-filter content.md < $contentPath > rendered.html
cat $headerPartPath rendered.html $footerPartPath > $out
''