Edited at time
This commit is contained in:
parent
73aefa28eb
commit
7d5cbfba3c
3 changed files with 38 additions and 2 deletions
16
blog
16
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",
|
||||
|
|
|
@ -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<post-edit>, :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<post-info>, [
|
||||
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
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Add table
Reference in a new issue