Move post to its own file
This commit is contained in:
parent
849f6543c8
commit
3fd900b2d6
2 changed files with 52 additions and 55 deletions
|
@ -6,61 +6,8 @@ unit module DB;
|
||||||
use Pandoc;
|
use Pandoc;
|
||||||
use JSON::Class:auth<zef:vrurg>;
|
use JSON::Class:auth<zef:vrurg>;
|
||||||
|
|
||||||
#| Top level metadata for the blog
|
use DB::Post;
|
||||||
class BlogMeta is json(:pretty) {
|
use DB::BlogMeta;
|
||||||
#| The title of the blog
|
|
||||||
has Str:D $.title is required;
|
|
||||||
#| The tagline of the blog
|
|
||||||
has Str:D $.tagline is required;
|
|
||||||
}
|
|
||||||
|
|
||||||
#| Shared post meta-data
|
|
||||||
role Post is json {
|
|
||||||
#| The location of the source file for the post
|
|
||||||
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
|
|
||||||
is json(
|
|
||||||
:to-json(*.Str),
|
|
||||||
:from-json(*.DateTime)
|
|
||||||
);
|
|
||||||
#| An optional list of edit times for the post
|
|
||||||
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 is json = [];
|
|
||||||
#| Should the post be hidden from the main list
|
|
||||||
has Bool:D $.hidden is json is rw = False;
|
|
||||||
|
|
||||||
#| Get the title for this post, intended to be extracted from whatever
|
|
||||||
#| document produced it
|
|
||||||
method title(--> Str:D) {...}
|
|
||||||
|
|
||||||
#| Get the list of slugs for this post, including ones auto generated from
|
|
||||||
#| the title, as well as any additional slugs
|
|
||||||
method all-slugs(--> Array[Str:D]) {
|
|
||||||
my $long-title-slug = self.title.lc.subst: /\h*/, '-';
|
|
||||||
return [$long-title-slug, @!slugs].flat.Array;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#| A plain markdown post
|
#| A plain markdown post
|
||||||
class MarkdownPost does Post is json {
|
class MarkdownPost does Post is json {
|
||||||
|
|
50
lib/DB/Post.rakumod
Normal file
50
lib/DB/Post.rakumod
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
use v6.e.PREVIEW;
|
||||||
|
|
||||||
|
use JSON::Class:auth<zef:vrurg>;
|
||||||
|
|
||||||
|
#| Shared post meta-data
|
||||||
|
unit role Post is json;
|
||||||
|
|
||||||
|
#| The location of the source file for the post
|
||||||
|
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
|
||||||
|
is json(
|
||||||
|
:to-json(*.Str),
|
||||||
|
:from-json(*.DateTime)
|
||||||
|
);
|
||||||
|
#| An optional list of edit times for the post
|
||||||
|
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 is json = [];
|
||||||
|
#| Should the post be hidden from the main list
|
||||||
|
has Bool:D $.hidden is json is rw = False;
|
||||||
|
|
||||||
|
#| Get the title for this post, intended to be extracted from whatever
|
||||||
|
#| document produced it
|
||||||
|
method title(--> Str:D) {...}
|
||||||
|
|
||||||
|
#| Get the list of slugs for this post, including ones auto generated from
|
||||||
|
#| the title, as well as any additional slugs
|
||||||
|
method all-slugs(--> Array[Str:D]) {
|
||||||
|
my $long-title-slug = self.title.lc.subst: /\h*/, '-';
|
||||||
|
return [$long-title-slug, @!slugs].flat.Array;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue