diff --git a/.eleventy.js b/.eleventy.js index 724fd46..64a0e20 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -8,6 +8,7 @@ const Image = require('@11ty/eleventy-img'); const markdownIt = require('markdown-it'); const markdownItAnchor = require('markdown-it-anchor'); const markdownItAttrs = require('markdown-it-attrs'); +const { EleventyI18nPlugin } = require('@11ty/eleventy'); function hyphenize(input) { return input @@ -27,6 +28,9 @@ module.exports = function (eleventyConfig) { eleventyConfig.addPlugin(pluginRss); eleventyConfig.addPlugin(pluginSyntaxHighlight); eleventyConfig.addPlugin(pluginNavigation); + eleventyConfig.addPlugin(EleventyI18nPlugin, { + defaultLanguage: "de", + }); eleventyConfig.setDataDeepMerge(true); @@ -56,20 +60,36 @@ module.exports = function (eleventyConfig) { } eleventyConfig.addFilter('filterTagList', filterTagList); + // Create separate collections for the different locales + function sortByLocales(items) { + return items.reduce((sorted, item) => ({ + ...sorted, + [`${item.page.lang}`]: [ + ...(sorted[item.page.lang] ?? []), + item + ], + }), {}) + } + // Build collections for the top and bottom navigation - the first one // contains the main sites and the latter contains legal pages. eleventyConfig.addCollection('topNavigation', (collection) => { - return collection + const topNavigation = collection .getAll() .filter((item) => !(item.data.tags || []).includes('legal')); + return sortByLocales(topNavigation); }); + eleventyConfig.addCollection('bottomNavigation', (collection) => { - return collection + const bottomNavigation = collection .getAll() .filter((item) => (item.data.tags || []).includes('legal')); + return sortByLocales(bottomNavigation); }); + eleventyConfig.addCollection('posts', (collection) => { - return collection.getAll().filter((item) => item.data.layout === 'post'); + const posts = collection.getAll().filter((item) => item.data.layout === 'post'); + return sortByLocales(posts); }); // diff --git a/includes/layouts/base/main.njk b/includes/layouts/base/main.njk index 61488d5..c1eb06d 100644 --- a/includes/layouts/base/main.njk +++ b/includes/layouts/base/main.njk @@ -1,5 +1,5 @@ - +