Add series links

This commit is contained in:
Nathan McCarty 2025-02-09 02:43:22 -05:00
parent d170a2fccf
commit 4793d660e2
6 changed files with 54 additions and 10 deletions

View file

@ -11,14 +11,15 @@ use DB::Post;
unit class Config; unit class Config;
# TODO: Support GFM admonitions # TODO: Support GFM admonitions
method generate-post(Post:D $post, BlogMeta:D $meta) { method generate-post(Int:D $id, Post:D $post, $db) {
my $meta = $db.meta;
my $content = $post.render-html; my $content = $post.render-html;
my $head = generate-head($meta, $post.title, $post.description); my $head = generate-head($meta, $post.title, $post.description);
my $body = my $body =
body [ body [
site-header $meta; site-header $meta;
article :class<post>, [ article :class<post>, [
post-header $post; post-header $id, $post, $db;
div :class<post-body>, [ div :class<post-body>, [
$content; $content;
] ]
@ -46,7 +47,7 @@ method generate-blurb(Int:D $id, $db) {
h2 $post.title; h2 $post.title;
]; ];
]; ];
post-info $post; post-info $id, $post, $db;
if $desc ~~ Str:D { if $desc ~~ Str:D {
div :class<post-blurb-description>, [ div :class<post-blurb-description>, [
p $post.description; p $post.description;
@ -117,7 +118,7 @@ method generate-tag-blurb($db, $tag, $limit?) {
a :href($link), span [ a :href($link), span [
h3 $post.title; h3 $post.title;
]; ];
post-info $post; post-info $id, $post, $db;
if $desc ~~ Str:D { if $desc ~~ Str:D {
div :class<tag-blurb-post-description>, [ div :class<tag-blurb-post-description>, [
p $post.description; p $post.description;

View file

@ -112,7 +112,7 @@ class PostDB {
mkdir $by-slug unless $by-slug.e; mkdir $by-slug unless $by-slug.e;
# Render all the posts and make symlinks # Render all the posts and make symlinks
for %!posts.kv -> $id, $post { for %!posts.kv -> $id, $post {
my $html = $config.generate-post: $post, $!meta; my $html = $config.generate-post: $id, $post, self;
my $id-path = $by-id.add: "$id.html"; my $id-path = $by-id.add: "$id.html";
$id-path.spurt: $html; $id-path.spurt: $html;
for $post.all-slugs -> $slug { for $post.all-slugs -> $slug {

View file

@ -13,3 +13,12 @@ has Str:D $.desc is required;
#| The ids of the posts in the series, in series order #| The ids of the posts in the series, in series order
has Int:D @.post-ids is rw = []; has Int:D @.post-ids is rw = [];
#| Returns true if this series contains the given post id
method contains-post(Int:D $post-id --> Bool:D) {
if $post-id ~~ any @!post-ids {
True
} else {
False
}
}

View file

@ -61,6 +61,7 @@ sub site-header(BlogMeta:D $meta) is export {
header-link 'Index', '/index.html', 'home'; header-link 'Index', '/index.html', 'home';
header-link 'Archive', '/archive.html', 'archive'; header-link 'Archive', '/archive.html', 'archive';
header-link 'Tags', '/tags.html', 'purchase-tag-alt'; header-link 'Tags', '/tags.html', 'purchase-tag-alt';
header-link 'Series', '/series.html', 'book';
header-link 'About', '/about.html', 'info-circle'; header-link 'About', '/about.html', 'info-circle';
header-link 'Feed', '/atom.xml', 'rss'; header-link 'Feed', '/atom.xml', 'rss';
]; ];

View file

@ -3,6 +3,7 @@ unit module Render::Post;
use Render::Util; use Render::Util;
use DB::Post; use DB::Post;
use DB::Series;
use HTML::Functional; use HTML::Functional;
@ -81,20 +82,52 @@ sub post-tags(Post:D $post) is export {
} }
} }
sub post-info(Post:D $post) is export { sub series-tag(Int:D $post-id, Int:D $series-id, Series:D $series) is export {
span :class<post-series-tag>, [
a :href("/series/$series-id.html"), [
icon 'book';
'&nbsp;';
span :class<post-series-tag-inner>, [
$series.title;
'&nbsp;';
'(';
($series.post-ids.first($post-id, :k) + 1).Str;
'/';
$series.post-ids.elems.Str;
')';
]
]
]
}
sub post-series-tags(Int:D $post-id, Post:D $post, $db) is export {
# Find all the series this post is in
my @series = $db.series.grep(*.value.contains-post: $post-id);
if @series {
div :class<post-series-tags>,
@series.map(-> $pair {
series-tag $post-id, $pair.key, $pair.value
});
} else {
[]
}
}
sub post-info(Int:D $id, Post:D $post, $db) is export {
div :class<post-info>, [ div :class<post-info>, [
post-date $post; post-date $post;
post-edit $post; post-edit $post;
post-read-time $post; post-read-time $post;
post-tags $post; post-tags $post;
post-series-tags $id, $post, $db;
]; ];
} }
sub post-header(Post:D $post) is export { sub post-header(Int:D $id, Post:D $post, $db) is export {
header :class<post-header>, [ header :class<post-header>, [
div :class<post-title>, [ div :class<post-title>, [
h1 $post.title; h1 $post.title;
]; ];
post-info $post; post-info $id, $post, $db;
] ]
} }

View file

@ -65,10 +65,10 @@ body, .post {
flex-wrap: wrap; flex-wrap: wrap;
margin-top: var(--box-margin-vert); margin-top: var(--box-margin-vert);
} }
.header-links > a > span { .header-links > a > span, .post-series-tag > a > span {
text-decoration: underline; text-decoration: underline;
} }
.header-links > a { .header-links > a, .post-series-tag > a {
text-decoration: none; text-decoration: none;
} }