summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Schlosser <christoph@linux.com>2025-08-24 18:19:13 +0200
committerChristoph Schlosser <christoph@linux.com>2025-08-24 18:19:13 +0200
commit54f78e712baafa9ab6072508e004b2b6bf6430f8 (patch)
tree93d54a8efc60a709d6e370add61b3f1962b4e6f9
parentd8d67f6ba38388aecbf66d791432d5cd3aa8db6e (diff)
downloadgit2hugo-54f78e712baafa9ab6072508e004b2b6bf6430f8.tar.gz
g2h: Link to commit pages from commit log
-rw-r--r--README.md6
-rw-r--r--g2h/log_page.py2
-rw-r--r--templates/log.md2
-rw-r--r--test_repo/git.tgzbin16230 -> 16230 bytes
-rw-r--r--tests/log_test.py31
5 files changed, 21 insertions, 20 deletions
diff --git a/README.md b/README.md
index e78a55c..b2540bb 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ Something like [cgit](https://git.zx2c4.com/cgit/) for static websites, like [st
Let's assume your git project is in `~/development/project` and the sources for your static site are in `~/web/page`.
Then you would run this command:
```bash
-g2h --repo ~/development/project --out ~/web/page --title "My awesome project" --static-subdir static/project --content-subdir content/git/project
+g2h --repo ~/development/project --out ~/web/page --title "My awesome project" --static-subdir project --content-subdir git/project
```
The markdown files for Hugo will be placed in `~/web/page/content/git/project` and static files, like tarballs for each commit and individual file hashes, into `~/web/page/static/project`.
For a full list of options, their defaults and how they're changing the behavior of the program run `g2h --help`.
@@ -35,9 +35,9 @@ 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.
- [ ] Link branch and tag name to tree view.
- [ ] Link commit messages to commit page.
-- [x] Commit log page.
+- [x] Log page.
Table with branch/tag, message summary and last modified date columns.
- - [ ] Link commit messages to commit page.
+ - [x] Link commit messages to commit page.
- [ ] Tabbed log page.
- [x] Commit page.
Collection of metadata at the beginning of the page.
diff --git a/g2h/log_page.py b/g2h/log_page.py
index 9a3d64f..4b8ee10 100644
--- a/g2h/log_page.py
+++ b/g2h/log_page.py
@@ -25,6 +25,7 @@ class LogPage(Page):
refs = ref_names_for_commit(self.branches, commit.hexsha) + ref_names_for_commit(self.tags, commit.hexsha)
commit_context = {
'committed_datetime': commit.committed_datetime,
+ 'hexsha': commit.hexsha,
'refs': refs,
'summary': commit.summary
}
@@ -38,6 +39,7 @@ class LogPage(Page):
return {
'commits': commits_context,
+ 'content_subdir': self.content_subdir,
'title': self.name + ': Log'
}
diff --git a/templates/log.md b/templates/log.md
index 70f719f..1949cf2 100644
--- a/templates/log.md
+++ b/templates/log.md
@@ -4,7 +4,7 @@
| Message | Branches/Tags | Date |
|---------|---------------|------|
{%- for commit in commits %}
-| {{ commit.summary }} | {% if commit.refs %}{{ commit.refs | join(', ') }}{% endif %} | {{ commit.committed_datetime.strftime('%Y-%m-%d %H:%M:%S') }} |{% endfor %}
+| [{{ commit.summary }}](/{{ content_subdir}}/{{ commit.hexsha }}/) | {% if commit.refs %}{{ commit.refs | join(', ') }}{% endif %} | {{ commit.committed_datetime.strftime('%Y-%m-%d %H:%M:%S') }} |{% endfor %}
{% else %}
No commits found.
{% endif %}
diff --git a/test_repo/git.tgz b/test_repo/git.tgz
index 5d00f06..79a44d5 100644
--- a/test_repo/git.tgz
+++ b/test_repo/git.tgz
Binary files differ
diff --git a/tests/log_test.py b/tests/log_test.py
index c0619de..041544e 100644
--- a/tests/log_test.py
+++ b/tests/log_test.py
@@ -21,7 +21,7 @@ def test_context_no_branches_and_tags():
page = LogPage('test/log', 'log test', [commit], None, None, '')
context = page.context()
assert(context['title'] == 'log test: Log')
- assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
+ assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}])
def test_context_matching_branch_no_tags():
commit = MagicMock()
@@ -34,7 +34,7 @@ def test_context_matching_branch_no_tags():
page = LogPage('test/log', 'log test', [commit], [branch], None, '')
context = page.context()
assert(context['title'] == 'log test: Log')
- assert(context['commits'] == [{'committed_datetime': 0, 'refs': ['mock branch'], 'summary': 'mock commit'}])
+ assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': ['mock branch'], 'summary': 'mock commit'}])
def test_context_unmatching_branch_no_tags():
commit = MagicMock()
@@ -47,7 +47,7 @@ def test_context_unmatching_branch_no_tags():
page = LogPage('test/log', 'log test', [commit], [branch], None, '')
context = page.context()
assert(context['title'] == 'log test: Log')
- assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
+ assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}])
def test_context_no_branch_matching_tag():
commit = MagicMock()
@@ -59,8 +59,7 @@ def test_context_no_branch_matching_tag():
tag.name = 'mock tag'
page = LogPage('test/log', 'log test', [commit], None, [tag], '')
context = page.context()
- assert(context['title'] == 'log test: Log')
- assert(context['commits'] == [{'committed_datetime': 0, 'refs': ['mock tag'], 'summary': 'mock commit'}])
+ assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': ['mock tag'], 'summary': 'mock commit'}])
def test_context_no_branch_no_matching_tag():
commit = MagicMock()
@@ -73,7 +72,7 @@ def test_context_no_branch_no_matching_tag():
page = LogPage('test/log', 'log test', [commit], None, [tag], '')
context = page.context()
assert(context['title'] == 'log test: Log')
- assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
+ assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}])
def test_context_no_matching_branch_no_matching_tag():
commit = MagicMock()
@@ -89,7 +88,7 @@ def test_context_no_matching_branch_no_matching_tag():
page = LogPage('test/log', 'log test', [commit], [branch], [tag], '')
context = page.context()
assert(context['title'] == 'log test: Log')
- assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
+ assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}])
def test_context_matching_branch_matching_tag():
commit = MagicMock()
@@ -105,7 +104,7 @@ def test_context_matching_branch_matching_tag():
page = LogPage('test/log', 'log test', [commit], [branch], [tag], '')
context = page.context()
assert(context['title'] == 'log test: Log')
- assert(context['commits'] == [{'committed_datetime': 0, 'refs': ['mock branch', 'mock tag'], 'summary': 'mock commit'}])
+ assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': ['mock branch', 'mock tag'], 'summary': 'mock commit'}])
def test_multiple_commits():
commit1 = MagicMock()
@@ -120,8 +119,8 @@ def test_multiple_commits():
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [
- {'committed_datetime': 0, 'refs': [], 'summary': 'mock commit 1'},
- {'committed_datetime': 1, 'refs': [], 'summary': 'mock commit 2'}
+ {'committed_datetime': 0, 'hexsha': 1, 'refs': [], 'summary': 'mock commit 1'},
+ {'committed_datetime': 1, 'hexsha': 2, 'refs': [], 'summary': 'mock commit 2'}
])
def test_multiple_commits_branch():
@@ -140,8 +139,8 @@ def test_multiple_commits_branch():
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [
- {'committed_datetime': 0, 'refs': ['mock branch'], 'summary': 'mock commit 1'},
- {'committed_datetime': 1, 'refs': [], 'summary': 'mock commit 2'}
+ {'committed_datetime': 0, 'hexsha': 1, 'refs': ['mock branch'], 'summary': 'mock commit 1'},
+ {'committed_datetime': 1, 'hexsha': 2, 'refs': [], 'summary': 'mock commit 2'}
])
def test_multiple_commits_tag():
@@ -160,8 +159,8 @@ def test_multiple_commits_tag():
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [
- {'committed_datetime': 0, 'refs': ['mock tag'], 'summary': 'mock commit 1'},
- {'committed_datetime': 1, 'refs': [], 'summary': 'mock commit 2'}
+ {'committed_datetime': 0, 'hexsha': 1, 'refs': ['mock tag'], 'summary': 'mock commit 1'},
+ {'committed_datetime': 1, 'hexsha': 2, 'refs': [], 'summary': 'mock commit 2'}
])
def test_multiple_commits_branch_and_tag():
@@ -183,7 +182,7 @@ def test_multiple_commits_branch_and_tag():
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [
- {'committed_datetime': 0, 'refs': ['mock branch'], 'summary': 'mock commit 1'},
- {'committed_datetime': 1, 'refs': ['mock tag'], 'summary': 'mock commit 2'}
+ {'committed_datetime': 0, 'hexsha': 1, 'refs': ['mock branch'], 'summary': 'mock commit 1'},
+ {'committed_datetime': 1, 'hexsha': 2, 'refs': ['mock tag'], 'summary': 'mock commit 2'}
])