moscardino.net

RSS and Sharing Tags in Hexo

Discovering new things is fun.

I’ve grown to love using Hexo for my blog. Writing posts is as easy as creating a new markdown file and writing away. A simple command to build, a little FTP, and a new post is live.

As I’ve been using it, though, some things have been missing. Namely, an RSS feed and sharing meta tags. Recently, I figured out how to do both. I’ve been purposefully not using a pre-built theme for Hexo, preferring to make my own from scratch, and in doing so the blog has missed what might be considered essential features.

RSS

RSS was actually very easy to set up. Hexo provides a plugin to generate feeds.

First, install the plugin:

npm install hexo-generator-feed --save

Then configure in your _config.yml file:

_config.yml
feed:
type: rss2
path: rss.xml
limit: 10
hub:

And that’s it. A feed file will be generated with each hexo generate.

Sharing Meta Tags

Sharing meta tags are usually pretty annoying to put on a site. Facebook has their own set that they want, and so does Twitter. I think Google+ might need some special ones, too, but no one really cares.

Luckily, Hexo makes it super easy. Add this to your layout in your <head>:

<%- open_graph({ twitter_site: "@_moscardino" }) %>

Boom! Meta tags! Check out the docs on this magic. The function covers everything and pulls the correct fields from your content automatically. Awesome.

Things To do

The blog is still missing some things, of course. I don’t think it will ever be fully finished (thus is the life of a developer). I think I’m going to try and tackle pagination next. As I add more posts (this is number 10), it becomes more necessary. I’m sure I’ll write about it when it happens.