Add post source code tag

This commit is contained in:
Nathan McCarty 2025-02-10 12:27:05 -05:00
parent f887be396b
commit dcc6799e6f
5 changed files with 46 additions and 4 deletions

28
blog
View file

@ -204,7 +204,7 @@ multi MAIN(
multi MAIN(
"post",
"info",
#| The id of the post to display information for
#| The id of the post
Int $id,
#| The path of the database directory
IO::Path(Str) :$db-dir = $default-db-dir,
@ -260,7 +260,7 @@ multi MAIN(
multi MAIN(
"post",
"tag",
#| The id of the post to display information for
#| The id of the post
Int $id,
#| The tag to add/remove
Str $tag,
@ -288,7 +288,7 @@ multi MAIN(
multi MAIN(
"post",
"now",
#| The id of the post to update the posted-at time
#| The id of the post
Int $id,
#| The path of the database directory
IO::Path(Str) :$db-dir = $default-db-dir,
@ -299,6 +299,26 @@ multi MAIN(
$db.write: $db-dir;
}
#| Set the source code link for a post
multi MAIN(
"post",
"source",
#| The id of the post
Int $id,
#| The path of the database directory
IO::Path(Str) :$db-dir = $default-db-dir,
) {
my $db = read-db $db-dir;
my $post = $db.posts{$id.Int};
say "Source Code Link:";
my $source-code = get;
$post.source-code = $source-code;
$db.write: $db-dir;
}
#| Create a new series
multi MAIN(
"series",
@ -387,7 +407,7 @@ multi MAIN(
"add",
#| The id of the series to add to
Int $series-id,
#| The id of the post to add
#| The id of the post
Int $post-id,
#| The path of the database directory
IO::Path(Str) :$db-dir = $default-db-dir,

View file

@ -8,6 +8,7 @@
"slugs": [
],
"source": "/home/nathan/Projects/Blog/projects/Idris/src/LessMacrosMoreTypes/Printf.md",
"source-code": "https://git.stranger.systems/thatonelutenist/website/src/branch/trunk/projects/Idris/src/LessMacrosMoreTypes/Printf.md",
"tags": [
"idris"
]

View file

@ -41,6 +41,8 @@ has Str:D @.slugs is json = [];
has Str:D @.tags is rw is json = [];
#| Should the post be hidden from the main list
has Bool:D $.hidden is json is rw = False;
#| An optional link to the source code for the post
has Str $.source-code is rw is json;
#| Get the title for this post, intended to be extracted from whatever
#| document produced it

View file

@ -82,6 +82,20 @@ sub post-tags(Post:D $post) is export {
}
}
sub post-source(Post:D $post) is export {
if $post.source-code {
div :class<post-source>, [
a :href($post.source-code), [
logo 'git';
'&nbsp;';
"Source Code";
];
]
} else {
[]
}
}
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"), [
@ -119,6 +133,7 @@ sub post-info(Int:D $id, Post:D $post, $db) is export {
post-edit $post;
post-read-time $post;
post-tags $post;
post-source $post;
post-series-tags $id, $post, $db;
];
}

View file

@ -47,6 +47,10 @@ sub icon($icon) is export {
i(:class("bx bx-$icon"))
}
sub logo($logo) is export {
i(:class("bx bxl-$logo"))
}
sub mins-to-string($mins) is export {
if $mins < 60 {
$mins.Str ~ "m"