LoginSignup
5
5

More than 5 years have passed since last update.

Hugoで記事の最終更新日時をGit履歴から自動取得する方法

Last updated at Posted at 2017-06-10

Hugoのバージョン0.18より、Gitの履歴情報から記事の最終更新日時(lastmod)を参照できるようになった。

これまでのHugoにおける最終更新日時の扱い

バージョン0.18よりも前のHugoでは、記事のfrontmatterでlastmodを明示しない限り、記事の更新日時を使えず、かなり使いにくい機能だった。

0.18以降での最終更新日時の扱い

enableGitInfoというオプションが追加され、これがtrueのときにはGitの履歴情報からMarkdownの最終更新日時を自動で取得し、lastmodとして割り当てる機能が追加された。

Add a GitInfo object to Page if enableGitInfo is set. It then also sets Lastmod for the given Page to the author date provided by Git.
https://gohugo.io/release-notes#0-18-0-december-19th-2016

有効化の方法

config.tomlへ1行追加してビルドしなおすだけでOK。

config.toml
enableGitInfo = true

公式ドキュメント

GitInfoの公式ドキュメントはこちら

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5