Sticky posts and datapages

Implementing sticky posts isn’t native to Jekyll, but easy to do. Datapages allows the creation of pages automatically based on data in a database.

Sticky posts

These are posts that stay at the top of lists and pages regardless of publish date. Normally posts are arranged in data decending order.

Identifying a post as sticky is done by adding an optional YAML entry to any post that wants to be sticky:

---
sticky: "local"
---
  • A value of “local” ensures the post is sticky on its taxonomy page eg ‘art’, but behaves like any other post elsewhere eg on the front page.
  • A value of “all” makes the post sticky on the taxonomy page and any other page it appears on.
  • A value of “front” makes the post sticky on the front page only.

And obviously no YAML entry at all is the default non-sticky post arranged by date.

The logic is handled in _layouts/front.html, not particularly elegantly but cleanly enough. The list of posts to be displayed is reordered with the required sticky posts brought to the start of the collection.

A post identified as sticky gets presented with a darker background by adding in a new css class to the div.

Datapages

Similar to Jekyll’s collections, datapages are created automatically based on formatted data read from a CSV file (for instance). The datapages plugin runs a Generator creating content based on that CSV, settings in the _config.yml and layouts that provide a template into which the data is parsed. Each record in the data produces a page.

So _data/art.csv lists my paintings, the plugin creates a page per record using the template at _layouts/datapages/art.html The created pages can be identified because the template contains a YAML header :-

---
datapage: true
---

so they can be filtered from the site.pages collection as wanted.

{% assign d = site.pages | where: "datapage", true %}
{% for p in d %} {{ p.title }} {% endfor %}