mirror of
https://github.com/Sea-Haven-Industries/seahaven-site.git
synced 2026-09-30 05:23:18 +00:00
31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
|
|
const images = require("./_data/images.json");
|
||
|
|
|
||
|
|
module.exports = function (eleventyConfig) {
|
||
|
|
// Static assets shipped verbatim to the document root.
|
||
|
|
eleventyConfig.addPassthroughCopy("assets");
|
||
|
|
eleventyConfig.addPassthroughCopy("robots.txt");
|
||
|
|
eleventyConfig.addPassthroughCopy("sitemap.xml");
|
||
|
|
|
||
|
|
// {% image "key", "alt text", 'loading="lazy" class="x"' %}
|
||
|
|
// Emits an <img> with width/height from _data/images.json (prevents CLS).
|
||
|
|
eleventyConfig.addShortcode("image", function (key, alt, attrs = "") {
|
||
|
|
const img = images[key];
|
||
|
|
if (!img) {
|
||
|
|
throw new Error(`image shortcode: unknown key "${key}" (add it to _data/images.json)`);
|
||
|
|
}
|
||
|
|
const safeAlt = String(alt).replace(/"/g, """);
|
||
|
|
const extra = attrs ? " " + attrs : "";
|
||
|
|
return `<img src="${img.src}" width="${img.w}" height="${img.h}" alt="${safeAlt}"${extra}>`;
|
||
|
|
});
|
||
|
|
|
||
|
|
// Current year, for the footer (replaces the deprecated document.write pattern).
|
||
|
|
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
|
||
|
|
|
||
|
|
return {
|
||
|
|
dir: { input: ".", includes: "_includes", data: "_data", output: "_site" },
|
||
|
|
templateFormats: ["njk"],
|
||
|
|
htmlTemplateEngine: "njk",
|
||
|
|
markdownTemplateEngine: "njk",
|
||
|
|
};
|
||
|
|
};
|