Skip to content

Commit

Permalink
fix: strip date from directory slugs per 11ty#1947
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrHovhannisyan committed Nov 20, 2021
1 parent 03ed136 commit 2488ab1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/TemplateFileSlug.js
Expand Up @@ -23,7 +23,12 @@ class TemplateFileSlug {
}

_getRawSlug() {
let slug = this.filenameNoExt;
const slug = this.filenameNoExt;
return this._stripDateFromSlug(slug);
}

/** Removes dates in the format of YYYY-MM-DD from a given slug string candidate. */
_stripDateFromSlug(slug) {
let reg = slug.match(/\d{4}-\d{2}-\d{2}-(.*)/);
if (reg) {
return reg[1];
Expand All @@ -35,7 +40,11 @@ class TemplateFileSlug {
let rawSlug = this._getRawSlug();

if (rawSlug === "index") {
return this.dirs.length ? this.dirs[this.dirs.length - 1] : "";
if (!this.dirs.length) {
return "";
}
const lastDir = this.dirs[this.dirs.length - 1];
return this._stripDateFromSlug(lastDir);
}

return rawSlug;
Expand Down

0 comments on commit 2488ab1

Please sign in to comment.