Skip to content

Commit

Permalink
First commit of i18n base blog using Eleventy v2. This uses English-i…
Browse files Browse the repository at this point in the history
…mplied URLs.
  • Loading branch information
zachleat committed Jul 15, 2022
1 parent 7053088 commit 2491464
Show file tree
Hide file tree
Showing 26 changed files with 87 additions and 42 deletions.
7 changes: 7 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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");
Expand Down
1 change: 0 additions & 1 deletion .eleventyignore

This file was deleted.

4 changes: 3 additions & 1 deletion _includes/layouts/base.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="{{ metadata.language }}">
<html lang="{{ lang or metadata.language }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand All @@ -14,6 +14,8 @@
<link rel="stylesheet" href="{{ '/css/prism-diff.css' | url }}">
<link rel="alternate" href="{{ metadata.feed.path | url }}" type="application/atom+xml" title="{{ metadata.title }}">
<link rel="alternate" href="{{ metadata.jsonfeed.path | url }}" type="application/json" title="{{ metadata.title }}">

{# TODO add link rel="alternate" for langs #}
</head>
<body>
<header>
Expand Down
23 changes: 18 additions & 5 deletions _includes/layouts/post.njk
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,27 @@ templateClass: tmpl-post

{{ content | safe }}

<hr>

{% set i18nLinks = page.url | locale_links %}
{% if i18nLinks.length %}
<ul>
<li>
This page is also available in: <!-- don’t forget to localize this text too -->
{%- for link in i18nLinks %}
{%- if not loop.first %},{% endif %}<a href="{{link.url}}" lang="{{link.lang}}" hreflang="{{link.lang}}">{{link.label}}</a>
{%- endfor -%}
</li>
</ul>
{% endif %}

{%- if collections.posts %}
{%- set nextPost = collections.posts | getNextCollectionItem(page) %}
{%- set previousPost = collections.posts | getPreviousCollectionItem(page) %}
{%- set previousPost = collections.posts | getPreviousCollectionItem() %}
{%- set nextPost = collections.posts | getNextCollectionItem() %}
{%- if nextPost or previousPost %}
<hr>
<ul>
{%- if nextPost %}<li>Next: <a href="{{ nextPost.url | url }}">{{ nextPost.data.title }}</a></li>{% endif %}
{%- if previousPost %}<li>Previous: <a href="{{ previousPost.url | url }}">{{ previousPost.data.title }}</a></li>{% endif %}
{%- if previousPost %}<li>Previous: <a href="{{ previousPost.url | locale_url | url }}">{{ previousPost.data.title }}</a></li>{% endif %}
{%- if nextPost %}<li>Next: <a href="{{ nextPost.url | locale_url | url }}">{{ nextPost.data.title }}</a></li>{% endif %}
</ul>
{%- endif %}
{%- endif %}
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion archive.njk → en/blog.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
layout: layouts/home.njk
permalink: /posts/
eleventyNavigation:
key: Archive
order: 2
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions en/en.11tydata.js
Original file line number Diff line number Diff line change
@@ -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`;
}
}
7 changes: 7 additions & 0 deletions index.njk → en/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ eleventyNavigation:
{% include "postslist.njk" %}

<p>More posts can be found in <a href="{{ '/posts/' | url }}">the archive</a>.</p>


<ul>
{%- for entry in collections.all %}
<li><a href="{{ entry.url }}"><code>{{ entry.url }}</code></a></li>
{%- endfor %}
</ul>
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions es/blog/fourthpost.md
Original file line number Diff line number Diff line change
@@ -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.

13 changes: 13 additions & 0 deletions es/blog/thirdpost.md
Original file line number Diff line number Diff line change
@@ -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.

11 changes: 11 additions & 0 deletions es/es.11tydata.js
Original file line number Diff line number Diff line change
@@ -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)}/`;
}
}
}
3 changes: 3 additions & 0 deletions feed/feed.11tydata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
eleventyExcludeFromCollections: true
}
1 change: 0 additions & 1 deletion feed/feed.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
# Metadata comes from _data/metadata.json
permalink: "{{ metadata.feed.path }}"
eleventyExcludeFromCollections: true
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
Expand Down
6 changes: 0 additions & 6 deletions feed/htaccess.njk

This file was deleted.

1 change: 0 additions & 1 deletion feed/json.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
# Metadata comes from _data/metadata.json
permalink: "{{ metadata.jsonfeed.path }}"
eleventyExcludeFromCollections: true
---
{
"version": "https://jsonfeed.org/version/1.1",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
24 changes: 0 additions & 24 deletions page-list.njk

This file was deleted.

File renamed without changes.

0 comments on commit 2491464

Please sign in to comment.