<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
<p>The following global configuration options are supported.
These values are specified by way of the plugins' <ahref="https://www.getlektor.com/docs/plugins/howto/#configure-plugins"rel="nofollow">configuration file</a>:
<code>configs/git-timestamp.ini</code> under the project site directory.</p>
<p>By default, the <ahref="https://git-scm.com/docs/git-log#Documentation/git-log.txt---follow"rel="nofollow"><code>--follow</code></a> option is passed to <code>git log</code> when
computing timestamps. This behavior may be adjusted on a global basis by way of the plugins' <ahref="https://www.getlektor.com/docs/plugins/howto/#configure-plugins"rel="nofollow">configuration file</a> (<code>configs/git-timestamp.ini</code> under the project site directory) via the following settings:</p>
<h4><code>follow_renames</code></h4>
<p>This is a boolean setting that specifies whether the
<ahref="https://git-scm.com/docs/git-log#Documentation/git-log.txt---follow"rel="nofollow"><code>--follow</code></a> option should be passed to <code>git log</code> when
querying git for timestamps. This options causes <code>git</code> to attempt to
follow file renames.</p>
<p>Currently, the <code>follow_renames</code> is not supported when <ahref="https://www.getlektor.com/docs/content/alts/"rel="nofollow">Lektor
Alternatives</a> are enabled.</p>
<p>If unspecified, <code>follow_renames</code> defaults to <em>false</em>.</p>
<blockquote>
<p><strong>Changed</strong> in version 1.0.0b3: The default value for
<code>follow_renames</code> was changed from <em>true</em> to <em>false</em>.</p>
</blockquote>
<blockquote>
<p><strong>Note</strong> Since we currently run <code>git log</code> on a per-record basis, when <code>--follow</code>
is specified, <em>copied</em> files may be detected as “renamed”. This may not be ideal.</p>
</blockquote>
<h4><code>follow_rename_threshold</code></h4>
<p>Set the <em>similarity index threshold</em> (passed to <code>git log</code> via its
<ahref="https://git-scm.com/docs/git-log#Documentation/git-log.txt--Mltngt"rel="nofollow"><code>-M</code> option</a>) used when detecting renames. This should be
specified as a (floating point) number between 0 and 100,
inclusive. Setting <code>follow_rename_threshold = 100</code> will limit
detection to exact renames only. The default value is 50.</p>
<li>The default value for the <code>follow_renames</code> global config setting has
changed from <em>true</em> to <em>false</em>.</li>
</ul>
<h4>Bugs Fixed</h4>
<ul>
<li>Fix to work when <ahref="https://www.getlektor.com/docs/content/alts/"rel="nofollow">alternatives</a> are enabled. Note that in this case
the <code>follow_renames</code> global option is not supported.</li>
</ul>
<h4>Testing</h4>
<ul>
<li>Test under python 3.12.</li>
</ul>
<h4>Code Style</h4>
<ul>
<li>Style: Use <ahref="https://docs.astral.sh/ruff/"rel="nofollow">ruff</a> for style linting and formatting. This replaces
our usage of <code>black</code>, <code>reorder-python-imports</code>, and <code>flake8</code>.</li>
</ul>
<h3>Release 1.0.0b2 (2023-06-15)</h3>
<ul>
<li>Added type annotations.</li>
<li>Convert packaging to PDM.</li>
</ul>
<h4>Code Style</h4>
<ul>
<li>Style: Run <ahref="https://github.com/psf/black"rel="nofollow">black</a> and <ahref="https://github.com/asottile/reorder-python-imports"rel="nofollow">reorder-python-imports</a> on code. Configure
<ahref="https://pre-commit.com/"rel="nofollow">pre-commit</a> to keep all up-to-date.</li>
</ul>
<h4>Tests</h4>
<ul>
<li>Disuse the deprecated module <code>pkg_resources</code>.</li>
</ul>
<h4>Buglets</h4>
<ul>
<li>Do not strip trailing whitespace from <code>git log</code> output. (This was
erroneously removing trailing newlines from the final commit
message.)</li>
</ul>
<h3>Release 1.0.0b1 (2023-04-11)</h3>
<ul>
<li>Drop support for python 2.7 and 3.6. (<ahref="https://github.com/dairiki/lektor-git-timestamp/pull/2"rel="nofollow">#2</a>)</li>
</ul>
<h4>Testing</h4>
<ul>
<li>
<p>Test under python 3.10 and 3.11. (<ahref="https://github.com/dairiki/lektor-git-timestamp/pull/2"rel="nofollow">#2</a>)</p>
</li>
<li>
<p>Test that <code>lektor.db.Record.get_sort_key</code> works with
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