Using scripts to update my personal site.
These last few days I have been adding code in Nikola to give it a more useful Python API. I added scripts then I started a PR that lets you modify posts programmatically.
Why?
Because my site has 20 years of baggage. Which means every bad idea in the my 20 year history of doing my own blog software is lurking in it somewhere.
For example, when Nikola got started, it had (it still has it!) support for what I called "meta files". Basically, you put your post's content in a file, say "mypost.txt" and you added things like the date, the title, tags and so on in "mypost.meta", which was the metafile.
That was good in that it was a way to quickly get it working without worrying about how to extract metadata from source files, and to keep source files compatible with other toolchains, like docutils' or normal markdown.
BUT, then we added ways to have metadata in the files and keep them compatible. But
I still had 1500 metafiles in my site. And getting rid of them would involve some
sed
some python
and some pain, so I never upgraded the posts to the newer format.
Until now.
two_post_files = [p for p in site.timeline if p.is_two_file]
for p in two_post_files:
p.is_two_file = False
print(p.title())
What is that? Well, it filters the site.timeline
and finds all the things
that are in two files using the is_two_file
property, and then makes them
not be two files.
What is the result?
$ git diff --stat 766d8e1c5dd495d4aa7e27bb0b7f6b2c62c6aa63 | tail -1
3739 files changed, 20521 insertions(+), 7381 deletions(-)
Of course my site is under git, I would not dare do this without it.
And hey, no more .meta
files!