Skip to main content

Ralsina.Me — Roberto Alsina's website

Using scripts to update my personal site.

These last few days I have been adding code in Niko­la to give it a more use­ful Python API. I added scripts then I start­ed a PR that lets you mod­i­fy posts pro­gram­mat­i­cal­ly.

Why?

Be­cause my site has 20 years of bag­gage. Which means ev­ery bad idea in the my 20 year his­to­ry of do­ing my own blog soft­ware is lurk­ing in it some­where.

For ex­am­ple, when Niko­la got start­ed, it had (it still has it!) sup­port for what I called "meta files". Ba­si­cal­ly, you put your post's con­tent in a file, say "my­post.tx­t" and you added things like the date, the ti­tle, tags and so on in "my­post.meta", which was the metafile.

That was good in that it was a way to quick­ly get it work­ing with­out wor­ry­ing about how to ex­tract meta­da­ta from source files, and to keep source files com­pat­i­ble with oth­er toolchain­s, like do­cu­til­s' or nor­mal mark­down.

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.

Un­til 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 re­sult?

$ 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!


Contents © 2000-2024 Roberto Alsina