<li><p><aclass="github-button"href="https://github.com/dairiki/lektor-git-timestamp"data-icon="octicon-star"data-size="large"data-show-count="true"aria-label="Star lektor-git-timestamp on GitHub"target="_blank">Star</a></p></li>
<p>This Lektor plugin implements a new datetime-like type,
<code>gittimestamp</code>, which gets it's default value from git timestamps.
This can be used to implement auto-updating <code>pub_date</code> and <code>last_mod</code>
fields in Lektor datamodels.</p>
<h2>Description</h2>
<p>The <code>gittimestamp</code> type behaves just like the built-in <code>datetime</code>
type, except that if the field is left blank in <code>contents.lr</code> a
default value will be deduced from git timestamps for the file (or
possibly the file’s filesystem mtime.)</p>
<p>If an explicit value for the field is not found, the git log for the
source file (typically <code>contents.lr</code>) is searched using <code>git log --follow --remove-empty -- <source_filename></code>, and the author
timestamp of all matching commits are considered. Additionally, if
the source file is dirty with respect to git’s HEAD, or if the file is
not checked into the git tree, the file’s mtime is prepended to that
list of timestamps. That list of timestamps is filtered based on the
<code>ignore_commits</code> and <code>skip_first_commit</code> options (see below); then,
finally, a timestamp is selected from those that remain based on the
setting of the <code>strategy</code> option.</p>
<h3>Options</h3>
<p>The <code>gittimestamp</code> type supports the following options.</p>
<h4><code>ignore_commits</code></h4>
<p>This can be set to a string, which is interpreted as a regular
expression. Any git commits whose commit message matches this pattern
are ignored when computing a default timestamp value for the field.
(The matching is performed using <code>re.search</code>.)</p>
<h4><code>skip_first_commit</code></h4>
<p>If this boolean option is set, the first commit in the git log for the
source file will be ignored. This is useful for implementing a
<code>last_mod</code> field which has a defined value only if the source file has
actually been modified since the initial commit.</p>
<h4><code>strategy</code></h4>
<p>This option determines which timestamp is selected from the git log
(and/or the file mtime). This can be set to one of four values:</p>
<ul>
<li>
<p><code>last</code>: If the source file is dirty (with respect to the git HEAD
tree), the mtime of the file is used. Otherwise, the timestamp of
the last (nominally the most recent) non-ignored git commit is
used. This is the default strategy.</p>
</li>
<li>
<p><code>first</code>: The timestamp of the first (nominally the earliest) commit
is used.</p>
</li>
<li>
<p><code>latest</code>: The latest timestamp is used. Normally this produces the same
result at <code>last</code>, however due to rebasing, cherry-picking, etc. the git timestamps
may not be monotonically increasing, in which case this option causes the
greatest (most recent) timestamp remaining after any filtering to be selected.</p>
</li>
<li>
<p><code>earliest</code>: The earliest timestamp is used. Normally this produces the same
result at <code>first</code>, but if the timestamps in the git log are not monotonic,
this will select the minimum of all the timestamps remaining after any filtering.</p>
</li>
</ul>
<h2>Examples</h2>
<p>Here is a simple example excerpt from a datamodel file:</p>
Please enable JavaScript to view the <ahref="https://disqus.com/?ref_noscript"
rel="nofollow">comments powered by Disqus.</a>
</noscript>
</div>
</div>
</div>
</div>
</div>
</div>
<divclass="bottomsummary">
<divclass="container">
</div>
</div>
<footer>
<divclass="container">
<divclass="row">
<divclass="col-sm-4 icon-bar">
<ahref="https://github.com/lektor/lektor/"title="Lektor on GitHub"
><iclass="fa fa-github"></i></a>
<ahref="https://github.com/lektor/lektor/issues/"title="Report Issues for Lektor"
><iclass="fa fa-bug"></i></a>
<ahref="https://twitter.com/getlektor"title="Find Lektor on Twitter"
><iclass="fa fa-twitter"></i></a>
<ahref="https://gitter.im/lektor/lektor"title="Chat on Gitter"
><iclass="fa fa-comment"></i></a>
<ahref="https://github.com/lektor/lektor-website/tree/master/content/plugins/lektor-git-timestamp/contents.lr"title="View source for this page"><iclass="fa fa-code"></i></a>
</div>
<divclass="col-sm-8">
<ahref="../../license/">License & Copyright</a> •
<ahref="../../contact/">Contact</a> •
Made with <iclass="fa fa-fw fa-heart"title="Heart"><spanhidden>Heart</span></i> in Carinthia