vegan-prestwich/.eleventy.js

102 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2024-04-14 22:13:53 +00:00
const fg = require("fast-glob");
2022-11-27 23:45:57 +00:00
2024-04-14 22:13:53 +00:00
const placeImages = fg.sync([
"place/*/*.jpg",
"!**/_site",
"!place/*/*-thumb.jpg",
]);
const Image = require("@11ty/eleventy-img");
module.exports = function (config) {
2024-11-30 14:58:14 +00:00
config.addGlobalData("siteUrl", "https://www.veganprestwich.co.uk");
2024-04-14 22:13:53 +00:00
config.addShortcode("image", async (src, alt, sizes) => {
let metadata = await Image(src, {
widths: [150, 300],
formats: ["webp", "jpeg"],
2024-11-30 14:58:14 +00:00
outputDir: "./_site/img/",
2024-04-14 22:13:53 +00:00
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
// You bet we throw an error on a missing alt (alt="" works okay)
return Image.generateHTML(metadata, imageAttributes);
});
2022-11-27 23:45:57 +00:00
// Aliases are in relation to the _includes folder
2024-04-14 22:13:53 +00:00
config.addLayoutAlias("default", "layouts/default.liquid");
config.addLayoutAlias("home", "layouts/home.liquid");
config.addLayoutAlias("page", "layouts/page.liquid");
config.addLayoutAlias("place", "layouts/place.liquid");
config.addLayoutAlias("tag", "layouts/tag.liquid");
config.addLayoutAlias("tags", "layouts/tags.liquid");
2022-11-27 23:45:57 +00:00
2022-11-28 00:49:39 +00:00
let sortedPlaces = (api) => {
2024-04-14 22:13:53 +00:00
return api
.getAll()
.filter((a) => {
return a.data.tags && a.data.tags.indexOf("places") != -1;
})
.sort((a, b) => {
return a.data.name.localeCompare(b.data.name);
});
};
2022-11-25 00:54:51 +00:00
2022-11-28 00:49:39 +00:00
config.addCollection("sorted_places", (api) => sortedPlaces(api));
2022-11-27 23:45:57 +00:00
config.addCollection("shops", (api) =>
2024-11-30 14:58:14 +00:00
sortedPlaces(api).filter((a) => a.data.permalink && a.data.shop),
2024-04-14 22:13:53 +00:00
);
2022-11-27 23:45:57 +00:00
config.addCollection("restaurants", (api) =>
2024-11-30 14:58:14 +00:00
sortedPlaces(api).filter((a) => a.data.permalink && a.data.restaurant),
2024-04-14 22:13:53 +00:00
);
2022-11-27 23:45:57 +00:00
config.addCollection("deliveries", (api) =>
2024-11-30 14:58:14 +00:00
sortedPlaces(api).filter((a) => a.data.permalink && a.data.delivery),
2024-04-14 22:13:53 +00:00
);
2022-11-27 23:45:57 +00:00
config.addWatchTarget("./style/style.scss");
2024-04-14 22:13:53 +00:00
config.addCollection("place_images", (collection) => placeImages);
config.addPassthroughCopy("place/*/*.jpg");
2024-04-14 22:13:53 +00:00
config.addPassthroughCopy({ "static/robots.txt": "/robots.txt" });
config.addPassthroughCopy({ "static/not_found.html": "/not_found.html" });
config.addPassthroughCopy({ "static/favicon.ico": "/favicon.ico" });
2022-11-27 23:45:57 +00:00
2024-04-14 22:13:53 +00:00
config.addFilter("where", (array, key, value) => {
return (array || []).filter((item) => {
const keys = key.split(".");
2022-11-28 00:24:52 +00:00
const reducedKey = keys.reduce((object, key) => {
return object[key];
}, item);
2024-04-14 22:13:53 +00:00
return reducedKey == value ? item : false;
2022-11-28 00:24:52 +00:00
});
});
2024-04-14 22:13:53 +00:00
config.addFilter("where_includes", (array, key, value) => {
return (array || []).filter((item) => {
const keys = key.split(".");
2022-11-28 00:24:52 +00:00
const reducedKey = keys.reduce((object, key) => {
return object[key];
}, item);
2024-04-14 22:13:53 +00:00
return reducedKey && reducedKey.indexOf(value) != -1 ? item : false;
2022-11-28 00:24:52 +00:00
});
});
2022-11-25 00:54:51 +00:00
return {
dir: {
2022-11-27 23:45:57 +00:00
input: "./",
2024-04-14 22:13:53 +00:00
output: "./_site",
},
2022-11-25 00:54:51 +00:00
};
2022-11-28 02:35:02 +00:00
};