summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Schlosser <christoph@linux.com>2025-08-24 17:37:43 +0200
committerChristoph Schlosser <christoph@linux.com>2025-08-24 17:42:39 +0200
commit0b3f38b3786c1b738165778d210453e1c2bfe309 (patch)
treef42d9533f1e5eee76b6fe147414dec53bf4eff1f
parent8f2f0d5d1176794bb7df2c42c54b7211e155d331 (diff)
downloadgit2hugo-0b3f38b3786c1b738165778d210453e1c2bfe309.tar.gz
g2h: Add commit page
-rw-r--r--README.md9
-rw-r--r--g2h/cli.py2
-rw-r--r--g2h/commit_page.py14
-rw-r--r--g2h/page_factory.py4
-rw-r--r--templates/commit.md9
-rw-r--r--test_repo/git.tgzbin16230 -> 16230 bytes
-rw-r--r--tests/commit_test.py19
7 files changed, 55 insertions, 2 deletions
diff --git a/README.md b/README.md
index 3796be6..e78a55c 100644
--- a/README.md
+++ b/README.md
@@ -39,11 +39,16 @@ For a full list of options, their defaults and how they're changing the behavior
Table with branch/tag, message summary and last modified date columns.
- [ ] Link commit messages to commit page.
- [ ] Tabbed log page.
-- [ ] Commit page.
+- [x] Commit page.
Collection of metadata at the beginning of the page.
- Consisting of commit hash, commit date, author, (redact email), parent(s) and child(ren).
+ Consisting of commit hash, commit date, author
Followed by the commit message and then a list of changed files.
+ - [ ] Add redacted email to authro.
+ - [ ] Add links to parent(s).
+ - [ ] Add links to child(ren).
- [ ] Show diffstat on commit page.
+ - [ ] Add button to browse tree.
+ - [ ] Add button to download tree tarball.
- [ ] Tree view.
Show the state of the tree at the current commit.
Folders should be traversable by clicking and clicking on a file should open that file's page.
diff --git a/g2h/cli.py b/g2h/cli.py
index 1391ec2..3d7028e 100644
--- a/g2h/cli.py
+++ b/g2h/cli.py
@@ -28,6 +28,8 @@ def main():
factory = PageFactory(args.out_dir, project_name)
factory.new_overview(branches, tags).render()
factory.new_log(commits, branches, tags).render()
+ for commit in commits:
+ factory.new_commit(commit).render()
if __name__ == '__main__':
main()
diff --git a/g2h/commit_page.py b/g2h/commit_page.py
new file mode 100644
index 0000000..325df85
--- /dev/null
+++ b/g2h/commit_page.py
@@ -0,0 +1,14 @@
+import os
+
+from .page import Page
+
+class CommitPage(Page):
+ def __init__(self, out_dir, name, commit):
+ super(CommitPage, self).__init__('commit.md', out_dir, os.path.join(commit.hexsha, 'index.md'), name)
+ self.commit = commit
+
+ def context(self):
+ return {
+ 'commit': self.commit,
+ 'title': self.name + ': ' + self.commit.hexsha
+ }
diff --git a/g2h/page_factory.py b/g2h/page_factory.py
index dae9675..f946e7a 100644
--- a/g2h/page_factory.py
+++ b/g2h/page_factory.py
@@ -1,3 +1,4 @@
+from .commit_page import CommitPage
from .overview_page import OverviewPage
from .log_page import LogPage
@@ -6,6 +7,9 @@ class PageFactory:
self.out_dir = out_dir
self.name = name
+ def new_commit(self, commit):
+ return CommitPage(self.out_dir, self.name, commit)
+
def new_overview(self, branches, tags):
return OverviewPage(self.out_dir, self.name, branches, tags)
diff --git a/templates/commit.md b/templates/commit.md
new file mode 100644
index 0000000..fcf57b7
--- /dev/null
+++ b/templates/commit.md
@@ -0,0 +1,9 @@
+{% include '_head.md' %}
+
+**Commit**: {{ commit.hexsha }}
+**Author**: {{ commit.author }}
+**Date**: {{ commit.committed_datetime.strftime('%Y-%m-%d %H:%M:%S') }}
+
+```
+{{ commit.message }}
+```
diff --git a/test_repo/git.tgz b/test_repo/git.tgz
index 3c96007..5d00f06 100644
--- a/test_repo/git.tgz
+++ b/test_repo/git.tgz
Binary files differ
diff --git a/tests/commit_test.py b/tests/commit_test.py
new file mode 100644
index 0000000..e36f835
--- /dev/null
+++ b/tests/commit_test.py
@@ -0,0 +1,19 @@
+from g2h.commit_page import CommitPage
+from unittest.mock import MagicMock
+
+def test_init():
+ commit = MagicMock()
+ commit.hexsha = '123'
+ page = CommitPage('test/commit', 'commit test', commit)
+ assert(page.name == 'commit test')
+ assert(page.out_file_path == 'test/commit/123/index.md')
+ assert(page.template.name == 'commit.md')
+
+def test_context():
+ commit = MagicMock()
+ commit.hexsha = '123'
+ page = CommitPage('test/commit', 'commit test', commit)
+ context = page.context()
+ assert(context['title'] == 'commit test: 123')
+ assert(context['commit'] == commit)
+