Generate tags page

This commit is contained in:
Nathan McCarty 2025-02-07 01:43:52 -05:00
parent f1515aab06
commit 20ecef3b3f
4 changed files with 138 additions and 3 deletions

View file

@ -69,6 +69,13 @@ method site-header(BlogMeta:D $meta) {
'Archive';
];
];
a :href</tags.html>, [
icon 'purchase-tag-alt';
' ';
span [
'Tags';
];
];
a :href</about.html>, [
icon 'info-circle';
' ';
@ -169,7 +176,7 @@ method post-tags(Post:D $post){
if @tags {
@tags.=map(-> $tag {self.post-tag($tag)});
div :class<post-tags>, [
icon 'purchase-tag';
icon 'purchase-tag-alt';
'&nbsp;';
intersperse(', ', @tags);
]
@ -299,6 +306,70 @@ method generate-archive($db) {
"<!doctype html>$html"
}
method generate-tag-blurb($db, $tag, $limit?) {
sub post-to-link($id, $post) {
my $desc = $post.description;
my @slugs = $post.all-slugs;
# Use the primary slug if there is one, the id if there isn't
my $link = do if @slugs.elems {
"/posts/by-slug/{@slugs[*-1]}.html"
} else {
"/posts/by-id/$id.html"
}
div :class<tag-blurb-post>, [
div :class<tag-blurb-post-title>, [
a :href($link), span [
h3 $post.title;
];
self.post-info: $post;
if $desc ~~ Str:D {
div :class<tag-blurb-post-description>, [
p $post.description;
];
} else {
[]
}
];
]
}
my @posts = $db.sorted-posts.grep(-> $a { $tag (elem) $a.value.tags });
if $limit {
@posts.=head($limit);
}
if @posts {
div :class<tag-blurb>, [
span :class<tag-blurb-title>, [
a :href("/tags/$tag.html"), [
icon 'hash';
$tag;
];
];
div :class<tag-blurb-links>,
@posts.map(-> $a {post-to-link $a.key, $a.value});
]
} else {
[]
}
}
method generate-tags-page($db, @tags) {
my $head = self.generate-head(Nil, $db.meta);
my $body = body [
self.site-header: $db.meta;
div :class<tags>, [
h1 "Tags";
], @tags.map(-> $tag {self.generate-tag-blurb($db, $tag, 4)});
];
my $html =
html :lang<en>, [
$head,
$body
];
"<!doctype html>$html"
}
sub icon($icon) {
i(:class("bx bx-$icon"))
}