-
I'm integrating Netlify CMS with 11ty atm and saw that when an i18n setup is used, 11ty will build everything in the output dir as expected but for the default language of a website this then results in urls that have the locale appended/prefixed. Is it possible to hook into the build process and change the output folder for content based on in which locale folder they are?
I would like everything that is in
That way all urls in default language would not contain any locale, and only translations would have their respective locale. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
OK, I think this might work… I have the following file structure (where tree . -aI node_modules
.
├── .eleventy.js
├── package-lock.json
├── package.json
├── src/
│ └── pages/
│ ├── de/
│ │ ├── one.md
│ │ └── three.md
│ └── en/
│ ├── en.11tydata.json
│ ├── one.md
│ ├── three.md
│ └── two.md
└── www/
└── pages/
├── de/
│ ├── one/
│ │ └── index.html
│ └── three/
│ └── index.html
├── one/
│ └── index.html
├── three/
│ └── index.html
└── two/
└── index.html
12 directories, 14 files // .eleventy.js
module.exports = (eleventyConfig) => {
// Probably not needed, and I think this will be the new default in 11ty v1.
eleventyConfig.setDataDeepMerge(true);
return {
dir: {
input: "src",
output: "www",
}
};
}; So really, the only interesting file is the ./src/pages/en/en.11tydata.json directory data file: {
"eleventyComputed": {
"permalink": "{{ page.filePathStem | replace: '/en/', '/' }}/"
}
} I think the above "works" because liquidjs is the default processor, so we're actually using the LiquidJS Or, if you want a bit more flexability, I'd probably rename it to "en.11tydata.js" (JavaScript instead of JSON w/ template strings), and do something like this: // ./src/pages/en/en.11tydata.js
module.exports = {
eleventyComputed: {
permalink(data) {
return `${data.page.filePathStem.replace("/en/", "/")}/`;
}
}
} As always, could be a lot of edge cases and other issues to work around (what if you explicitly set |
Beta Was this translation helpful? Give feedback.
-
@pdehaan I've been trying this and other methods all day. In the end, I again went the default 11ty route, I realized it is possible to redirect the output just by using permalinks. So all I had to do was this: Add the language data files like With this content: {
"dir": "ltr",
"locale": "en"
} In the {
"layout": "layouts/page.njk",
"permalink": "{{ locale }}/{{ page.fileSlug }}/"
} With this content: {
"dir": "ltr",
"locale": "en"
}
permalink: "/{{ locale }}/" And the permalink: / 11ty then builds everything into This way I can now have the directory structure that Netlify CMS supports for i18n websites, and it's then in the build step where the site is built into the structure 11ty recommends :) |
Beta Was this translation helpful? Give feedback.
OK, I think this might work…
I have the following file structure (where
src/
are my input files, andwww/
are my output files):