Table of contents

Another migration

The past

My blog has changed many forms during the years. Originally it was a static HTML based website. Then it became a Joomla based dynamic site. At some point there was also a version that lived in livejournal.com, and eventually I ended up in blogger.com when I did not want to maintain my own server.

The content

Most of the time, these blog entries were not long form. They were basically notes to myself about how I can do something, a cool hack or something smart I had seen somewhere. Some of these posts were about books or films I had watched.

Things that in modern times would most likely be posted in a microblogging platform. Back when, we thought that the content we posted there was our own and our friends that might be following us would most likely see it in their timeline.

Before the algorithmic manipulation of feeds.

In any case, these things were mostly of interest to me. Things that I returned to from time to time when I needed to repeat an operation to fix something I had fixed before, and I needed to fix again.

As such, this older content most of the time was just a few lines and potentially links to other websites.

The present

This content has already been migrated a few times from one platform to another. As such, and because this content has changed form many times, it might not be properly formatted for this particular platform.

In any case, I think it makes sense to do another migration, to this new website, so I can properly preserve it for future reference. Looking at my oldest post when I migrated to Blogger, it seems to be from 2014.

It is a shame that I do not have anything surviving from 2002 when I created my first website.

In any case, I have tried to convert and transform these old posts to something somewhat compatible with the new format. All old posts share the same tag called old-blog in case anyone wants to see them altogether.

The migration process

Blogger is a Google service so it has a way to export all of your content alongside any media and comments it may have. It generates a zip file that contains everything. The blog posts are contained in a file called feed.atom.

Despite the name, in my case at least, this file was not parsable by the python atom library I tried to use.

The next attempt was to use BeautifulSoup and this worked like a charm. I created a little script that extracted the posts and transformed them to something that would work with my current platform.

from bs4 import BeautifulSoup
from pathlib import Path
import pprint
from datetime import datetime

file_path = Path('feed.atom')
file_content = file_path.read_text()

soup = BeautifulSoup(file_content, features="xml")
counter=0
entries=soup.find_all('entry')
for item in entries:
    if item.title is None:
        continue
    else:
        dateo=datetime.fromisoformat(item.published.contents[0].replace("Z", "+00:00"))
        dt=dateo.date()
        bar1='---\n'
        layout='layout: post\n'
        title=f"title: {item.title.contents[0]}\n"
        date=f"date: {dt}\n"
        try:
            tags=f"tags: old-blog {item.category['term']}\n"
        except:
            tags=f"tags: old-blog\n"
        bar2='---\n'
        spacer='\n'
        content=item.contents[11].contents[0]
        output=bar1 + layout + title + date + tags + bar2 + spacer + content
        print(output)
        filename=f"{dt}-{item.title.contents[0]}.markdown".replace(" ", "_").replace("/","_").replace(":","_")
        print(filename)
        with open(f"blog-posts/{filename}","w") as f:
            f.write(output)

This seems to be working just fine, and I was able to move more than 100 old blog posts over to the new platform.

Tag alignment

Sometimes it is easy to end up with different spellin in tags which makes everything difficult. Some articles might end up in different tags than others when they should be under the same tag.

To make things simple we will convert all tag names to lower case with:

grep -lz "^tags:" * | xargs gsed -i -r "s/(^tags:)(.+)/\1\L\2/g"