Add guardrail against duplicate slugs
This commit is contained in:
parent
3f59c75523
commit
b067f79e1c
2 changed files with 8 additions and 1 deletions
|
@ -71,6 +71,12 @@ class PostDB {
|
||||||
|
|
||||||
#| Render the site to the provided output directory
|
#| Render the site to the provided output directory
|
||||||
method render(IO::Path:D $out-dir, Config:D :$config = Config.new) {
|
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 $posts = $out-dir.add('posts/');
|
||||||
my $by-id = $posts.add('by-id/');
|
my $by-id = $posts.add('by-id/');
|
||||||
my $by-slug = $posts.add('by-slug/');
|
my $by-slug = $posts.add('by-slug/');
|
||||||
|
|
|
@ -63,7 +63,8 @@ method all-slugs(--> Array[Str:D]) {
|
||||||
my Str:D @slugs = @!slugs.clone;
|
my Str:D @slugs = @!slugs.clone;
|
||||||
@slugs.push($long-title-slug);
|
@slugs.push($long-title-slug);
|
||||||
@slugs.push($six-word-slug);
|
@slugs.push($six-word-slug);
|
||||||
@slugs;
|
@slugs.=unique;
|
||||||
|
@slugs
|
||||||
}
|
}
|
||||||
|
|
||||||
#| Render this post to an html body
|
#| Render this post to an html body
|
||||||
|
|
Loading…
Add table
Reference in a new issue