Metadata support
This commit is contained in:
parent
1d01a8986f
commit
707b55d761
2 changed files with 22 additions and 3 deletions
9
blog
9
blog
|
@ -33,7 +33,14 @@ multi MAIN(
|
||||||
die "Database file already exists, use --force to overwrite: {$file.Str}"
|
die "Database file already exists, use --force to overwrite: {$file.Str}"
|
||||||
if $file.e && !$force;
|
if $file.e && !$force;
|
||||||
|
|
||||||
my $db = DB::PostDB.new;
|
print "Blog Title: ";
|
||||||
|
my $title = get;
|
||||||
|
print "Tagline: ";
|
||||||
|
my $tagline = get;
|
||||||
|
|
||||||
|
my $meta = DB::BlogMeta.new: title => $title, tagline => $tagline;
|
||||||
|
|
||||||
|
my $db = DB::PostDB.new: meta => $meta;
|
||||||
|
|
||||||
if $force {
|
if $force {
|
||||||
$file.spurt: $db.to-json, :create-only;
|
$file.spurt: $db.to-json, :create-only;
|
||||||
|
|
|
@ -6,6 +6,14 @@ 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
|
||||||
|
class BlogMeta is json(:pretty) {
|
||||||
|
#| 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
|
#| Shared post meta-data
|
||||||
role Post is json {
|
role Post is json {
|
||||||
#| The location of the source file for the post
|
#| The location of the source file for the post
|
||||||
|
@ -16,6 +24,8 @@ role Post is json {
|
||||||
has DateTime:D @.edited-at = [];
|
has DateTime:D @.edited-at = [];
|
||||||
#| An optional list of extra slugs to use for this post
|
#| An optional list of extra slugs to use for this post
|
||||||
has Str:D @.slugs = [];
|
has Str:D @.slugs = [];
|
||||||
|
#| Should the post be hidden from the main list
|
||||||
|
has Bool:D $.hidden is rw = False;
|
||||||
|
|
||||||
#| Get the title for this post, intended to be extracted from whatever
|
#| Get the title for this post, intended to be extracted from whatever
|
||||||
#| document produced it
|
#| document produced it
|
||||||
|
@ -23,9 +33,9 @@ role Post is json {
|
||||||
|
|
||||||
#| Get the list of slugs for this post, including ones auto generated from
|
#| Get the list of slugs for this post, including ones auto generated from
|
||||||
#| the title, as well as any additional slugs
|
#| the title, as well as any additional slugs
|
||||||
method all-slugs(--> List[Str:D]) {
|
method all-slugs(--> Array[Str:D]) {
|
||||||
my $long-title-slug = self.title.lc.subst: /\h*/, '-';
|
my $long-title-slug = self.title.lc.subst: /\h*/, '-';
|
||||||
return [$long-title-slug, @!slugs].flat.list;
|
return [$long-title-slug, @!slugs].flat.Array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +60,8 @@ class MarkdownPost does Post is json {
|
||||||
|
|
||||||
#| The top level posts database
|
#| The top level posts database
|
||||||
class PostDB is json(:pretty) {
|
class PostDB is json(:pretty) {
|
||||||
|
#| The metadat for the blog
|
||||||
|
has BlogMeta:D $.meta is required;
|
||||||
#| A mapping from post ids to posts
|
#| A mapping from post ids to posts
|
||||||
has Hash[Int:D, Post:D] %.posts = %();
|
has Hash[Int:D, Post:D] %.posts = %();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue