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 <sternenseemann@systemli.org>
This commit is contained in:
parent
e99d8510d7
commit
bbf92dcdea
3 changed files with 29 additions and 25 deletions
|
@ -4,6 +4,20 @@ with depot.nix.yants;
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (builtins) hasAttr filter;
|
inherit (builtins) hasAttr filter;
|
||||||
|
|
||||||
|
blogConfig = {
|
||||||
|
name = "tazjin's blog";
|
||||||
|
|
||||||
|
footer = ''
|
||||||
|
<p class="footer">
|
||||||
|
<a class="uncoloured-link" href="https://tazj.in">homepage</a>
|
||||||
|
|
|
||||||
|
<a class="uncoloured-link" href="https://cs.tvl.fyi/">code</a>
|
||||||
|
</p>
|
||||||
|
<p class="lod">ಠ_ಠ</p>
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
inherit (depot.web.blog) post includePost renderPost;
|
inherit (depot.web.blog) post includePost renderPost;
|
||||||
|
|
||||||
posts = filter includePost (list post (import ./posts.nix));
|
posts = filter includePost (list post (import ./posts.nix));
|
||||||
|
@ -12,7 +26,7 @@ let
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
|
|
||||||
${lib.concatStringsSep "\n" (map (post:
|
${lib.concatStringsSep "\n" (map (post:
|
||||||
"cp ${renderPost post} $out/${post.key}.html"
|
"cp ${renderPost blogConfig post} $out/${post.key}.html"
|
||||||
) posts)}
|
) posts)}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ with depot.nix.yants;
|
||||||
let
|
let
|
||||||
# Type definition for a single blog post.
|
# Type definition for a single blog post.
|
||||||
post = struct "blog-post" {
|
post = struct "blog-post" {
|
||||||
key = string; #
|
key = string;
|
||||||
title = string;
|
title = string;
|
||||||
date = int;
|
date = int;
|
||||||
|
|
||||||
|
@ -31,11 +31,9 @@ let
|
||||||
oldKey = option string;
|
oldKey = option string;
|
||||||
};
|
};
|
||||||
|
|
||||||
posts = list post (import ./posts.nix);
|
|
||||||
fragments = import ./fragments.nix args;
|
fragments = import ./fragments.nix args;
|
||||||
|
|
||||||
includePost = post: !(fragments.isDraft post) && !(fragments.isUnlisted post);
|
|
||||||
in {
|
in {
|
||||||
inherit post includePost;
|
inherit post;
|
||||||
inherit (fragments) renderPost;
|
inherit (fragments) renderPost;
|
||||||
|
includePost = post: !(fragments.isDraft post) && !(fragments.isUnlisted post);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
#
|
#
|
||||||
# An entire post is rendered by `renderPost`, which assembles the
|
# An entire post is rendered by `renderPost`, which assembles the
|
||||||
# fragments together in a runCommand execution.
|
# fragments together in a runCommand execution.
|
||||||
#
|
|
||||||
# The post index is generated by //users/tazjin/homepage, not by this
|
|
||||||
# code.
|
|
||||||
{ depot, lib, pkgs, ... }:
|
{ depot, lib, pkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
@ -20,33 +17,28 @@ let
|
||||||
|
|
||||||
escape = replaceStrings [ "<" ">" "&" "'" ] [ "<" ">" "&" "'" ];
|
escape = replaceStrings [ "<" ">" "&" "'" ] [ "<" ">" "&" "'" ];
|
||||||
|
|
||||||
header = title: ''
|
header = name: title: ''
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta name="description" content="tazjin's blog">
|
<meta name="description" content="${escape name}">
|
||||||
<link rel="stylesheet" type="text/css" href="/static/tvl.css" media="all">
|
<link rel="stylesheet" type="text/css" href="/static/tvl.css" media="all">
|
||||||
<link rel="icon" type="image/webp" href="/static/favicon.webp">
|
<link rel="icon" type="image/webp" href="/static/favicon.webp">
|
||||||
<link rel="alternate" type="application/atom+xml" title="Atom Feed" href="/feed.atom">
|
<link rel="alternate" type="application/atom+xml" title="Atom Feed" href="/feed.atom">
|
||||||
<title>tazjin's blog: ${escape title}</title>
|
<title>${escape name}: ${escape title}</title>
|
||||||
</head>
|
</head>
|
||||||
<body class="light">
|
<body class="light">
|
||||||
<header>
|
<header>
|
||||||
<h1><a class="blog-title" href="/">tazjin's interblag</a> </h1>
|
<h1><a class="blog-title" href="/">${escape name}</a> </h1>
|
||||||
<hr>
|
<hr>
|
||||||
</header>
|
</header>
|
||||||
'';
|
'';
|
||||||
|
|
||||||
footer = ''
|
footer = content: ''
|
||||||
<hr>
|
<hr>
|
||||||
<footer>
|
<footer>
|
||||||
<p class="footer">
|
${content}
|
||||||
<a class="uncoloured-link" href="https://tazj.in">homepage</a>
|
|
||||||
|
|
|
||||||
<a class="uncoloured-link" href="https://cs.tvl.fyi/">code</a>
|
|
||||||
</p>
|
|
||||||
<p class="lod">ಠ_ಠ</p>
|
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
'';
|
'';
|
||||||
|
@ -54,7 +46,7 @@ let
|
||||||
draftWarning = writeText "draft.html" ''
|
draftWarning = writeText "draft.html" ''
|
||||||
<p class="cheddar-callout cheddar-warning">
|
<p class="cheddar-callout cheddar-warning">
|
||||||
<b>Note:</b> This post is a <b>draft</b>! Please do not share
|
<b>Note:</b> This post is a <b>draft</b>! Please do not share
|
||||||
the link to it without asking me first.
|
the link to it without asking first.
|
||||||
</p>
|
</p>
|
||||||
<hr>
|
<hr>
|
||||||
'';
|
'';
|
||||||
|
@ -62,13 +54,13 @@ let
|
||||||
unlistedWarning = writeText "unlisted.html" ''
|
unlistedWarning = writeText "unlisted.html" ''
|
||||||
<p class="cheddar-callout cheddar-warning">
|
<p class="cheddar-callout cheddar-warning">
|
||||||
<b>Note:</b> This post is <b>unlisted</b>! Please do not share
|
<b>Note:</b> This post is <b>unlisted</b>! Please do not share
|
||||||
the link to it without asking me first.
|
the link to it without asking first.
|
||||||
</p>
|
</p>
|
||||||
<hr>
|
<hr>
|
||||||
'';
|
'';
|
||||||
|
|
||||||
renderPost = post: runCommandNoCC "${post.key}.html" {} ''
|
renderPost = { name, footer }: post: runCommandNoCC "${post.key}.html" {} ''
|
||||||
cat ${writeText "header.html" (header post.title)} > $out
|
cat ${writeText "header.html" (header name post.title)} > $out
|
||||||
|
|
||||||
# Write the post title & date
|
# Write the post title & date
|
||||||
echo '<article><h2 class="inline">${escape post.title}</h2>' >> $out
|
echo '<article><h2 class="inline">${escape post.title}</h2>' >> $out
|
||||||
|
@ -97,5 +89,5 @@ let
|
||||||
cat ${writeText "footer.html" footer} >> $out
|
cat ${writeText "footer.html" footer} >> $out
|
||||||
'';
|
'';
|
||||||
in {
|
in {
|
||||||
inherit renderPost isDraft isUnlisted;
|
inherit isDraft isUnlisted renderPost;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue