Add checks if categories exist

This commit is contained in:
Leilukin 2025-05-07 16:16:51 +08:00
parent e4dc17266e
commit 453d797298

View File

@ -5,7 +5,9 @@ export default function(eleventyConfig) {
let contents = collectionApi.getFilteredByTag('contents');
contents.forEach(p => {
let cats = p.data.categories;
cats.forEach(c => categories.add(c));
if (cats) {
cats.forEach(c => categories.add(c));
}
});
return Array.from(categories).sort();
});
@ -15,7 +17,9 @@ export default function(eleventyConfig) {
cat = cat.toLowerCase();
let result = contents.filter(item => {
let cats = item.data.categories.map(c => c.toLowerCase());
return cats.includes(cat);
if (cats) {
return cats.includes(cat);
}
});
return result;
});