2020-02-08 14:33:13 +01:00
|
|
|
# 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.
|
2021-04-10 18:05:16 +02:00
|
|
|
{ depot, lib, pkgs, ... }:
|
2020-02-08 14:33:13 +01:00
|
|
|
|
|
|
|
let
|
2021-03-25 19:14:48 +01:00
|
|
|
inherit (builtins) filter map hasAttr replaceStrings;
|
2022-09-26 19:33:05 +02:00
|
|
|
inherit (pkgs) runCommand writeText;
|
2021-10-16 16:30:41 +02:00
|
|
|
inherit (depot.nix) renderMarkdown;
|
2020-02-08 14:33:13 +01:00
|
|
|
|
2020-02-09 22:44:48 +01:00
|
|
|
# Generate a post list for all listed, non-draft posts.
|
|
|
|
isDraft = post: (hasAttr "draft" post) && post.draft;
|
|
|
|
isUnlisted = post: (hasAttr "listed" post) && !post.listed;
|
|
|
|
|
2020-02-08 14:33:13 +01:00
|
|
|
escape = replaceStrings [ "<" ">" "&" "'" ] [ "<" ">" "&" "'" ];
|
|
|
|
|
2022-06-30 21:48:48 +02:00
|
|
|
header = name: title: staticUrl: ''
|
2020-02-08 14:33:13 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
2021-11-02 14:34:20 +01:00
|
|
|
<meta name="description" content="${escape name}">
|
2021-11-30 10:51:30 +01:00
|
|
|
<link rel="stylesheet" type="text/css" href="${staticUrl}/tvl.css" media="all">
|
2020-02-09 01:43:00 +01:00
|
|
|
<link rel="icon" type="image/webp" href="/static/favicon.webp">
|
2021-11-30 10:51:30 +01:00
|
|
|
<link rel="alternate" type="application/atom+xml" title="Atom Feed" href="https://tvl.fyi/feed.atom">
|
2021-11-02 14:34:20 +01:00
|
|
|
<title>${escape name}: ${escape title}</title>
|
2020-02-08 14:33:13 +01:00
|
|
|
</head>
|
2020-02-09 01:01:07 +01:00
|
|
|
<body class="light">
|
2020-02-08 14:33:13 +01:00
|
|
|
<header>
|
2021-11-02 14:34:20 +01:00
|
|
|
<h1><a class="blog-title" href="/">${escape name}</a> </h1>
|
2020-02-08 14:33:13 +01:00
|
|
|
<hr>
|
|
|
|
</header>
|
|
|
|
'';
|
|
|
|
|
2021-11-04 16:23:47 +01:00
|
|
|
fullFooter = content: ''
|
2020-02-08 14:33:13 +01:00
|
|
|
<hr>
|
|
|
|
<footer>
|
2021-11-02 14:34:20 +01:00
|
|
|
${content}
|
2020-02-08 14:33:13 +01:00
|
|
|
</footer>
|
|
|
|
</body>
|
|
|
|
'';
|
|
|
|
|
2021-03-25 19:14:48 +01:00
|
|
|
draftWarning = writeText "draft.html" ''
|
2020-02-09 22:44:48 +01:00
|
|
|
<p class="cheddar-callout cheddar-warning">
|
|
|
|
<b>Note:</b> This post is a <b>draft</b>! Please do not share
|
2021-11-02 14:34:20 +01:00
|
|
|
the link to it without asking first.
|
2020-02-09 22:44:48 +01:00
|
|
|
</p>
|
|
|
|
<hr>
|
|
|
|
'';
|
|
|
|
|
2021-03-25 19:14:48 +01:00
|
|
|
unlistedWarning = writeText "unlisted.html" ''
|
2020-02-09 22:44:48 +01:00
|
|
|
<p class="cheddar-callout cheddar-warning">
|
|
|
|
<b>Note:</b> This post is <b>unlisted</b>! Please do not share
|
2021-11-02 14:34:20 +01:00
|
|
|
the link to it without asking first.
|
2020-02-09 22:44:48 +01:00
|
|
|
</p>
|
|
|
|
<hr>
|
|
|
|
'';
|
|
|
|
|
2022-06-30 21:48:48 +02:00
|
|
|
renderPost = { name, footer, staticUrl ? "https://static.tvl.fyi/${depot.web.static.drvHash}", ... }: post: runCommand "${post.key}.html" { } ''
|
|
|
|
cat ${writeText "header.html" (header name post.title staticUrl)} > $out
|
2020-02-08 14:33:13 +01:00
|
|
|
|
2020-02-08 14:47:47 +01:00
|
|
|
# Write the post title & date
|
2020-02-08 14:33:13 +01:00
|
|
|
echo '<article><h2 class="inline">${escape post.title}</h2>' >> $out
|
2020-02-08 14:47:47 +01:00
|
|
|
echo '<aside class="date">' >> $out
|
|
|
|
date --date="@${toString post.date}" '+%Y-%m-%d' >> $out
|
2021-04-02 15:35:35 +02:00
|
|
|
${
|
|
|
|
if post ? updated
|
|
|
|
then ''date --date="@${toString post.updated}" '+ (updated %Y-%m-%d)' >> $out''
|
|
|
|
else ""
|
|
|
|
}
|
2022-09-13 14:14:37 +02:00
|
|
|
${if post ? author then "echo ' by ${post.author}' >> $out" else ""}
|
2020-02-08 14:47:47 +01:00
|
|
|
echo '</aside>' >> $out
|
|
|
|
|
2020-02-09 22:44:48 +01:00
|
|
|
${
|
|
|
|
# Add a warning to draft/unlisted posts to make it clear that
|
|
|
|
# people should not share the post.
|
|
|
|
|
|
|
|
if (isDraft post) then "cat ${draftWarning} >> $out"
|
|
|
|
else if (isUnlisted post) then "cat ${unlistedWarning} >> $out"
|
|
|
|
else "# Your ads could be here?"
|
|
|
|
}
|
|
|
|
|
2020-02-08 14:47:47 +01:00
|
|
|
# Write the actual post through cheddar's about-filter mechanism
|
2020-08-10 23:48:05 +02:00
|
|
|
cat ${renderMarkdown post.content} >> $out
|
2020-02-08 14:33:13 +01:00
|
|
|
echo '</article>' >> $out
|
|
|
|
|
2021-11-04 16:23:47 +01:00
|
|
|
cat ${writeText "footer.html" (fullFooter footer)} >> $out
|
2020-02-08 14:33:13 +01:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
2021-11-02 14:34:20 +01:00
|
|
|
inherit isDraft isUnlisted renderPost;
|
2020-02-08 14:33:13 +01:00
|
|
|
}
|