Tuesday, October 18, 2016

Oh Hi There

So, Twitter's had these things called Twitter Cards for a while now.  You've probably already seen them in action.  When you post a link to a website, there will be a box with information about the link as opposed to just a plain link.  That's the Twitter Card, and it's dead simple to implement.

It's all in your page's <meta /> tags.  I'm not going to go in-depth describing how to do it here, because Twitter's got a whole section of their developer site for that.  There's a bit of finagling to get it working on Blogger since you have to edit your template, and if you want to customize them at all you'll end up having to learn Blogger's template language.  Thankfully, it's XML-based, so it's not completely terrible.

Blogger's template language isn't without its shortcomings, though.  The vast majority of the data you might want to work with is only available to specific page widgets.  For instance, on the Twitter Card for my blog's archive pages (click a year or month header in the archive section to get one such page), I wanted the title to just be my blog title, and the description to say something like "Post archive for $MONTH $YEAR".  While there's a way to get the date of the archive, it's only available within the archive widget itself, and not available to the whole page, even when the page is an archive page.  I had to settle for leaving the archive's date in the title and just putting "Post Archive" in the description.

Also, their template language completely barfs all over the place if you have the nerve to try and prepend a string to a data variable.  Appending works beautifully, but prepending causes the whole thing to fail.

Now, in any other language, I'd just go "oh, well, the page title contains the archive's date, I can just test for page type, and if it's an archive page, use string functions to pull the archive's date out of the title and stick it in the description instead!", but we don't get anything nearly as fancy as that here.  I'm basically stuck with what I've got until their template system gets more powerful.

Theoretically I could submit feedback about this, but the trouble with that is, this is Google we're dealing with.  I'm not going to get a response.  In all reality, I'll be completely ignored.  They're not going to implement some random suggestion that one guy would find useful; they'll only implement what they come up with because then it's "cool".

Anyway, when I link my new posts on Twitter, they'll now have Twitter Cards instead of just being plain links.  This change doesn't seem to apply retroactively, so don't go looking through my old tweets for it.

No comments:

Post a Comment

I moderate comments because when Blogger originally implemented a spam filter it wouldn't work without comment moderation enabled. So if your comment doesn't show up right away, that would be why.