diff --git a/lib/Config.rakumod b/lib/Config.rakumod index a16d9f4..dafed14 100644 --- a/lib/Config.rakumod +++ b/lib/Config.rakumod @@ -11,14 +11,15 @@ use DB::Post; unit class Config; # 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 $head = generate-head($meta, $post.title, $post.description); my $body = body [ site-header $meta; article :class, [ - post-header $post; + post-header $id, $post, $db; div :class, [ $content; ] @@ -46,7 +47,7 @@ method generate-blurb(Int:D $id, $db) { h2 $post.title; ]; ]; - post-info $post; + post-info $id, $post, $db; if $desc ~~ Str:D { div :class, [ p $post.description; @@ -117,7 +118,7 @@ method generate-tag-blurb($db, $tag, $limit?) { a :href($link), span [ h3 $post.title; ]; - post-info $post; + post-info $id, $post, $db; if $desc ~~ Str:D { div :class, [ p $post.description; diff --git a/lib/DB.rakumod b/lib/DB.rakumod index 042f1a9..f092775 100644 --- a/lib/DB.rakumod +++ b/lib/DB.rakumod @@ -112,7 +112,7 @@ class PostDB { mkdir $by-slug unless $by-slug.e; # Render all the posts and make symlinks 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"; $id-path.spurt: $html; for $post.all-slugs -> $slug { diff --git a/lib/DB/Series.rakumod b/lib/DB/Series.rakumod index 4379cae..6510a7b 100644 --- a/lib/DB/Series.rakumod +++ b/lib/DB/Series.rakumod @@ -13,3 +13,12 @@ has Str:D $.desc is required; #| The ids of the posts in the series, in series order 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 + } +} diff --git a/lib/Render/Head.rakumod b/lib/Render/Head.rakumod index e7eb435..5eaf19c 100644 --- a/lib/Render/Head.rakumod +++ b/lib/Render/Head.rakumod @@ -61,6 +61,7 @@ sub site-header(BlogMeta:D $meta) is export { header-link 'Index', '/index.html', 'home'; header-link 'Archive', '/archive.html', 'archive'; header-link 'Tags', '/tags.html', 'purchase-tag-alt'; + header-link 'Series', '/series.html', 'book'; header-link 'About', '/about.html', 'info-circle'; header-link 'Feed', '/atom.xml', 'rss'; ]; diff --git a/lib/Render/Post.rakumod b/lib/Render/Post.rakumod index 826582e..637217f 100644 --- a/lib/Render/Post.rakumod +++ b/lib/Render/Post.rakumod @@ -3,6 +3,7 @@ unit module Render::Post; use Render::Util; use DB::Post; +use DB::Series; 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, [ + a :href("/series/$series-id.html"), [ + icon 'book'; + ' '; + span :class, [ + $series.title; + ' '; + '('; + ($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, + @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-date $post; post-edit $post; post-read-time $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, [ div :class, [ h1 $post.title; ]; - post-info $post; + post-info $id, $post, $db; ] } diff --git a/resources/main.css b/resources/main.css index 4b54d5e..87dc6ac 100644 --- a/resources/main.css +++ b/resources/main.css @@ -65,10 +65,10 @@ body, .post { flex-wrap: wrap; margin-top: var(--box-margin-vert); } -.header-links > a > span { +.header-links > a > span, .post-series-tag > a > span { text-decoration: underline; } -.header-links > a { +.header-links > a, .post-series-tag > a { text-decoration: none; }