Working new post
This commit is contained in:
parent
707b55d761
commit
0bd8a986e3
2 changed files with 84 additions and 13 deletions
|
@ -17,15 +17,37 @@ class BlogMeta is json(:pretty) {
|
|||
#| Shared post meta-data
|
||||
role Post is json {
|
||||
#| The location of the source file for the post
|
||||
has IO::Path:D $.source is required;
|
||||
has
|
||||
IO::Path:D $.source
|
||||
is required
|
||||
is json(
|
||||
:to-json(*.Str),
|
||||
:from-json(*.IO)
|
||||
);
|
||||
#| The time to display for the creation of the post
|
||||
has DateTime:D $.posted-at is required;
|
||||
has
|
||||
DateTime:D $.posted-at
|
||||
is required
|
||||
is json(
|
||||
:to-json(*.Str),
|
||||
:from-json(*.DateTime)
|
||||
);
|
||||
#| An optional list of edit times for the post
|
||||
has DateTime:D @.edited-at = [];
|
||||
has
|
||||
DateTime:D @.edited-at
|
||||
is json(
|
||||
:to-json()
|
||||
value => { $^value.Str }
|
||||
),
|
||||
:from-json()
|
||||
value => { $^value.DateTime }
|
||||
)
|
||||
)
|
||||
= [];
|
||||
#| An optional list of extra slugs to use for this post
|
||||
has Str:D @.slugs = [];
|
||||
has Str:D @.slugs is json = [];
|
||||
#| Should the post be hidden from the main list
|
||||
has Bool:D $.hidden is rw = False;
|
||||
has Bool:D $.hidden is json is rw = False;
|
||||
|
||||
#| Get the title for this post, intended to be extracted from whatever
|
||||
#| document produced it
|
||||
|
@ -37,6 +59,7 @@ role Post is json {
|
|||
my $long-title-slug = self.title.lc.subst: /\h*/, '-';
|
||||
return [$long-title-slug, @!slugs].flat.Array;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#| A plain markdown post
|
||||
|
@ -63,5 +86,21 @@ class PostDB is json(:pretty) {
|
|||
#| The metadat for the blog
|
||||
has BlogMeta:D $.meta is required;
|
||||
#| A mapping from post ids to posts
|
||||
has Hash[Int:D, Post:D] %.posts = %();
|
||||
has %.posts{Int:D} of MarkdownPost:D = %();
|
||||
|
||||
#| Get the next unused post ID
|
||||
method next-post-id(--> Int) {
|
||||
if %!posts {
|
||||
%!posts.keys.max + 1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
#| Insert a new post to the DB, returning its id
|
||||
method insert-post(Post:D $post --> Int) {
|
||||
my $id = self.next-post-id;
|
||||
%!posts{$id} = $post;
|
||||
$id
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue