using jekyll collections for a secondary, rss-only feed
this post outlines how i’m generating this feed as a separate, secondary feed
using jekyll collections. this is completely possible using the
current version (as of this post: 0.11.0) of the
jekyll-feed
plugin. this plugin is included in all new jekyll
projects that have been generated with the jekyll new
command.
the main blog feed for this site is at the default location:
https://benjaminwil.info/feed.xml
and the feed you’re reading from now is at:
https://benjaminwil.into/antisocial/feed.xml
collection names
there is one caveat: jekyll-feed
doesn’t provide a way to set a custom name
for your secondary feed. any other feeds you make use basic site metadata:
- your
site.title
orsite.name
variable’s value - a pipe character with some spaces around it (
|
) - and your collection name – with the first letter capitalized
this can look a little bit stupid if you aren’t careful:
Cool Website | My-new-collection
yeah, that’s the feed name that would show up in your friends’ rss readers.
i have a pull request open on the jekyll-feed
repository that fixes
this. but if you want custom names right now, you’ll have to use my fork of the
jekyll-feed
gem.
step one: update the jekyll-feed gem
when you create a new jekyll site using the jekyll new
command, the version of
the jekyll-feed
plugin included is ~> 0.6
. to create a secondary feed, you
need to manually update your Gemfile
to use jekyll-feed
~> 0.11
:
ruby
# Gemfile ...
group :jekyll_plugins do
gem "jekyll-feed", "~> 0.11"
end
and add this git
argument if you’re comfortable using my fork of the plugin
(until my – or another similar – pull request has been merged):
ruby
# Gemfile ...
group :jekyll_plugins do
gem "jekyll-feed", "~> 0.11", git: https://github.com/benjaminwil/jf
end
step two: create a new collection
in your site’s _config.yml
file, you need to add the name and metadata for the
collection you intend to use for the feed. in my case:
yml
# _config.yml ...
collections:
antisocial:
output: true
permalink: /antisocial/:name
output: true
ensures a separate file is generated for each item in the
collection (the permalink page), and the permalink:
setting is probably
familiar to you: use it to set your collection post’s uris.
the jekyll permalinks docs include a list of available collections permalinks
variables. the variable i’m using (:name
) just attaches the
filename to the uri.
your new collection can be created in the directory _collection_name
(unless
you’ve set a custom collections_dir:
in your _config.yml
). in my case:
_antisocial
.
step three: pick a layout
you can either use your standard post
layout or make a new one. if you’re a
jekyll user, you likely know all about layouts: so i won’t go into any more
detail here.
you can either set a layout:
value in the frontmatter for every collection
item, or you can set each collection item’s layout globally from your
_config.yml
:
yml
# _config.yml ...
defaults:
-
scope:
path: "" # an empty string here means all files in the project
type: "antisocial"
values:
layout: "your_preferred_layout"
this is some ugly yaml, but that’s what is has to be according to the front matter defaults docs.
step four: configure the feed
we’re pretty much done now. we just have to configure the secondary feed
information using the provided jekyll-feed
configuration
settings.
again, in your _config.yml
:
yml
# _config.yml ...
feed:
collections:
antisocial:
path: "/antisocial/feed.xml"
where antisocial:
is the name of your collection and the path:
value is a
string with your preferred feed location.
now that you’ve configured the feed, you can start to add new posts to your collection directory.
note that if you’re keeping a blog you still need to use date:
front matter to
ensure your posts get to the feed.