Removing all the page aliases from my personal blog
Backwards compatibility through aliases
In my personal blog I had a lot of posts with aliases. The reason is that I have a taste of tinkering with the configuration of my sites, which is a great advantage of having a static website? I guess?
Anyway, my personal blog would have pages with many aliases set.
The last configuration —and the one that I like the most— produces the permalinks with the following format: /YYYY/MM/my-post/
.
A series of previous configs made the permalinks to have many different structures,
so that a given post would have the following keys in the frontmatter:
|
|
That situation started to bothering me because I didn’t feel like maintaining so many redirects for historical reasons. When I first used the strategy of putting aliases in old posts was to make sure that whatever new configuration I was trying would be “backwards compatible” and to avoid throwing too many 404 errors.
However, in the last few days I had second thoughts about it and decided to put an end to the aliasing thing.
Looking for the non-compliant files
To change this situation I first needed to know which files I had to change. To achieve that, I wrote the following helper script:
|
|
I’m using the python-frontmatter library, which freed me from parsing the frontmatter from scratch. I put the script in the root directory of my personal blog and executed it, which gave a list of 97 markdown files (!) that I needed to modify. The output wasn’t too fancy, but it got the work done. Although I could have included logic to directly change the frontmatter in the files, I did modify them all one by one because I wanted to give it a double check.
A different strategy would have been made Hugo ignore the aliases
key, but somehow that felt like cheating ¯\_(ツ)_/¯.