add exclude_tags filter
This commit is contained in:
parent
08f0ec496f
commit
8a22c5e7a9
1 changed files with 31 additions and 0 deletions
|
|
@ -34,6 +34,37 @@ module.exports = function (eleventyConfig, { TIME_ZONE, defaultLanguage }) {
|
||||||
return filtered;
|
return filtered;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// takes a collection or all collections and returns only the tags no matched
|
||||||
|
// works with arrays and key-objects so may repurpose under different name
|
||||||
|
eleventyConfig.addFilter("exclude_tags", function (collection, ...tagsToExclude) {
|
||||||
|
if (!collection || typeof collection !== "object") {
|
||||||
|
console.warn("[exclude_tags] Invalid collection input:", collection);
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle both array and key-value object inputs
|
||||||
|
const items = Array.isArray(collection) ? collection : Object.values(collection);
|
||||||
|
|
||||||
|
// filter out items where any of the tagsToExclude are in item.data.tags
|
||||||
|
const filtered = items.filter(item => {
|
||||||
|
const itemTags = item.data && item.data.tags ? item.data.tags : [];
|
||||||
|
return !tagsToExclude.some(tag => itemTags.includes(tag));
|
||||||
|
});
|
||||||
|
|
||||||
|
// if input was a key-value object, reconstruct it
|
||||||
|
if (!Array.isArray(collection)) {
|
||||||
|
const result = {};
|
||||||
|
Object.keys(collection).forEach(key => {
|
||||||
|
if (filtered.includes(collection[key])) {
|
||||||
|
result[key] = collection[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return filtered;
|
||||||
|
});
|
||||||
|
|
||||||
const LOCALE_URL_DEBUG = process.env.LOCALE_URL_DEBUG === "1" || process.env.LOCALE_URL_DEBUG === "true";
|
const LOCALE_URL_DEBUG = process.env.LOCALE_URL_DEBUG === "1" || process.env.LOCALE_URL_DEBUG === "true";
|
||||||
|
|
||||||
// locale_url replacement that uses pre-compile filesystem
|
// locale_url replacement that uses pre-compile filesystem
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue