Fix slugs logic

This commit is contained in:
Nathan McCarty 2025-01-22 21:17:38 -05:00
parent 22952a01f7
commit a8e3b30668
2 changed files with 5 additions and 2 deletions

1
blog
View file

@ -91,4 +91,5 @@ multi MAIN(
);
write-db $db-file, $db;
say 'Post inserted with id ', $id;
say 'Post has slugs: ', $db.posts{$id}.all-slugs;
}

View file

@ -45,6 +45,8 @@ 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;
my $long-title-slug = self.title.lc.trim.subst: /\h+/, '-', :g;
my Str:D @slugs = @!slugs.clone;
@slugs.push($long-title-slug);
@slugs;
}