From 7a52ddeba2a68388b544f529d2d92104420f77b0 Mon Sep 17 00:00:00 2001 From: Shipwreckt Date: Fri, 31 Oct 2025 20:02:14 +0000 Subject: Changed from static to 11ty! --- .../@11ty/eleventy/src/Util/PathNormalizer.js | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 node_modules/@11ty/eleventy/src/Util/PathNormalizer.js (limited to 'node_modules/@11ty/eleventy/src/Util/PathNormalizer.js') diff --git a/node_modules/@11ty/eleventy/src/Util/PathNormalizer.js b/node_modules/@11ty/eleventy/src/Util/PathNormalizer.js new file mode 100644 index 0000000..cdc3253 --- /dev/null +++ b/node_modules/@11ty/eleventy/src/Util/PathNormalizer.js @@ -0,0 +1,58 @@ +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import { TemplatePath } from "@11ty/eleventy-utils"; + +export default class PathNormalizer { + static getParts(inputPath) { + if (!inputPath) { + return []; + } + + let separator = "/"; + if (inputPath.includes(path.sep)) { + separator = path.sep; + } + + return inputPath.split(separator).filter((entry) => entry !== "."); + } + + // order is important here: the top-most directory returns first + // array of file and all parent directories + static getAllPaths(inputPath) { + let parts = this.getParts(inputPath); + let allPaths = []; + + let fullpath = ""; + for (let part of parts) { + fullpath += (fullpath.length > 0 ? "/" : "") + part; + allPaths.push(fullpath); + } + + return allPaths; + } + + static normalizeSeperator(inputPath) { + if (!inputPath) { + return inputPath; + } + return inputPath.split(path.sep).join("/"); + } + + static fullNormalization(inputPath) { + if (typeof inputPath !== "string") { + return inputPath; + } + + // Fix file:///Users/ or file:///C:/ paths passed in + if (inputPath.startsWith("file://")) { + inputPath = fileURLToPath(inputPath); + } + + // Paths should not be absolute (we convert absolute paths to relative) + // Paths should not have a leading dot slash + // Paths should always be `/` independent of OS path separator + return TemplatePath.stripLeadingDotSlash( + this.normalizeSeperator(TemplatePath.relativePath(inputPath)), + ); + } +} -- cgit v1.2.3