From 2491464043a6ecf01052ebcd037d9561d988519d Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Fri, 15 Jul 2022 12:11:54 -0500 Subject: [PATCH] First commit of i18n base blog using Eleventy v2. This uses English-implied URLs. --- .eleventy.js | 7 ++++++ .eleventyignore | 1 - _includes/layouts/base.njk | 4 +++- _includes/layouts/post.njk | 25 ++++++++++++++++------ 404.md => en/404.md | 0 {about => en/about}/index.md | 0 archive.njk => en/blog.njk | 1 - posts/posts.json => en/blog/blog.json | 0 {posts => en/blog}/firstpost.md | 0 {posts => en/blog}/fourthpost.md | 0 {posts => en/blog}/secondpost.md | 0 {posts => en/blog}/thirdpost.md | 0 en/en.11tydata.js | 9 ++++++++ index.njk => en/index.njk | 7 ++++++ tags-list.njk => en/tags-list.njk | 0 tags.njk => en/tags.njk | 0 es/blog/fourthpost.md | 14 ++++++++++++ es/blog/thirdpost.md | 13 +++++++++++ es/es.11tydata.js | 11 ++++++++++ feed/feed.11tydata.js | 3 +++ feed/feed.njk | 1 - feed/htaccess.njk | 6 ------ feed/json.njk | 1 - package.json | 4 ++-- page-list.njk | 24 --------------------- sitemap.xml.njk => sitemap/sitemap.xml.njk | 0 26 files changed, 88 insertions(+), 43 deletions(-) delete mode 100644 .eleventyignore rename 404.md => en/404.md (100%) rename {about => en/about}/index.md (100%) rename archive.njk => en/blog.njk (89%) rename posts/posts.json => en/blog/blog.json (100%) rename {posts => en/blog}/firstpost.md (100%) rename {posts => en/blog}/fourthpost.md (100%) rename {posts => en/blog}/secondpost.md (100%) rename {posts => en/blog}/thirdpost.md (100%) create mode 100644 en/en.11tydata.js rename index.njk => en/index.njk (76%) rename tags-list.njk => en/tags-list.njk (100%) rename tags.njk => en/tags.njk (100%) create mode 100644 es/blog/fourthpost.md create mode 100644 es/blog/thirdpost.md create mode 100644 es/es.11tydata.js create mode 100644 feed/feed.11tydata.js delete mode 100644 feed/htaccess.njk delete mode 100644 page-list.njk rename sitemap.xml.njk => sitemap/sitemap.xml.njk (100%) diff --git a/.eleventy.js b/.eleventy.js index 952f7f2..f853843 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,11 +1,14 @@ const { DateTime } = require("luxon"); const markdownItAnchor = require("markdown-it-anchor"); +const { EleventyI18nPlugin } = require("@11ty/eleventy"); const pluginRss = require("@11ty/eleventy-plugin-rss"); const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight"); const pluginNavigation = require("@11ty/eleventy-navigation"); module.exports = function(eleventyConfig) { + eleventyConfig.ignores.add("README.md"); + // Copy the `img` and `css` folders to the output eleventyConfig.addPassthroughCopy("img"); eleventyConfig.addPassthroughCopy("css"); @@ -14,6 +17,10 @@ module.exports = function(eleventyConfig) { eleventyConfig.addPlugin(pluginRss); eleventyConfig.addPlugin(pluginSyntaxHighlight); eleventyConfig.addPlugin(pluginNavigation); + eleventyConfig.addPlugin(EleventyI18nPlugin, { + defaultLanguage: "en", + errorMode: "allow-fallback", + }); eleventyConfig.addFilter("readableDate", dateObj => { return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("dd LLL yyyy"); diff --git a/.eleventyignore b/.eleventyignore deleted file mode 100644 index b43bf86..0000000 --- a/.eleventyignore +++ /dev/null @@ -1 +0,0 @@ -README.md diff --git a/_includes/layouts/base.njk b/_includes/layouts/base.njk index a1787c9..7bf676f 100644 --- a/_includes/layouts/base.njk +++ b/_includes/layouts/base.njk @@ -1,5 +1,5 @@ - + @@ -14,6 +14,8 @@ + + {# TODO add link rel="alternate" for langs #}
diff --git a/_includes/layouts/post.njk b/_includes/layouts/post.njk index bf2d93f..34d0887 100644 --- a/_includes/layouts/post.njk +++ b/_includes/layouts/post.njk @@ -12,14 +12,27 @@ templateClass: tmpl-post {{ content | safe }} -{%- if collections.posts %} -{%- set nextPost = collections.posts | getNextCollectionItem(page) %} -{%- set previousPost = collections.posts | getPreviousCollectionItem(page) %} -{%- if nextPost or previousPost %}
+ +{% set i18nLinks = page.url | locale_links %} +{% if i18nLinks.length %} +{% endif %} + +{%- if collections.posts %} +{%- set previousPost = collections.posts | getPreviousCollectionItem() %} +{%- set nextPost = collections.posts | getNextCollectionItem() %} +{%- if nextPost or previousPost %} + {%- endif %} {%- endif %} diff --git a/404.md b/en/404.md similarity index 100% rename from 404.md rename to en/404.md diff --git a/about/index.md b/en/about/index.md similarity index 100% rename from about/index.md rename to en/about/index.md diff --git a/archive.njk b/en/blog.njk similarity index 89% rename from archive.njk rename to en/blog.njk index 0b277a8..7fde8b9 100644 --- a/archive.njk +++ b/en/blog.njk @@ -1,6 +1,5 @@ --- layout: layouts/home.njk -permalink: /posts/ eleventyNavigation: key: Archive order: 2 diff --git a/posts/posts.json b/en/blog/blog.json similarity index 100% rename from posts/posts.json rename to en/blog/blog.json diff --git a/posts/firstpost.md b/en/blog/firstpost.md similarity index 100% rename from posts/firstpost.md rename to en/blog/firstpost.md diff --git a/posts/fourthpost.md b/en/blog/fourthpost.md similarity index 100% rename from posts/fourthpost.md rename to en/blog/fourthpost.md diff --git a/posts/secondpost.md b/en/blog/secondpost.md similarity index 100% rename from posts/secondpost.md rename to en/blog/secondpost.md diff --git a/posts/thirdpost.md b/en/blog/thirdpost.md similarity index 100% rename from posts/thirdpost.md rename to en/blog/thirdpost.md diff --git a/en/en.11tydata.js b/en/en.11tydata.js new file mode 100644 index 0000000..7d01bf1 --- /dev/null +++ b/en/en.11tydata.js @@ -0,0 +1,9 @@ +module.exports = { + lang: "en", + permalink: function(data) { + // Change (English) /en/blog/my-post URLs to have an implied language code /blog/my-post URLs instead. + let [slashPrefixEmpty, langCode, ...stem] = data.page.filePathStem.split("/"); + let path = stem.join("/"); + return stem[stem.length - 1] === "index" ? `${path}.html` : `${path}/index.html`; + } +} diff --git a/index.njk b/en/index.njk similarity index 76% rename from index.njk rename to en/index.njk index bf096f7..3a24fca 100644 --- a/index.njk +++ b/en/index.njk @@ -12,3 +12,10 @@ eleventyNavigation: {% include "postslist.njk" %}

More posts can be found in the archive.

+ + + diff --git a/tags-list.njk b/en/tags-list.njk similarity index 100% rename from tags-list.njk rename to en/tags-list.njk diff --git a/tags.njk b/en/tags.njk similarity index 100% rename from tags.njk rename to en/tags.njk diff --git a/es/blog/fourthpost.md b/es/blog/fourthpost.md new file mode 100644 index 0000000..6c3c565 --- /dev/null +++ b/es/blog/fourthpost.md @@ -0,0 +1,14 @@ +--- +title: Esta es mi cuarta publicación. +slugOverride: cuarta publicación +date: 2018-09-30 +layout: layouts/post.njk +--- +Aproveche los marcos ágiles para proporcionar una sinopsis sólida para descripciones generales de alto nivel. Los enfoques iterativos de la estrategia corporativa fomentan el pensamiento colaborativo para promover la propuesta de valor general. Hacer crecer orgánicamente la visión holística del mundo de la innovación disruptiva a través de la diversidad y el empoderamiento en el lugar de trabajo. + +Traiga a la mesa estrategias de supervivencia de ganar-ganar para asegurar una dominación proactiva. Al final del día, en el futuro, una nueva normalidad que ha evolucionado desde la generación X está en camino hacia una solución de nube optimizada. El contenido generado por el usuario en tiempo real tendrá múltiples puntos de contacto para la deslocalización. + +## Encabezado de sección + +Saque provecho de la fruta al alcance de la mano para identificar una actividad de valor agregado de estadio de béisbol para la prueba beta. Supere la brecha digital con clics adicionales de DevOps. La inmersión en nanotecnología a lo largo de la autopista de la información cerrará el círculo centrándose únicamente en el resultado final. + diff --git a/es/blog/thirdpost.md b/es/blog/thirdpost.md new file mode 100644 index 0000000..2d965ba --- /dev/null +++ b/es/blog/thirdpost.md @@ -0,0 +1,13 @@ +--- +title: Esta es mi tercer publicación. +date: 2018-09-30 +layout: layouts/post.njk +--- +Aproveche los marcos ágiles para proporcionar una sinopsis sólida para descripciones generales de alto nivel. Los enfoques iterativos de la estrategia corporativa fomentan el pensamiento colaborativo para promover la propuesta de valor general. Hacer crecer orgánicamente la visión holística del mundo de la innovación disruptiva a través de la diversidad y el empoderamiento en el lugar de trabajo. + +Traiga a la mesa estrategias de supervivencia de ganar-ganar para asegurar una dominación proactiva. Al final del día, en el futuro, una nueva normalidad que ha evolucionado desde la generación X está en camino hacia una solución de nube optimizada. El contenido generado por el usuario en tiempo real tendrá múltiples puntos de contacto para la deslocalización. + +## Encabezado de sección + +Saque provecho de la fruta al alcance de la mano para identificar una actividad de valor agregado de estadio de béisbol para la prueba beta. Supere la brecha digital con clics adicionales de DevOps. La inmersión en nanotecnología a lo largo de la autopista de la información cerrará el círculo centrándose únicamente en el resultado final. + diff --git a/es/es.11tydata.js b/es/es.11tydata.js new file mode 100644 index 0000000..4267c79 --- /dev/null +++ b/es/es.11tydata.js @@ -0,0 +1,11 @@ +module.exports = { + "lang": "es", + "permalink": function(data) { + // Slug override is set in the post for localized URL slugs + // e.g. /es/blog/fourthpost.md will optionally write to + // /es/blog/cuarta-publicacion/ instead of /es/blog/fourth-post/ + if(data.slugOverride) { + return `/${data.lang}/blog/${this.slugify(data.slugOverride)}/`; + } + } +} diff --git a/feed/feed.11tydata.js b/feed/feed.11tydata.js new file mode 100644 index 0000000..f3e7f32 --- /dev/null +++ b/feed/feed.11tydata.js @@ -0,0 +1,3 @@ +module.exports = { + eleventyExcludeFromCollections: true +} diff --git a/feed/feed.njk b/feed/feed.njk index 161fc93..28e3c32 100755 --- a/feed/feed.njk +++ b/feed/feed.njk @@ -1,7 +1,6 @@ --- # Metadata comes from _data/metadata.json permalink: "{{ metadata.feed.path }}" -eleventyExcludeFromCollections: true --- diff --git a/feed/htaccess.njk b/feed/htaccess.njk deleted file mode 100644 index ac4a3c5..0000000 --- a/feed/htaccess.njk +++ /dev/null @@ -1,6 +0,0 @@ ---- -permalink: feed/.htaccess -eleventyExcludeFromCollections: true ---- -# For Apache, to show `{{ metadata.feed.filename }}` when browsing to directory /feed/ (hide the file!) -DirectoryIndex {{ metadata.feed.filename }} diff --git a/feed/json.njk b/feed/json.njk index 40bba3c..f822b12 100644 --- a/feed/json.njk +++ b/feed/json.njk @@ -1,7 +1,6 @@ --- # Metadata comes from _data/metadata.json permalink: "{{ metadata.jsonfeed.path }}" -eleventyExcludeFromCollections: true --- { "version": "https://jsonfeed.org/version/1.1", diff --git a/package.json b/package.json index 77019a0..79ca8a3 100644 --- a/package.json +++ b/package.json @@ -25,11 +25,11 @@ }, "homepage": "https://github.com/11ty/eleventy-base-blog#readme", "dependencies": { - "@11ty/eleventy": "^2.0.0-canary.12", + "@11ty/eleventy": "^2.0.0-canary.13", "@11ty/eleventy-navigation": "^0.3.3", "@11ty/eleventy-plugin-rss": "^1.2.0", "@11ty/eleventy-plugin-syntaxhighlight": "^4.1.0", - "luxon": "^2.4.0", + "luxon": "^3.0.1", "markdown-it-anchor": "^8.6.4" } } diff --git a/page-list.njk b/page-list.njk deleted file mode 100644 index cb53ec6..0000000 --- a/page-list.njk +++ /dev/null @@ -1,24 +0,0 @@ ---- -pagination: - data: collections.all - size: 20 - alias: entries -layout: layouts/home.njk -permalink: /page-list/{% if pagination.pageNumber > 0 %}{{ pagination.pageNumber }}/{% endif %} ---- - - - - - - - - -{%- for entry in entries %} - - - - -{%- endfor %} - -
URLPage Title
{{ entry.url }}{{ entry.data.title }}
diff --git a/sitemap.xml.njk b/sitemap/sitemap.xml.njk similarity index 100% rename from sitemap.xml.njk rename to sitemap/sitemap.xml.njk