const i18n = require('eleventy-plugin-i18n'); const translations = require('./src/_data/i18n'); module.exports = function (eleventyConfig) { // Plugins eleventyConfig.addPlugin(i18n, { defaultLanguage: 'de', localesDirectory: 'src', // optional: customize the URL structure urlPrefix: locale => (locale === 'de' ? '' : `/${locale}`), translations, fallbackLocales: { '*': 'de' } }); // TEMP demo of what could be an i18n-aware plural package? eleventyConfig.addFilter('pluralize', function (term, count = 1) { // Poorman's pluralize for now... return count === 1 ? term : `${term}s`; }); eleventyConfig.addFilter('localizedPermalink', (slug, locale) => { const newPath = locale === 'de' ? `${slug.slice(3)}.html` : `${slug}.html`; return `${newPath}`; }); // these folders will be copied into webroot // e.g. /image => /_site/image eleventyConfig.addPassthroughCopy('image'); eleventyConfig.addPassthroughCopy('css'); eleventyConfig.addPassthroughCopy('font'); // contents of public folder will be copied into webroot // e.g. /public/something.html => /_site/something.html eleventyConfig.addPassthroughCopy({ "public": "." }); // Browsersync // Redirect from root to default language root during --serve // Can also be handled by netlify.toml? eleventyConfig.setBrowserSyncConfig({ callbacks: { ready: function (err, bs) { bs.addMiddleware('*', (req, res) => { if (req.url === '/') { res.writeHead(302, { location: '/en/' }); res.end(); } }); } } }); // Configuration return { dir: { input: 'src' }, markdownTemplateEngine: 'njk' }; };