code and games
Built with Hugo and Hyde-Y.

A toy project I like to fiddle with is a person URL shortener. Right now I have an old URL shortener on zikes.me to which I added some logic to the routing, such that certain paths would lead to administrative areas while others would be treated as shortened URL keys. This was pretty hack-ish, and I’d like to be able to use /anything as a key without worry. That meant either a separate administrative process, an API, or somehow serving a separate admin area via a subdomain, like admin.zikes.me. The third option sounded ideal, as keeping the admin within the same process should keep the code pretty tight.

Personal Hosted Git Server

In an attempt to continue doing things right, I’ve put my blog in a git repository. I considered putting it on Github, whether public or private, but honestly I’ve been looking for an excuse to set up my own personal Git server. Normally I’d go with a self-hosted all-in-one system like Gitlab or gogs. We use Gitlab at work, and I love the minimal resource usage of gogs, but for now they’re just overkill for what I need.

Everyone loves parsing XML files, right? The inconsistent formatting, undocumented fields and attributes, they’re always a hoot. If you’re especially unlucky, you’ll also come up against invalid Unicode characters that cause the parser to choke, as I did recently:

2017/01/24 11:28:06 error parsing data/201701182200040_58647400_2.xml: XML syntax error on line 96: illegal character code U+001E

Fortunately, Go makes it really easy to clean that part up, thanks to the excellent unicode and strings standard libraries. In my case, I had read in the contents of an xml file into a byte slice called xmlData, using os.ReadFile. I simply put the code below in between the file read and the XML unmarshal, and it’s been smooth sailing ever since:

printOnly := func(r rune) rune {
  if unicode.IsPrint(r) {
    return r
  }
  return -1
}
xmlData = []byte(strings.Map(printOnly, string(xmlData)))

Tying Files to Posts

One of my initial concerns with using a static site generator was managing related content files. Some posts may have related post-specific images, or scripts, and I didn’t want to have to manually organize them in /static subfolders. Ideally, they would live alongside the post’s own .md file.