From 7d5cbfba3c79b4783162d35e154e30badc1ded93 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Wed, 5 Feb 2025 03:45:01 -0500 Subject: [PATCH] Edited at time --- blog | 16 ++++++++++++++++ lib/Config.rakumod | 23 +++++++++++++++++++++-- lib/DB/Post.rakumod | 1 + 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/blog b/blog index 4198bdd..83f331c 100755 --- a/blog +++ b/blog @@ -118,6 +118,22 @@ multi MAIN( say 'Post has slugs: ', $db.posts{$id}.all-slugs; } +#| Update the last editied time on a post +multi MAIN( + "touch", + #| The post id to touch + Int:D $id, + #| The path of the database file + IO::Path(Str) :$db-dir = $default-db-dir, + #| The date/time the post should be recorded as laste edited at + DateTime(Str) :$edited-at = DateTime.now, +) { + my $db = read-db $db-dir; + my $post = $db.posts{$id.Int}; + $post.edited-at.push: $edited-at; + $db.write: $db-dir; +} + #| Render the blog to html multi MAIN( "render", diff --git a/lib/Config.rakumod b/lib/Config.rakumod index e5a1dd4..c7a32df 100644 --- a/lib/Config.rakumod +++ b/lib/Config.rakumod @@ -86,7 +86,7 @@ method site-header(BlogMeta:D $meta) { method post-date(Post:D $post) { my $datetime = $post.posted-at; my $timestamp = sprintf( - "%s %02d:%02d %s", + "%s %02d:%02d%s", $datetime.yyyy-mm-dd, ($datetime.hour % 12) || 12, $datetime.minute, @@ -100,6 +100,24 @@ method post-date(Post:D $post) { ] } +method post-edit(Post:D $post) { + return [] unless $post.edited-at.elems; + my $datetime = $post.edited-at.max; + my $timestamp = sprintf( + "%s %02d:%02d%s", + $datetime.yyyy-mm-dd, + ($datetime.hour % 12) || 12, + $datetime.minute, + $datetime.hour < 12 ?? 'am' !! 'pm' + ); + + div :class, :title("Laste Edited At $timestamp"), [ + icon 'edit'; + ' '; + $timestamp + ] +} + sub mins-to-string($mins) { if $mins < 60 { $mins.Str ~ "m" @@ -130,7 +148,9 @@ method post-read-time(Post:D $post) { method post-info(Post:D $post) { div :class, [ self.post-date: $post; + self.post-edit: $post; self.post-read-time: $post; + # TODO: Add tags once we have support for that ]; } @@ -140,7 +160,6 @@ method post-header(Post:D $post) { h1 $post.title; ]; self.post-info: $post; - # TODO: Add tags once we have support for that ] } diff --git a/lib/DB/Post.rakumod b/lib/DB/Post.rakumod index 3e7c377..dbdc0f7 100644 --- a/lib/DB/Post.rakumod +++ b/lib/DB/Post.rakumod @@ -24,6 +24,7 @@ DateTime:D $.posted-at #| An optional list of edit times for the post has DateTime:D @.edited-at + is rw is json( :to-json( value => { $^value.Str }