From 1d01a8986f1676ad3537cf3f111efb3e796d3888 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Tue, 21 Jan 2025 21:58:10 -0500 Subject: [PATCH] Slug support --- lib/DB.rakumod | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/DB.rakumod b/lib/DB.rakumod index 0085d70..ab110f4 100644 --- a/lib/DB.rakumod +++ b/lib/DB.rakumod @@ -13,11 +13,20 @@ role Post is json { #| The time to display for the creation of the post has DateTime:D $.posted-at is required; #| An optional list of edit times for the post - has DateTime:D @.edited-at is rw = []; + has DateTime:D @.edited-at = []; + #| An optional list of extra slugs to use for this post + has Str:D @.slugs = []; #| 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(--> List[Str:D]) { + my $long-title-slug = self.title.lc.subst: /\h*/, '-'; + return [$long-title-slug, @!slugs].flat.list; + } } #| A plain markdown post