From 707b55d761767e767207b0c2a08308a0e0d092d0 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Tue, 21 Jan 2025 22:08:10 -0500 Subject: [PATCH] Metadata support --- blog | 9 ++++++++- lib/DB.rakumod | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/blog b/blog index 10e1c46..b6b183d 100755 --- a/blog +++ b/blog @@ -33,7 +33,14 @@ multi MAIN( die "Database file already exists, use --force to overwrite: {$file.Str}" 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 { $file.spurt: $db.to-json, :create-only; diff --git a/lib/DB.rakumod b/lib/DB.rakumod index ab110f4..a242fce 100644 --- a/lib/DB.rakumod +++ b/lib/DB.rakumod @@ -6,6 +6,14 @@ unit module DB; use Pandoc; use JSON::Class:auth; +#| 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 role Post is json { #| The location of the source file for the post @@ -16,6 +24,8 @@ role Post is json { has DateTime:D @.edited-at = []; #| An optional list of extra slugs to use for this post 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 #| document produced it @@ -23,9 +33,9 @@ role Post is json { #| Get the list of slugs for this post, including ones auto generated from #| 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*/, '-'; - 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 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 = %(); }