Add guardrail against duplicate slugs

This commit is contained in:
Nathan McCarty 2025-02-06 20:32:38 -05:00
parent 3f59c75523
commit b067f79e1c
2 changed files with 8 additions and 1 deletions

View file

@ -71,6 +71,12 @@ class PostDB {
#| Render the site to the provided output directory
method render(IO::Path:D $out-dir, Config:D :$config = Config.new) {
## Consistency checks
# Check to make sure all the slugs are unique
my @all-the-slugs = %!posts.values.map(*.all-slugs).flat;
die "Duplicate slug detected"
unless @all-the-slugs.unique.elems == @all-the-slugs.elems;
## Rendering
my $posts = $out-dir.add('posts/');
my $by-id = $posts.add('by-id/');
my $by-slug = $posts.add('by-slug/');

View file

@ -63,7 +63,8 @@ method all-slugs(--> Array[Str:D]) {
my Str:D @slugs = @!slugs.clone;
@slugs.push($long-title-slug);
@slugs.push($six-word-slug);
@slugs;
@slugs.=unique;
@slugs
}
#| Render this post to an html body