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/TemplateCollection.js | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 node_modules/@11ty/eleventy/src/TemplateCollection.js (limited to 'node_modules/@11ty/eleventy/src/TemplateCollection.js') diff --git a/node_modules/@11ty/eleventy/src/TemplateCollection.js b/node_modules/@11ty/eleventy/src/TemplateCollection.js new file mode 100755 index 0000000..6e99a32 --- /dev/null +++ b/node_modules/@11ty/eleventy/src/TemplateCollection.js @@ -0,0 +1,77 @@ +import { TemplatePath } from "@11ty/eleventy-utils"; + +import TemplateData from "./Data/TemplateData.js"; +import Sortable from "./Util/Objects/Sortable.js"; +import { isGlobMatch } from "./Util/GlobMatcher.js"; + +class TemplateCollection extends Sortable { + constructor() { + super(); + + this._filteredByGlobsCache = new Map(); + } + + getAll() { + return this.items.slice(); + } + + getAllSorted() { + return this.sort(Sortable.sortFunctionDateInputPath); + } + + getSortedByDate() { + return this.sort(Sortable.sortFunctionDate); + } + + getGlobs(globs) { + if (typeof globs === "string") { + globs = [globs]; + } + + globs = globs.map((glob) => TemplatePath.addLeadingDotSlash(glob)); + + return globs; + } + + getFilteredByGlob(globs) { + globs = this.getGlobs(globs); + + let key = globs.join("::"); + if (!this._dirty) { + // Try to find a pre-sorted list and clone it. + if (this._filteredByGlobsCache.has(key)) { + return [...this._filteredByGlobsCache.get(key)]; + } + } else if (this._filteredByGlobsCache.size) { + // Blow away cache + this._filteredByGlobsCache = new Map(); + } + + let filtered = this.getAllSorted().filter((item) => { + return isGlobMatch(item.inputPath, globs); + }); + this._dirty = false; + this._filteredByGlobsCache.set(key, [...filtered]); + return filtered; + } + + getFilteredByTag(tagName) { + return this.getAllSorted().filter((item) => { + if (!tagName || TemplateData.getIncludedTagNames(item.data).includes(tagName)) { + return true; + } + return false; + }); + } + + getFilteredByTags(...tags) { + return this.getAllSorted().filter((item) => { + let itemTags = new Set(TemplateData.getIncludedTagNames(item.data)); + return tags.every((requiredTag) => { + return itemTags.has(requiredTag); + }); + }); + } +} + +export default TemplateCollection; -- cgit v1.2.3