Categories as Keywords in Octopress

The version of Octopress that I use for this blog requires you to give both categories as well as keywords for a page / post to have these appear in the meta tags of the generated HTML. I didn’t check what the current Octopress does in this respect, as I don’t feel like upgrading at the moment.

Since I’m lazy, I’ve updated source/_includes/head.html to fall back to using categories as keywords for a page if no keywords are given.

As this may be useful to other Octopress users, this is what I’ve changed: In source/_includes/head.html, change:

1
{% if page.keywords %}<meta name="keywords" content="{{ page.keywords }}">{% endif %}

to:

1
2
3
4
5
6
7
8
{% capture keywords %}{% if page.keywords %}
  {{ page.keywords }}
{% elsif page.categories %}
  {{ page.categories | join: ', ' }}
{% else %}
  {{ site.keywords }}
{% endif %}{% endcapture %}
<meta name="keywords" content="{{ keywords }}">

and Octopress will default to the categories of a post to use as meta keywords.

Comments