added several qol scripts and shortcuts
This commit is contained in:
@@ -4,6 +4,53 @@ module.exports = function(eleventyConfig) {
|
|||||||
host: "0.0.0.0",
|
host: "0.0.0.0",
|
||||||
port: 80
|
port: 80
|
||||||
});
|
});
|
||||||
|
eleventyConfig.addWatchTarget("byTag"), (collection, tag) => {
|
||||||
|
return collection.filter(item => item.data.tags && item.data.tags.includes(tag));
|
||||||
|
};
|
||||||
|
eleventyConfig.addFilter("filterTags", (tags) => {
|
||||||
|
return (tags || []).filter(tag => !["recipe", "all", "nav"].includes(tag));
|
||||||
|
});
|
||||||
|
|
||||||
|
eleventyConfig.addCollection("recipesByTag", function(collectionApi) {
|
||||||
|
const recipes = collectionApi.getFilteredByTag("recipe");
|
||||||
|
const tagMap = {};
|
||||||
|
|
||||||
|
recipes.forEach(recipe => {
|
||||||
|
const customTags = (recipe.data.tags || []).filter(t => !["recipe", "all", "nav"].includes(t));
|
||||||
|
const tagsToUse = customTags.length > 0 ? customTags : ["other"];
|
||||||
|
|
||||||
|
tagsToUse.forEach(tag => {
|
||||||
|
if (!tagMap[tag]) {
|
||||||
|
tagMap[tag] = [];
|
||||||
|
}
|
||||||
|
tagMap[tag].push(recipe);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return Object.keys(tagMap).sort().map(tag => ({
|
||||||
|
tagName: tag,
|
||||||
|
recipes: tagMap[tag].sort((a, b) => (a.data.title || "").localeCompare(b.data.title || ""))
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
eleventyConfig.addCollection("recipesByAuthor", function(collectionApi) {
|
||||||
|
const recipes = collectionApi.getFilteredByTag("recipe");
|
||||||
|
const authorMap = {};
|
||||||
|
|
||||||
|
recipes.forEach(recipe => {
|
||||||
|
const author = (recipe.data.author || "Unknown Cook").trim();
|
||||||
|
if (!authorMap[author]) {
|
||||||
|
authorMap[author] = [];
|
||||||
|
}
|
||||||
|
authorMap[author].push(recipe);
|
||||||
|
});
|
||||||
|
|
||||||
|
return Object.keys(authorMap).sort().map(author => ({
|
||||||
|
authorName: author,
|
||||||
|
recipes: authorMap[author].sort((a, b) => (a.data.title || "").localeCompare(b.data.title || ""))
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dir: {
|
dir: {
|
||||||
input: "src", // Where your markdown files live
|
input: "src", // Where your markdown files live
|
||||||
|
|||||||
Reference in New Issue
Block a user