Skip to content

Content that fills itself in

Dates

Copy page

Two dates, and knowing which is which is the difference between an index that behaves and one that reshuffles itself every time you fix a typo.

The two

date is the publication date — when the article came out. You set it, and it does not move unless you move it.

lastmod is when the page last changed. It updates on its own every time you publish a change to that page.

Sort by date, not lastmod

An index sorted by lastmod reshuffles whenever you touch anything:

{% assign posts = collections.articles | sort: "date" | reverse %}

Correcting a spelling mistake in a two-year-old article should not move it to the top of the blog. Sorting by date is what stops that.

lastmod has its uses — “updated on” under a heading, or a list of what changed recently — but it is the wrong thing to order a blog by.

Setting the date

It is an ordinary setting on the article, alongside the title and the description — and a page has one too. Left empty, it is the day the page was first published, which is right for almost everything. Set it only to say something different: backdating an article you are importing from somewhere else, or setting a date ahead of today for something written in advance.

A date in the future does not hide the page. It publishes like anything else and simply sorts to the top of a newest-first list.

Showing a date

<time datetime="{{ page.date }}">{{ page.date | date: "%e %B %Y" }}</time>

The datetime attribute wants the full value, which is what page.date is. The visible part is formatted with date, and the site’s own time zone is what it formats in.

A page with no date

A page that has never had one sorts as though it were empty, which puts it at one end of the list. If an index looks oddly ordered, an article with a missing date is the first thing to check.

On this page