feat(web/blog): Add support for draft & unlisted posts
Posts with either `draft = true;` or `listed = false;` will no longer be included in index generation and will have a warning callout inserted at the top of the page urging people not to share the links to them.
This commit is contained in:
parent
0bc2f8995e
commit
1e770f5d88
2 changed files with 39 additions and 8 deletions
|
@ -7,6 +7,8 @@
|
||||||
with pkgs.nix.yants;
|
with pkgs.nix.yants;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
inherit (builtins) filter;
|
||||||
|
|
||||||
# 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; #
|
||||||
|
@ -38,7 +40,12 @@ let
|
||||||
"cp ${fragments.renderPost post} $out/${post.key}.html"
|
"cp ${fragments.renderPost post} $out/${post.key}.html"
|
||||||
) posts)}
|
) posts)}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
includePost = post: !(fragments.isDraft post) && !(fragments.isUnlisted post);
|
||||||
in {
|
in {
|
||||||
inherit post posts rendered;
|
inherit post rendered;
|
||||||
static = ./static;
|
static = ./static;
|
||||||
|
|
||||||
|
# Only include listed posts
|
||||||
|
posts = filter includePost posts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,17 @@
|
||||||
# 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 overview is rendered by 'postList'.
|
# The post index is generated by //web/homepage, not by this code.
|
||||||
{ pkgs, lib, ... }:
|
{ pkgs, lib, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (builtins) filter map hasAttr replaceStrings toFile;
|
inherit (builtins) filter map hasAttr replaceStrings toFile;
|
||||||
inherit (pkgs.third_party) runCommandNoCC writeText;
|
inherit (pkgs.third_party) runCommandNoCC writeText;
|
||||||
|
|
||||||
|
# Generate a post list for all listed, non-draft posts.
|
||||||
|
isDraft = post: (hasAttr "draft" post) && post.draft;
|
||||||
|
isUnlisted = post: (hasAttr "listed" post) && !post.listed;
|
||||||
|
|
||||||
escape = replaceStrings [ "<" ">" "&" "'" ] [ "<" ">" "&" "'" ];
|
escape = replaceStrings [ "<" ">" "&" "'" ] [ "<" ">" "&" "'" ];
|
||||||
|
|
||||||
header = title: ''
|
header = title: ''
|
||||||
|
@ -47,6 +51,22 @@ let
|
||||||
</body>
|
</body>
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
draftWarning = toFile "draft.html" ''
|
||||||
|
<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>
|
||||||
|
'';
|
||||||
|
|
||||||
|
unlistedWarning = toFile "unlisted.html" ''
|
||||||
|
<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>
|
||||||
|
'';
|
||||||
|
|
||||||
renderPost = post: runCommandNoCC "${post.key}.html" {} ''
|
renderPost = post: runCommandNoCC "${post.key}.html" {} ''
|
||||||
cat ${toFile "header.html" (header post.title)} > $out
|
cat ${toFile "header.html" (header post.title)} > $out
|
||||||
|
|
||||||
|
@ -56,17 +76,21 @@ let
|
||||||
date --date="@${toString post.date}" '+%Y-%m-%d' >> $out
|
date --date="@${toString post.date}" '+%Y-%m-%d' >> $out
|
||||||
echo '</aside>' >> $out
|
echo '</aside>' >> $out
|
||||||
|
|
||||||
|
${
|
||||||
|
# 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?"
|
||||||
|
}
|
||||||
|
|
||||||
# Write the actual post through cheddar's about-filter mechanism
|
# Write the actual post through cheddar's about-filter mechanism
|
||||||
cat ${post.content} | ${pkgs.tools.cheddar}/bin/cheddar --about-filter ${post.content} >> $out
|
cat ${post.content} | ${pkgs.tools.cheddar}/bin/cheddar --about-filter ${post.content} >> $out
|
||||||
echo '</article>' >> $out
|
echo '</article>' >> $out
|
||||||
|
|
||||||
cat ${toFile "footer.html" footer} >> $out
|
cat ${toFile "footer.html" footer} >> $out
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Generate a post list for all listed, non-draft posts.
|
|
||||||
isDraft = post: (hasAttr "draft" post) && post.draft;
|
|
||||||
isUnlisted = post: (hasAttr "listed" post) && !post.listed;
|
|
||||||
includePost = post: !(isDraft post) && !(isUnlisted post);
|
|
||||||
in {
|
in {
|
||||||
inherit renderPost;
|
inherit renderPost isDraft isUnlisted;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue