eleventy-dot-js-blog/content
By default, Eleventy works with your project’s existing directory structure. Unlike other static site generators, Eleventy let’s you choose how to organize your content.
This directory shows one way to organize content into pages and posts, like a typical blog. If you wanted to use this project to publish an e-book, you might use directories for each of the parts and chapters. Or, if you wanted to make a glossary, you might use directories for each letter of the alphabet.
The content.11tydata.js file here defines directory data, accessible in templates via the data object. For example, because content.11tydata.js defines a locale property, all the templates in this directory as well as any directories nested inside this one will inherit that data.locale value (i.e., en for English). You can override that “default” value by specifying a new locale value in either a template data file or the front matter data for a given template.
See the Eleventy documentation for more information about the data cascade.
To carry the data.locale example further, this directory structure also allows you to add support for internationalization (i18n) and localization (l10n).
Here’s an example of one way you might go about adding Spanish-language content:
- Make a directory named
esinside this one (optionally, you could move all existing English-language content into a newendirectory too) - Nest corresponding copies of the
pagesandpostsdirectories inside the newly createdesdirectory (e.g.,content/es/pagesandcontent/es/posts) - Copy
content.11tydata.jsto theesdirectory, and rename the copied filees.11tydata.js - Do the same for
content/es/pages/pages.11tydata.jsandcontent/es/posts/posts.11tydata.js - Copy
content/index.md(the blog home page) tocontent/es/index.mdand setpermalinkto'/es/'in the front matter data - Add an identical front matter data property to each of the multilingual content files (don’t translate the value, e.g., add
translationKey: 'about'in the front matter for bothpages/about.mdandes/pages/about.md, ortranslationKey: 'home'inside bothcontect/index.mdandcontent/es/index.md)
See ../_data/README.md for instructions on how to translate global data strings.
For a discussion of how a multilingual setup like this might work (using Nunjucks templates), check out Jérôme Coupé’s pair of blog posts from 2019 on “Multilingual Sites with Eleventy” and prototype for a “Language switcher for multilingual JAMstack sites”.