Two item changelog.

1.15 (Mar 1)

✅ Added syntax highlighting support for whenever I post code

I wrote the 1.14 update below, pasted the code in, and realized I was gonna need to add syntax highlighting. At first I downloaded and started using Highlight JS. But I needed to output code blocks (<pre> and <code>) in a certain way in order to use it, and I realized the markdown parsing library I was using just isn’t very good. So I switched to a better library. And it does its own syntax highlighting so I don’t have to add Highlight JS (which is nice because I’m not serving much Javascript for this site and it would have been the biggest script by far).

1.14 (Feb 29)

✅ Improved the way post titles are generated

The titles on the posts I write are optional. Usually when I write a small comment or response I leave the post title blank. When that happens, the server generates a title so that the RSS feed displays correctly and I always have a HTML page title.

At first, the titles that were generated always looked like: Post at 9:00 PM. I wasn’t feeling that that so I updated the title generation in version 1.13 to append the post’s tags, so they look like: Post at 9:00 (nyc, photo).

I still wasn’t satisfied so I changed it again. Most of my title-less posts are responses to a link, and when I post something, the server automatically looks for the title of any links in the post content, looks up the title and image for them, and adds them as attachments to the post. Since I have that info, I changed the title generation logic to this:

  1. If the user entered a post title use it. Done.
  2. If the user did not enter a post title, but there’s at least one link (and therefore an attachment), prepend the first attachment’s title with “Re: " and use that.
  3. If neither of those things happened, fall back to the title generation from version 1.13.

The code looks like this:

 1var itemTitle string
 2
 3if title.Status == pgtype.Present && title.String != "" {
 4    itemTitle = title.String
 5} else if caption.Status == pgtype.Present && caption.String != "" {
 6    itemTitle = fmt.Sprintf("Re: %s", caption.String)
 7} else {
 8    itemTitle = fmt.Sprintf("Post at %s", created.Format("3:04 PM"))
 9
10    if tags.Status == pgtype.Present && len(tags.Elements) > 0 {
11        tagsString := tagsFromTextArray(tags)
12        if tagsString != "" {
13            itemTitle += fmt.Sprintf(" (%s)", tagsFromTextArray(tags))
14        }
15    }
16}