This is a plugin for Metalsmith that adds created and updated attributes to files based on cached information saved in a file.
This module is released via npm, install the latest released version with:
npm install --save metalsmith-updated
If using the CLI for Metalsmith, metalsmith-updated can be used like any other plugin by including it in
var updated = ;__dirname;
metalsmith-updated will only check HTML pages. Normally you will want to use the plugin as soon as your markup has been converted to HTML, but before it is templated, since these variables are useful in templates.
metalsmith-updated adds three attributes to each HTML file: created, and updated.
created: set if this is the first time that metalsmith-updated has seen the file.
updated: set if the file is new or if it's contents have changed.
modified: set if the file has been modified since it was created. This implies that
created != modified.
metalsmith-updated identifies files by filename and changes by hashing
file.contents. Timestamps are set to
metadata.date if it exists (for
new Date() if not.
Note that metalsmith-updated will not override these attributes if they already exist on any file, but will save dutifully to its comparison file. This can be useful for bootstrapping metalsmith-updated for existing blog posts, for example.
metalsmith-updated does not require any options, but the following options are available:
If set a message will be printed if files generate warnings or errors.
metalsmith-updated will ignore files that have "truthy" values in any of these keys.
A list of minimatch patterns to constrain the files that metalsmith-updated
["*.html"] is a potentially-useful option.
Path relative to the metalsmith source directory where metalsmith-updated caches file information. This will be removed from the build directory.