fix and rename exclude_tags to exclude_collections
This commit is contained in:
parent
8a22c5e7a9
commit
24e6abb811
1 changed files with 15 additions and 23 deletions
|
|
@ -34,35 +34,27 @@ module.exports = function (eleventyConfig, { TIME_ZONE, defaultLanguage }) {
|
||||||
return filtered;
|
return filtered;
|
||||||
});
|
});
|
||||||
|
|
||||||
// takes a collection or all collections and returns only the tags no matched
|
// takes all collections and returns only the tags not matched
|
||||||
// works with arrays and key-objects so may repurpose under different name
|
// key-objects so may repurpose under different name
|
||||||
eleventyConfig.addFilter("exclude_tags", function (collection, ...tagsToExclude) {
|
eleventyConfig.addFilter("exclude_collections", function (collections, ...keysToExclude) {
|
||||||
if (!collection || typeof collection !== "object") {
|
if (!collections || typeof collections !== "object") {
|
||||||
console.warn("[exclude_tags] Invalid collection input:", collection);
|
console.warn("[exclude_collections] Invalid collections input:", collections);
|
||||||
return collection;
|
return collections;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle both array and key-value object inputs
|
const result = {};
|
||||||
const items = Array.isArray(collection) ? collection : Object.values(collection);
|
Object.keys(collections).forEach(key => {
|
||||||
|
if (!keysToExclude.includes(key)) {
|
||||||
// filter out items where any of the tagsToExclude are in item.data.tags
|
result[key] = collections[key];
|
||||||
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 (process.env.LOCALE_URL_DEBUG === "1" || process.env.LOCALE_URL_DEBUG === "true") {
|
||||||
if (!Array.isArray(collection)) {
|
console.warn("[excludeCollections] Excluded keys:", keysToExclude);
|
||||||
const result = {};
|
console.warn("[excludeCollections] Resulting keys:", Object.keys(result));
|
||||||
Object.keys(collection).forEach(key => {
|
|
||||||
if (filtered.includes(collection[key])) {
|
|
||||||
result[key] = collection[key];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return filtered;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
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";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue