A simple starter kit for Eleventy-based static sites for the Fluid Project.
This repository contains the files needed to build Eleventy-based static sites for the Fluid Project. It includes support for internationalization; if your project does not require internationalization, use Trivet Monolingual instead.
You can use GitHub's template repository feature to create your own project based on Trivet Monolingual. From the repository homepage, click the "Use this template" button and then choose "Create a new repository".
You can also set up a new project locally using degit:
npx degit fluid-project/trivet YOUR-PROJECT-NAME- Install the required NPM packages:
npm install - Run Eleventy in development mode:
npm start.
The website will be available at http://localhost:8080.
You can build and serve the website from a Docker container.
Once you have Docker installed, run the following commands to build a Docker image and start a container:
- Build the image:
docker build -t trivet . - Run the container:
docker run --name trivet -p 8000:80 trivet
The website will be available at http://localhost:8000
If you make changes to the website, repeat the steps to build the image and start a new container.
- Install the required NPM packages:
npm install - Run the build script:
npm run build - Upload the contents of the
./_site/directory to the web root of your server.
If you make changes to the website, repeat step 2 to build the website and upload any changed files from the ./_site/
directory to the web root of your server.
- Basic static site configuration for developing project websites and blogs.
- Starter configuration for Sveltia CMS.
- Integrated User Interface Options Preferences Editor.
- Internationalization support.
Modifications can be made to any source file or directory except for the contents of the _site directory. The
_site directory is not versioned since it contains the built website that Eleventy generates from the source files,
and files in _site are overwritten at build time.
The Sveltia CMS configuration can be edited in src/admin/config.yml.
For full documentation, see the Sveltia CMS documentation.
Trivet includes internationalization support for English (Canada) and French (Canada). More languages can be added. If your project doesn't require internationalization,
To add a language, the following changes need to be made:
-
Update the
localesarray ofsrc/_data/config.jsonto add the new language. For example, to add German, you would add the IETF language codede:{ "locales": [ + "de", "en", "fr" ], } -
Add a new key to
src/_data/site.jsonfor the new language which provides the site metadata in the new language:{ "en": { "name": "Trivet", "description": "Trivet is a simple starter kit for Eleventy-based static sites for the Fluid Project.", "url": "https://trivet.netlify.app", "authorWebsite": "https://fluidproject.org/", "authorEmail": "idrc@ocadu.ca", "authorName": "Fluid Project" }, "fr": { "name": "Trivet", "description": "Trivet est un kit de démarrage simple pour les sites statiques basés sur Eleventy pour le projet Fluid.", "url": "https://trivet.netlify.app", "authorWebsite": "https://fluidproject.org/", "authorEmail": "idrc@ocadu.ca", "authorName": "Projet Fluid" - } + }, + "de": { + ... + }, } -
Modify
src/admin/config.ymlto support the new language:- locales: [en, fr] + locales: [en, fr, de]
-
Update the
eleventy-plugin-fluidconfiguration'ssupportedLanguagesobject ineleventy.config.jswith the following data:slug: a short form of the language code for use in URLsuioSlug: a short form of the language code that corresponds to an available message bundle locale for Infusion's User Interface Options (if UIO is not localized in that language, you can omit this option)dir: the direction of the language (ltrfor left to right orrtlfor right to left)name: the localized language name (endonym), which will be used to link to content in that language
eleventyConfig.addPlugin(fluidPlugin, { defaultLanguage: "en-CA", localesDirectory: "src/_locales", supportedLanguages: { "en": { slug: "en", name: "English" }, + "de": { + slug: "de", + dir: "ltr", + name: "Deutsch", + }, "fr": { slug: "fr", name: "Français" } } });You can change the site's default language by changing the the
eleventy-plugin-fluidconfiguration'sdefaultLanguagestring ineleventy.config.jsto the IETF language code of the desired default language. -
Add directories in each collection for translated content. For example, you would add a directory called
detosrc/collections/pagesandsrc/collections/posts. Eachdedirectory will also need a directory data file calledde.json. The contents should be identical to the default language directory'sde.jsonfile (except with the appropriate language code). -
Create a localized version of the posts archive page, following the example of
src/collections/pages/fr-CA/posts.md.
For more information about how Sveltia CMS works with internationalized content, see the internationalization support documentation.
If you do not need internationalization support for all content on your site, it can be disabled for a specific collection or collections. If you don't need internationalization support at all, you should use Trivet Monolingual as the basis of your project instead.
If your site is translated into more than two languages but you aren't translating all your content, any empty
collection will not be output by Eleventy. For example, if your site is configured to use en, fr and
de but you are not translating your posts into de, you can leave the /src/collections/posts/de
directory empty and the German posts index page will not be built. However, if you want to disable all
internationalization for a specific collection, you can do so in one of two ways.
-
Deleting all directories but the default locale in the
/src/collections/<collection>/directory. For example, to disable localization for posts, delete the/src/collections/posts/fr/directory. -
Modify the
src/admin/config.ymlcollection block'si18nandfolderproperties for the relevant collection. For example, to disable localization for posts, make the following changes in thepostsblock:- i18n: - structure: multiple_folders + i18n: false - folder: "src/collections/posts/" + folder: "src/collections/posts/en/" # Look for posts to edit in the default locale directory.
-
Modify the
src/admin/config.ymlcollection block'si18nproperty for the relevant collection. For example, to disable localization for posts, make the following changes in thepostsblock:- i18n: - structure: multiple_folders + i18n: false
-
Remove all locale subdirectories of
src/collections/posts, moving theen(or other default language) subdirectory's contents (with the exception of theen.jsonfile) up intosrc/collections/posts. You'll also need to make the following changes to the collection's directory data file, in this casesrc/collections/posts.11tydata.js:- import {__, generatePermalink} from 'eleventy-plugin-fluid'; + import {generatePermalink} from 'eleventy-plugin-fluid'; export default { layout: 'layouts/post', eleventyComputed: { - langDir: data => data.supportedLanguages[data.lang].dir, + langDir: data => data.supportedLanguages[data.defaultLanguage].dir, permalink(data) { - return generatePermalink(data, 'posts', __('posts', {}, data)); + return generatePermalink(data, 'posts'); }, }, };
-
Disable localization of the index pages for the collection. In the case of posts, the configuration file creates indexes of posts in each language:
/* eslint-disable no-undef, @stylistic/indent */ const now = new Date(); const livePosts = post => post.date <= now && !post.data.draft; // Custom collections for (const locale of siteConfig.locales) { eleventyConfig.addCollection(`posts_${locale}`, collection => collection .getFilteredByGlob(`./src/collections/posts/${locale}/*.md`) .filter(posts => livePosts(posts))); // The following collection is used to create a collection of posts for the RSS feed. eleventyConfig.addCollection(`postFeed_${locale}`, collection => collection .getFilteredByGlob(`./src/collections/posts/${locale}/*.md`) .filter(posts => livePosts(posts)) .toReversed() .slice(0, siteConfig.maxPostsInFeed)); }
You'll only need one index, so you can change this as follows:
const now = new Date(); const livePosts = post => post.date <= now && !post.data.draft; // Custom collections - for (const locale of siteConfig.locales) { - eleventyConfig.addCollection(`posts_${locale}`, collection => collection - .getFilteredByGlob(`./src/collections/posts/${locale}/*.md`) - .filter(posts => livePosts(posts))); + eleventyConfig.addCollection("posts", collection => { + return collection.getFilteredByGlob("./src/collections/posts/*.md").filter(posts => livePosts(posts)); + }); // The following collection is used to create a collection of posts for the RSS feed. - eleventyConfig.addCollection(`postFeed_${locale}`, collection => collection - .getFilteredByGlob(`./src/collections/posts/${locale}/*.md`) - .filter(posts => livePosts(posts)) - .toReversed() - .slice(0, siteConfig.maxPostsInFeed)); - } + eleventyConfig.addCollection("postFeed", collection => { + return collection.getFilteredByGlob("./src/collections/posts/*.md").filter(posts => livePosts(posts)) + .toReversed() + .slice(0, siteConfig.maxPostsInFeed); + });Then you'll need to modify the
posts.mdpage in all locales to reflect the new collection:pagination: - data: collections.posts_fr + data: collections.posts size: 10 alias: posts
-
Lastly, for posts, you will also need to remove the localized feed by editing
src/feed.njk:
- pagination:
- data: config.locales
- size: 1
- alias: locale
+ locale: "{{ defaultLanguage }}"
- permalink: "{% if lang !== defaultLanguage %}/{{ supportedLanguages[lang].slug }}{% endif %}/feed.xml"
+ permalink: /feed.xml
eleventyExcludeFromCollections: true
+ collection: "postFeed"
---
- {% set collection = "postFeed_" + lang %}
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ lang }}">
<title>{{ site[lang].name }}</title>
- <subtitle>{% __ 'rss', {site: site[lang].name} %}</subtitle>
+ <subtitle>The most recent posts from {{ site.name }}</subtitle>Trivet is available under the New BSD License.
Trivet is based on other publicly available software, categorized by license: