Skip to content

Commit

Permalink
feat: localize 404 page
Browse files Browse the repository at this point in the history
  • Loading branch information
jobara committed Sep 27, 2021
1 parent a7b1093 commit 8f26f6a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/_includes/layouts/base.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!DOCTYPE html>
{% set lang %}{{ lang | default(config.defaultLanguage) }}{% endset %}
<html lang="{{ lang }}" dir="{{ config.languages[lang].dir }}">
<head>
{% include 'partials/head-matter.njk' %}
Expand Down
2 changes: 2 additions & 0 deletions src/_redirects
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/fr/* /fr/404.html 404

/principles /insights
/principles/DiverseParticipationAndPerspectives.html /insights/diverse-participation-and-perspectives/
/principles/AutonomousUser.html /insights/PersonalDiscovery.html
Expand Down
2 changes: 1 addition & 1 deletion src/404.md → src/documents/pages/en-CA/404.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: 404 - Page Not Found
layout: "layouts/404.njk"
permalink: /404.html
permalink: /en/404.html
---

Check the entered URL, or go to the [Inclusive Design Guides homepage](/).
7 changes: 7 additions & 0 deletions src/documents/pages/fr/404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Erreur 404 - page introuvable
layout: "layouts/404.njk"
permalink: /fr/404.html
---

Vérifiez l'adresse URL ou rendez-vous sur la page d'[accueil du guide pour une conception inclusive](/fr/).
16 changes: 14 additions & 2 deletions src/documents/pages/pages.11tydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ module.exports = {

return data.page.fileSlug;
},
/* Build a permalink using the title and language key. */
permalink: data => generatePermalink(data, "pages")
/* Build a permalink using the title and language key, or to the 404 page. */
permalink: data => {
if (data.page.fileSlug !== "404") {
return generatePermalink(data, "pages");
}

let lang = getLang(data.page.filePathStem, "pages");

if (lang !== data.config.defaultLanguage) {
return `/${data.config.languages[lang].slug}/404.html`;
}
return "/404.html";

}
}
};

0 comments on commit 8f26f6a

Please sign in to comment.