diff options
| author | Christoph Schlosser <christoph@linux.com> | 2025-09-18 22:38:36 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christoph@linux.com> | 2025-09-18 22:38:36 +0200 |
| commit | 2a592ecd951f758a62b1c4907e5da212cf1ba264 (patch) | |
| tree | fe83de1e1d92f927589a07c0a02005e99d4649f2 | |
| parent | 74cd345f76dd01034c804f75e7f16b42e9c0643c (diff) | |
| download | git2hugo-2a592ecd951f758a62b1c4907e5da212cf1ba264.tar.gz | |
g2h: Set `date` frontmatter in overview page to HEAD commit
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | g2h/cli.py | 2 | ||||
| -rw-r--r-- | g2h/git.py | 3 | ||||
| -rw-r--r-- | g2h/overview_page.py | 4 | ||||
| -rw-r--r-- | g2h/page_factory.py | 4 | ||||
| -rw-r--r-- | templates/_head.md | 1 | ||||
| -rw-r--r-- | templates/commit.md | 1 | ||||
| -rw-r--r-- | templates/file.md | 1 | ||||
| -rw-r--r-- | templates/log.md | 1 | ||||
| -rw-r--r-- | templates/overview.md | 2 | ||||
| -rw-r--r-- | templates/tree.md | 1 | ||||
| -rw-r--r-- | tests/overview_page_test.py | 7 |
12 files changed, 22 insertions, 7 deletions
@@ -35,7 +35,7 @@ For a full list of options, their defaults and how they're changing the behavior Each with name, most recent message summary and last modified date. - [x] Link branch and tag name to tree view. - [x] Link commit messages to commit page. - - [ ] Set `date` frontmatter to latest commit date from repo. + - [x] Set `date` frontmatter to latest commit date from repo. - [x] Log page. Table with branch/tag, message summary and last modified date columns. - [x] Link commit messages to commit page. @@ -27,7 +27,7 @@ def main(): tags = sorted(git.get_tags(), key=lambda t: t.commit.committed_date, reverse=True) factory = PageFactory(args.out_dir, project_name, args.content_subdir) - factory.new_overview(branches, tags).render() + factory.new_overview(branches, tags, git.get_head()).render() factory.new_log(commits, branches, tags).render() for commit in commits: factory.new_commit(commit).render() @@ -13,6 +13,9 @@ class Git: def get_commits(self): return list(self.repo.iter_commits()) + def get_head(self): + return self.repo.head.commit + def get_repo(self): return self.repo diff --git a/g2h/overview_page.py b/g2h/overview_page.py index 76de8cc..0363494 100644 --- a/g2h/overview_page.py +++ b/g2h/overview_page.py @@ -1,15 +1,17 @@ from .page import Page class OverviewPage(Page): - def __init__(self, out_dir, name, branches, tags, content_subdir): + def __init__(self, out_dir, name, branches, tags, content_subdir, latest_commit): super(OverviewPage, self).__init__('overview.md', out_dir, '_index.md', name, content_subdir) self.branches = branches self.tags = tags + self.latest_commit = latest_commit def context(self): return { 'branches': self.branches, 'content_subdir': self.content_subdir, + 'latest_commit_date': self.latest_commit.committed_datetime, 'tags': self.tags, 'title': self.name } diff --git a/g2h/page_factory.py b/g2h/page_factory.py index da9c5d5..82e2b0f 100644 --- a/g2h/page_factory.py +++ b/g2h/page_factory.py @@ -20,8 +20,8 @@ class PageFactory: dir = os.path.dirname(path) return FilePage(self.out_dir, self.name, commit, filename, dir, self.content_subdir) - def new_overview(self, branches, tags): - return OverviewPage(self.out_dir, self.name, branches, tags, self.content_subdir) + def new_overview(self, branches, tags, head): + return OverviewPage(self.out_dir, self.name, branches, tags, self.content_subdir, head) def new_log(self, commits, branches, tags): return LogPage(self.out_dir, self.name, commits, branches, tags, self.content_subdir) diff --git a/templates/_head.md b/templates/_head.md index 90c29a2..9b8fdea 100644 --- a/templates/_head.md +++ b/templates/_head.md @@ -1,4 +1,3 @@ ---- title: "{{ title }}" layout: git --- diff --git a/templates/commit.md b/templates/commit.md index 8648760..d97505a 100644 --- a/templates/commit.md +++ b/templates/commit.md @@ -1,3 +1,4 @@ +--- {% include '_head.md' %} **Commit**: {{ commit.hexsha }} diff --git a/templates/file.md b/templates/file.md index 28f458a..a78d9bf 100644 --- a/templates/file.md +++ b/templates/file.md @@ -1,3 +1,4 @@ +--- {% include '_head.md' %} {% include '_breadcrumbs.md' %} diff --git a/templates/log.md b/templates/log.md index 1949cf2..afe6874 100644 --- a/templates/log.md +++ b/templates/log.md @@ -1,3 +1,4 @@ +--- {% include '_head.md' %} {% if commits %} diff --git a/templates/overview.md b/templates/overview.md index 080524b..135e107 100644 --- a/templates/overview.md +++ b/templates/overview.md @@ -1,3 +1,5 @@ +--- +date: {{ latest_commit_date }} {% include '_head.md' %} {% if branches %} diff --git a/templates/tree.md b/templates/tree.md index 8a30cee..8786021 100644 --- a/templates/tree.md +++ b/templates/tree.md @@ -1,3 +1,4 @@ +--- {% include '_head.md' %} {% if entries %} diff --git a/tests/overview_page_test.py b/tests/overview_page_test.py index 06eea97..1d94acf 100644 --- a/tests/overview_page_test.py +++ b/tests/overview_page_test.py @@ -1,9 +1,14 @@ +from unittest.mock import Mock + from g2h.overview_page import OverviewPage def test_init(): - page = OverviewPage('test/overview', 'overview test', 'test branch', 'test tag', 'overview/sub/dir') + commit = Mock() + commit.committed_datetime = '2025-04-01T12:34:56+00:00' + page = OverviewPage('test/overview', 'overview test', 'test branch', 'test tag', 'overview/sub/dir', commit) context = page.context() assert(context['title'] == 'overview test') assert(context['branches'] == 'test branch') assert(context['tags'] == 'test tag') assert(context['content_subdir'] == 'overview/sub/dir') + assert(context['latest_commit_date'] == '2025-04-01T12:34:56+00:00') |