summaryrefslogtreecommitdiff
path: root/node_modules/@11ty/eleventy/src/TemplateFileSlug.js
diff options
context:
space:
mode:
authorShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
committerShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
commit7a52ddeba2a68388b544f529d2d92104420f77b0 (patch)
tree15ddd47457a2cb4a96060747437d36474e4f6b4e /node_modules/@11ty/eleventy/src/TemplateFileSlug.js
parent53d6ae2b5568437afa5e4995580a3fb679b7b91b (diff)
Changed from static to 11ty!
Diffstat (limited to 'node_modules/@11ty/eleventy/src/TemplateFileSlug.js')
-rw-r--r--node_modules/@11ty/eleventy/src/TemplateFileSlug.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/node_modules/@11ty/eleventy/src/TemplateFileSlug.js b/node_modules/@11ty/eleventy/src/TemplateFileSlug.js
new file mode 100644
index 0000000..03c9a29
--- /dev/null
+++ b/node_modules/@11ty/eleventy/src/TemplateFileSlug.js
@@ -0,0 +1,57 @@
+import path from "node:path";
+import { TemplatePath } from "@11ty/eleventy-utils";
+
+class TemplateFileSlug {
+ constructor(inputPath, extensionMap, eleventyConfig) {
+ let inputDir = eleventyConfig.directories.input;
+ if (inputDir) {
+ inputPath = TemplatePath.stripLeadingSubPath(inputPath, inputDir);
+ }
+
+ this.inputPath = inputPath;
+ this.cleanInputPath = inputPath.replace(/^.\//, "");
+
+ let dirs = this.cleanInputPath.split("/");
+ this.dirs = dirs;
+ this.dirs.pop();
+
+ this.parsed = path.parse(inputPath);
+ this.filenameNoExt = extensionMap.removeTemplateExtension(this.parsed.base);
+ }
+
+ // `page.filePathStem` see https://v3.11ty.dev/docs/data-eleventy-supplied/#page-variable
+ getFullPathWithoutExtension() {
+ return "/" + TemplatePath.join(...this.dirs, this._getRawSlug());
+ }
+
+ _getRawSlug() {
+ let 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];
+ }
+ return slug;
+ }
+
+ // `page.fileSlug` see https://v3.11ty.dev/docs/data-eleventy-supplied/#page-variable
+ getSlug() {
+ let rawSlug = this._getRawSlug();
+
+ if (rawSlug === "index") {
+ if (!this.dirs.length) {
+ return "";
+ }
+ let lastDir = this.dirs[this.dirs.length - 1];
+ return this._stripDateFromSlug(lastDir);
+ }
+
+ return rawSlug;
+ }
+}
+
+export default TemplateFileSlug;