Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .config/collections/redirect.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions .config/eleventy.config.collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -14,4 +15,5 @@ module.exports = function (config) {
config.addCollection('gameTags', gameTags);
config.addCollection('apiToc', apiToc);
config.addCollection('articlesToc', articlesToc);
config.addCollection('redirects', redirect);
}
13 changes: 13 additions & 0 deletions _includes/layouts/redirect.layout.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en-US">
<meta charset="utf-8"/>
<title>Redirecting&hellip;</title>
<link rel="canonical" href="{{ redirect.to | url }}"/>
<script>
location = '{{ redirect.to | url }}';
</script>
<meta http-equiv="refresh" content="0; url={{ redirect.to | url }}"/>
<meta name="robots" content="noindex"/>
<h1>Redirecting&hellip;</h1>
<a href="{{ redirect.to | url }}">Click here if you are not redirected.</a>
</html>
8 changes: 8 additions & 0 deletions content/redirects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
pagination:
data: collections.redirects
size: 1
alias: redirect
permalink: "{{ redirect.from }}"
layout: "layouts/redirect.layout.njk"
---