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.
|
|
|
|
#
|
2020-08-10 22:53:19 +02:00
|
|
|
# The post index is generated by //users/tazjin/homepage, not by this
|
|
|
|
# code.
|
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;
|
2021-04-10 18:05:16 +02:00
|
|
|
inherit (pkgs) runCommandNoCC writeText;
|
2020-08-10 23:48:05 +02:00
|
|
|
inherit (depot.users.tazjin) 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 [ "<" ">" "&" "'" ] [ "<" ">" "&" "'" ];
|
|
|
|
|
|
|
|
header = title: ''
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
<meta name="description" content="tazjin's blog">
|
2020-02-09 01:01:07 +01:00
|
|
|
<link rel="stylesheet" type="text/css" href="/static/tazjin.css" media="all">
|
2020-02-09 01:43:00 +01:00
|
|
|
<link rel="icon" type="image/webp" href="/static/favicon.webp">
|
2020-08-11 00:38:07 +02:00
|
|
|
<link rel="alternate" type="application/atom+xml" title="Atom Feed" href="/feed.atom">
|
2020-02-09 01:01:07 +01:00
|
|
|
<title>tazjin's blog: ${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>
|
2020-02-09 01:01:07 +01:00
|
|
|
<h1><a class="blog-title" href="/">tazjin's interblag</a> </h1>
|
2020-02-08 14:33:13 +01:00
|
|
|
<hr>
|
|
|
|
</header>
|
|
|
|
'';
|
|
|
|
|
|
|
|
footer = ''
|
|
|
|
<hr>
|
|
|
|
<footer>
|
|
|
|
<p class="footer">
|
|
|
|
<a class="uncoloured-link" href="https://tazj.in">homepage</a>
|
|
|
|
|
|
2021-01-16 21:49:01 +01:00
|
|
|
<a class="uncoloured-link" href="https://cs.tvl.fyi/">code</a>
|
2020-02-08 14:33:13 +01:00
|
|
|
</p>
|
|
|
|
<p class="lod">ಠ_ಠ</p>
|
|
|
|
</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
|
|
|
|
the link to it without asking me first.
|
|
|
|
</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
|
|
|
|
the link to it without asking me first.
|
|
|
|
</p>
|
|
|
|
<hr>
|
|
|
|
'';
|
|
|
|
|
2020-02-08 14:33:13 +01:00
|
|
|
renderPost = post: runCommandNoCC "${post.key}.html" {} ''
|
2021-03-25 19:14:48 +01:00
|
|
|
cat ${writeText "header.html" (header post.title)} > $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 ""
|
|
|
|
}
|
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-03-25 19:14:48 +01:00
|
|
|
cat ${writeText "footer.html" footer} >> $out
|
2020-02-08 14:33:13 +01:00
|
|
|
'';
|
|
|
|
in {
|
2020-02-09 22:44:48 +01:00
|
|
|
inherit renderPost isDraft isUnlisted;
|
2020-02-08 14:33:13 +01:00
|
|
|
}
|