From 956edcdde0f657fd9868d8af4fe72eed7211cf40 Mon Sep 17 00:00:00 2001 From: venus Date: Sat, 1 Aug 2026 12:35:16 -0500 Subject: [PATCH] added several qol scripts and shortcuts --- eleventy.config.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/eleventy.config.js b/eleventy.config.js index 97141ba..7e47a1c 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -4,6 +4,53 @@ module.exports = function(eleventyConfig) { host: "0.0.0.0", 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 { dir: { input: "src", // Where your markdown files live