2014-03-21

The feed tem­plate in mid­dle­man-blog uses file mod­i­fi­ca­tion times to de­ter­mine when ar­ti­cles were up­dated. If your ar­ti­cles are un­der ver­sion con­trol, how­ever, you can do bet­ter.

Your ver­sion con­trol sys­tem al­ready de­scribes pre­cisely the mod­i­fi­ca­tions that are mean­ing­ful: those that in­volve the ar­ti­cles’ con­tent. Arbitrary file sys­tem ac­tiv­ity such as cloning a repos­i­tory or syn­chro­niz­ing data be­tween com­put­ers is ir­rel­e­vant.

To tap into this more re­li­able data source, I’ve cre­ated a Middleman extension that pro­vides an mtime at­tribute on each ar­ti­cle. Behind the scenes it queries the ver­sion con­trol sys­tem to find the last recorded change to the ar­ti­cle’s con­tent.

With the ex­ten­sion in place, the atom:updated el­e­ment for each ar­ti­cle can be writ­ten as:

xml.updated article.mtime.to_datetime.rfc3339

and for the en­tire feed as:

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

The ex­ten­sion is mod­u­lar with re­spect to ver­sion con­trol sys­tems. I’ve implemented sup­port for Git and a plain file sys­tem fall­back.