Note

The content of this page is obsolete. The website is now converted using 💎 Quartz, which solves some of the topics discussed here out of the box. The page is kept for future reference.

I have added a \pages-prefix to all URLs on my website. Initially, I thought this was a requirement, but it turns out I was misinterpreting the documentation.

Now the question is how to get rid of that prefix. I’m probably massively overcomplicating the problem because there is nearly no traffic on this website. I still want to spend some time thinking about this problem, because this will probably still be required in the future.

My original idea was to add a canonical reference to the main page from each of the old pages using:

<link rel="canonical" href=<main-url> />

This can be relatively easily done to all pages that are generated through Markdown because there’s the metadata section at the top of the page and automatic replacement of template variables in Pandoc.

The problem is any other type of file because those are using custom code to replace template variables. It’s relatively easy to add another template variable, but the problem is defining the main file it should refer to. There is no metadata section in code files, and adding that would require a custom implementation for each language (each using a different type of comment). This is not necessarily such a big problem, but it feels like an overcomplicated solution to the problem.

Another solution would be to use HTTP Status Codes (HTTP 301 when a page is moved permanently). The question here is how to define which URLs should refer to which other URL.

An idea could be to create a URL ‘blacklist’. This could be easily done in a YAML file or even in code. The problem with the code approach would be that both the website and website-generation code need access to the URL mapping, but they are both implemented in different languages (Python vs JavaScript).

Conclusion

Attempt the YAML-file approach to define the URL mapping and share that same file with the website (e.g., refer from the website generation code to the website code where the file is placed).

  • The website loads this document and uses that as a reference to return HTTP 301s in case it finds a match.
  • The website generation code uses it as a URL ‘blacklist’ that throws an error in case one of those URLs is reused.