Series commands
This commit is contained in:
parent
0571a16dab
commit
d170a2fccf
3 changed files with 118 additions and 2 deletions
|
@ -40,6 +40,15 @@ class PostDB {
|
|||
}
|
||||
}
|
||||
|
||||
#| Get the next unused series ID
|
||||
method next-series-id(--> Int) {
|
||||
if %!series.elems > 0 {
|
||||
%!series.keys.max + 1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
#| Insert a new post to the DB, returning its id
|
||||
method insert-post(PostTypes $post --> Int) {
|
||||
my $id = self.next-post-id;
|
||||
|
@ -47,6 +56,13 @@ class PostDB {
|
|||
$id
|
||||
}
|
||||
|
||||
#| Insert a new series to the DB, returning its id
|
||||
method insert-series(Series:D $series --> Int) {
|
||||
my $id = self.next-series-id;
|
||||
%!series{$id} = $series;
|
||||
$id
|
||||
}
|
||||
|
||||
#| Initialize a new database
|
||||
method init(BlogMeta:D $meta --> PostDB:D) {
|
||||
my %posts{Int} of PostTypes = %();
|
||||
|
@ -172,7 +188,7 @@ sub read-db(IO::Path:D $dir --> PostDB:D) is export {
|
|||
}
|
||||
}
|
||||
# Read series
|
||||
my %series{Int} of PostTypes = %();
|
||||
my %series{Int} of Series:D = %();
|
||||
# For backwards compatability, the series directory is optional. It will be
|
||||
# created on the next db operation, but we don't need it to read the site
|
||||
if $series-dir.e {
|
||||
|
|
|
@ -12,4 +12,4 @@ has Str:D $.title is required;
|
|||
has Str:D $.desc is required;
|
||||
|
||||
#| The ids of the posts in the series, in series order
|
||||
has Int:D @.post-ids = [];
|
||||
has Int:D @.post-ids is rw = [];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue