-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheleventy.config.js
More file actions
45 lines (39 loc) · 1.35 KB
/
eleventy.config.js
File metadata and controls
45 lines (39 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { EleventyI18nPlugin } = require("@11ty/eleventy");
module.exports = function(eleventyConfig) {
// Pass through static assets
eleventyConfig.addPassthroughCopy("src/assets");
eleventyConfig.addPassthroughCopy("src/api");
eleventyConfig.addPassthroughCopy("src/favicon.svg");
eleventyConfig.addPassthroughCopy("src/indexnow-key.txt");
// Enable the i18n plugin
eleventyConfig.addPlugin(EleventyI18nPlugin, {
defaultLanguage: "en",
errorMode: "allow-fallback"
});
// Translation filter: {{ "hero.title" | t(locales, page.lang) }}
eleventyConfig.addFilter("t", function(key, locales, lang = 'en') {
const translations = locales[lang] || locales['en'];
if (!translations) return key;
return key.split('.').reduce((obj, i) => (obj ? obj[i] : null), translations) || key;
});
// URL switcher filter
eleventyConfig.addFilter("langUrl", function(url, newLang) {
if (!url) return `/${newLang}/`;
return url.replace(/^\/[a-z]{2}\//, `/${newLang}/`);
});
// Date ISO formatter filter
eleventyConfig.addFilter("dateIso", function(date) {
if (!date) return "";
return new Date(date).toISOString().split('T')[0];
});
return {
dir: {
input: "src",
output: "_site",
includes: "_includes",
data: "_data"
},
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk"
};
};