2014-03-21

The feed template in middleman-blog uses file modification times to determine when articles were updated. If your articles are under version control, however, you can do better.

Your version control system already describes precisely the modifications that are meaningful: those that involve the articles' content. Arbitrary file system activity such as cloning a repository or synchronizing data between computers is irrelevant.

To tap into this more reliable data source, I've created a Middleman extension that provides an mtime attribute on each article. Behind the scenes it queries the version control system to find the last recorded change to the article's content.

With the extension in place, the atom:updated element for each article can be written as:

xml.updated article.mtime.to_datetime.rfc3339

and for the entire feed as:

xml.updated feed_articles.map(&:mtime).max.to_datetime.rfc3339

The extension is modular with respect to version control systems. I've implemented support for Git and a plain file system fallback.