diff --git a/.config/collections/redirect.js b/.config/collections/redirect.js new file mode 100644 index 00000000..3754ae3a --- /dev/null +++ b/.config/collections/redirect.js @@ -0,0 +1,32 @@ +'use strict'; + +const redirects = new Set(); + +/** @param {import("@11ty/eleventy/src/TemplateCollection")} api */ +function redirect(api) { + // Add any manual redirects needed in the future here manually + // Example: + // redirects.add({from: "old/path", to: "new/path"}); + + //-------------------------------------------------------------------------- + // Warning: + // + // Do not edit below unless you are aware of what you are doing. + // The following is an automation that creates redirects for all article + // files since the URLs have changed on them once we moved to 11ty. + // + // For example + // '/articles/packaging_games.html' changed to '/articles/packaging_game/' + // + //-------------------------------------------------------------------------- + api.getFilteredByGlob('./content/articles/**/*.md') + .forEach( (article) => { + let path = article.page.url; + let from = path.slice(0, -1) + '.html' + redirects.add({from: from, to: path}); + }); + + return Array.from(redirects); +} + +module.exports = redirect; diff --git a/.config/eleventy.config.collections.js b/.config/eleventy.config.collections.js index 86a96320..1e02468c 100644 --- a/.config/eleventy.config.collections.js +++ b/.config/eleventy.config.collections.js @@ -5,6 +5,7 @@ const blogTags = require('./collections/blogTags'); const gameTags = require('./collections/gameTags'); const apiToc = require('./collections/apiToc'); const articlesToc = require('./collections/articlesToc'); +const redirect = require('./collections/redirect'); /** @param {import("@11ty/eleventy").UserConfig} config */ @@ -14,4 +15,5 @@ module.exports = function (config) { config.addCollection('gameTags', gameTags); config.addCollection('apiToc', apiToc); config.addCollection('articlesToc', articlesToc); + config.addCollection('redirects', redirect); } diff --git a/_includes/layouts/redirect.layout.njk b/_includes/layouts/redirect.layout.njk new file mode 100644 index 00000000..de223e7d --- /dev/null +++ b/_includes/layouts/redirect.layout.njk @@ -0,0 +1,13 @@ + + + + Redirecting… + + + + +

Redirecting…

+ Click here if you are not redirected. + diff --git a/content/redirects.md b/content/redirects.md new file mode 100644 index 00000000..923e3c6c --- /dev/null +++ b/content/redirects.md @@ -0,0 +1,8 @@ +--- +pagination: + data: collections.redirects + size: 1 + alias: redirect +permalink: "{{ redirect.from }}" +layout: "layouts/redirect.layout.njk" +---