leDailySquirrel/eleventy.config.js
2026-07-04 14:55:57 -05:00

42 lines
1.7 KiB
JavaScript

module.exports = function(eleventyConfig) {
// 1. Collection: All published editions, newest first
eleventyConfig.addCollection("publishedEditions", function(collectionApi) {
return collectionApi.getFilteredByGlob("content/editions/*/index.md")
.filter(item => item.data.status === "published")
.sort((a, b) => b.date - a.date); // Sort descending
});
// 2. Collection: The current (newest) published edition for the index page
eleventyConfig.addCollection("currentEdition", function(collectionApi) {
const published = collectionApi.getFilteredByGlob("content/editions/*/index.md")
.filter(item => item.data.status === "published")
.sort((a, b) => b.date - a.date);
return published.length > 0 ? [published[0]] : [];
});
// 3. Layout aliases so you don't have to type the full path in front matter
eleventyConfig.addLayoutAlias("edition", "layouts/edition.njk");
eleventyConfig.addLayoutAlias("article", "layouts/article.njk");
eleventyConfig.addLayoutAlias("base", "layouts/base.njk");
// 4. Force UTC date formatting to fix the 5-hour timezone shift
eleventyConfig.addFilter("newsDate", function(dateObj) {
return new Date(dateObj).toLocaleDateString('en-US', {
timeZone: 'UTC',
weekday: 'long',
month: 'long',
day: 'numeric',
year: 'numeric'
});
});
return {
dir: {
input: "content",
includes: "../_includes", // Keeps templates safely outside the content dir
output: "dist"
},
templateFormats: ["md", "njk", "html"]
};
};