diff --git a/blog b/blog index 5051bef..3d3cb5a 100755 --- a/blog +++ b/blog @@ -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, diff --git a/db/posts/5.json b/db/posts/5.json index a689e5e..c3b3ed4 100644 --- a/db/posts/5.json +++ b/db/posts/5.json @@ -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" ] diff --git a/lib/DB/Post.rakumod b/lib/DB/Post.rakumod index d231956..6cf7ad0 100644 --- a/lib/DB/Post.rakumod +++ b/lib/DB/Post.rakumod @@ -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 diff --git a/lib/Render/Post.rakumod b/lib/Render/Post.rakumod index 8bb6f97..7b50d0a 100644 --- a/lib/Render/Post.rakumod +++ b/lib/Render/Post.rakumod @@ -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, [ + a :href($post.source-code), [ + logo 'git'; + ' '; + "Source Code"; + ]; + ] + } else { + [] + } +} + sub series-tag(Int:D $post-id, Int:D $series-id, Series:D $series) is export { span :class, [ 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; ]; } diff --git a/lib/Render/Util.rakumod b/lib/Render/Util.rakumod index 475a79a..4b26e28 100644 --- a/lib/Render/Util.rakumod +++ b/lib/Render/Util.rakumod @@ -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"