diff options
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | g2h/cli.py | 5 | ||||
| -rw-r--r-- | g2h/commit_page.py | 3 | ||||
| -rw-r--r-- | g2h/file_page.py | 1 | ||||
| -rw-r--r-- | g2h/log_page.py | 6 | ||||
| -rw-r--r-- | g2h/overview_page.py | 3 | ||||
| -rw-r--r-- | g2h/page_factory.py | 4 | ||||
| -rw-r--r-- | g2h/tree_page.py | 1 | ||||
| -rw-r--r-- | templates/_nav.md | 4 | ||||
| -rw-r--r-- | templates/commit.md | 2 | ||||
| -rw-r--r-- | templates/file.md | 2 | ||||
| -rw-r--r-- | templates/log.md | 2 | ||||
| -rw-r--r-- | templates/overview.md | 2 | ||||
| -rw-r--r-- | templates/tree.md | 2 | ||||
| -rw-r--r-- | tests/commit_page_test.py | 1 | ||||
| -rw-r--r-- | tests/file_page_test.py | 1 | ||||
| -rw-r--r-- | tests/log_page_test.py | 27 | ||||
| -rw-r--r-- | tests/overview_page_test.py | 2 | ||||
| -rw-r--r-- | tests/tree_page_test.py | 1 |
19 files changed, 49 insertions, 22 deletions
@@ -60,7 +60,7 @@ For a full list of options, their defaults and how they're changing the behavior - [x] Don't treat pictures as binary files. - [x] Breadcrumbs for navigating. - [ ] Add button to download raw file. -- [ ] Nav bar for navigating the pages mentioned above. +- [x] Nav bar for navigating the pages mentioned above. - [ ] Link to special readme, if a readme can be found, rendering markdown. - [ ] Wrapper script that takes care of `venv` setup. - [ ] Limit to certain branch(es). @@ -22,13 +22,14 @@ def main(): branches = sorted(git.get_branches(), key=lambda b: b.commit.committed_date, reverse=True) commits = git.get_commits() + head = git.get_head() # TODO: Fix this for repo_path=(.|~) project_name = args.name if args.name is not None else os.path.basename(args.repo_path) 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, git.get_head()).render() - factory.new_log(commits, branches, tags).render() + factory.new_overview(branches, tags, head).render() + factory.new_log(commits, branches, tags, head).render() for commit in commits: factory.new_commit(commit).render() tree = factory.new_tree(commit, '', git.get_repo()) diff --git a/g2h/commit_page.py b/g2h/commit_page.py index 03d74ab..84374e6 100644 --- a/g2h/commit_page.py +++ b/g2h/commit_page.py @@ -31,5 +31,6 @@ class CommitPage(Page): 'commit': self.commit, 'title': self.name + ': ' + self.commit.hexsha, 'redacted_email': redact_email(self.commit.author.email), - 'content_subdir': self.content_subdir + 'content_subdir': self.content_subdir, + 'this_commit': self.commit } diff --git a/g2h/file_page.py b/g2h/file_page.py index 67ddf6d..a558254 100644 --- a/g2h/file_page.py +++ b/g2h/file_page.py @@ -42,5 +42,6 @@ class FilePage(Page): 'content_subdir': self.content_subdir, 'file_extension': os.path.splitext(self.file_name)[1].lstrip('.'), 'title': self.name + ': ' + self.file_name, + 'this_commit': self.commit, 'type': file_type } diff --git a/g2h/log_page.py b/g2h/log_page.py index 4b8ee10..b8df839 100644 --- a/g2h/log_page.py +++ b/g2h/log_page.py @@ -13,11 +13,12 @@ def ref_names_for_commit(refs, commit_sha): return ref_names class LogPage(Page): - def __init__(self, out_dir, name, commits, branches, tags, content_subdir): + def __init__(self, out_dir, name, commits, branches, tags, content_subdir, latest_commit): super(LogPage, self).__init__('log.md', out_dir, 'l.md', name, content_subdir) self.commits = commits self.branches = branches self.tags = tags + self.latest_commit = latest_commit def _commits_with_refs(self): commits_context = [] @@ -40,6 +41,7 @@ class LogPage(Page): return { 'commits': commits_context, 'content_subdir': self.content_subdir, - 'title': self.name + ': Log' + 'title': self.name + ': Log', + 'this_commit': self.latest_commit } diff --git a/g2h/overview_page.py b/g2h/overview_page.py index 0363494..145a8d7 100644 --- a/g2h/overview_page.py +++ b/g2h/overview_page.py @@ -13,6 +13,7 @@ class OverviewPage(Page): 'content_subdir': self.content_subdir, 'latest_commit_date': self.latest_commit.committed_datetime, 'tags': self.tags, - 'title': self.name + 'title': self.name, + 'this_commit': self.latest_commit } diff --git a/g2h/page_factory.py b/g2h/page_factory.py index 82e2b0f..4a46f14 100644 --- a/g2h/page_factory.py +++ b/g2h/page_factory.py @@ -23,8 +23,8 @@ class PageFactory: 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) + def new_log(self, commits, branches, tags, head): + return LogPage(self.out_dir, self.name, commits, branches, tags, self.content_subdir, head) def new_tree(self, commit, tree_segment, repo): return TreePage(self.out_dir, self.name, commit, tree_segment, repo, self.content_subdir) diff --git a/g2h/tree_page.py b/g2h/tree_page.py index c36212c..df65a33 100644 --- a/g2h/tree_page.py +++ b/g2h/tree_page.py @@ -46,6 +46,7 @@ class TreePage(Page): 'entries': self._get_entries(), # TODO: Make this fit the rest of the system. 'subdir': '/'.join([self.content_subdir, tree_join(self.commit, self.tree.path)]), + 'this_commit': self.commit, 'title': self.name + ': Tree' } diff --git a/templates/_nav.md b/templates/_nav.md new file mode 100644 index 0000000..873c204 --- /dev/null +++ b/templates/_nav.md @@ -0,0 +1,4 @@ +[Overview](/{{ content_subdir }}) +| [Log](/{{ content_subdir }}/l) +| [Tree](/{{ content_subdir }}/{{ this_commit }}/t) +| [Commit](/{{ content_subdir }}/{{ this_commit.hexsha }}/) diff --git a/templates/commit.md b/templates/commit.md index d97505a..3eb2437 100644 --- a/templates/commit.md +++ b/templates/commit.md @@ -1,6 +1,8 @@ --- {% include '_head.md' %} +{% include '_nav.md' %} + **Commit**: {{ commit.hexsha }} **Author**: {{ commit.author }} <{{ redacted_email }}> **Date**: {{ commit.committed_datetime.strftime('%Y-%m-%d %H:%M:%S') }} diff --git a/templates/file.md b/templates/file.md index a78d9bf..e82f1c9 100644 --- a/templates/file.md +++ b/templates/file.md @@ -1,6 +1,8 @@ --- {% include '_head.md' %} +{% include '_nav.md' %} + {% include '_breadcrumbs.md' %} {% if type == 'text' %} diff --git a/templates/log.md b/templates/log.md index afe6874..ccfb780 100644 --- a/templates/log.md +++ b/templates/log.md @@ -1,6 +1,8 @@ --- {% include '_head.md' %} +{% include '_nav.md' %} + {% if commits %} | Message | Branches/Tags | Date | |---------|---------------|------| diff --git a/templates/overview.md b/templates/overview.md index 135e107..e9a7599 100644 --- a/templates/overview.md +++ b/templates/overview.md @@ -2,6 +2,8 @@ date: {{ latest_commit_date }} {% include '_head.md' %} +{% include '_nav.md' %} + {% if branches %} | Branch | Commit | Date | |--------|--------|------| diff --git a/templates/tree.md b/templates/tree.md index 8786021..bfc8af4 100644 --- a/templates/tree.md +++ b/templates/tree.md @@ -1,6 +1,8 @@ --- {% include '_head.md' %} +{% include '_nav.md' %} + {% if entries %} {% include '_breadcrumbs.md' %} diff --git a/tests/commit_page_test.py b/tests/commit_page_test.py index bfff3c4..2078ed3 100644 --- a/tests/commit_page_test.py +++ b/tests/commit_page_test.py @@ -19,6 +19,7 @@ def test_context(): assert(context['commit'] == commit) assert(context['redacted_email'] == 'u...@te.st') assert(context['content_subdir'] == 'commit/content') + assert(context['this_commit'] == commit) def test_redacting_email(): assert(redact_email(None) == '') diff --git a/tests/file_page_test.py b/tests/file_page_test.py index 3fff51e..097f5a1 100644 --- a/tests/file_page_test.py +++ b/tests/file_page_test.py @@ -42,6 +42,7 @@ def test_context(): assert(context['title'] == 'file test: test_file.txt') assert(context['type'] == 'text') assert(context['breadcrumbs'] == '[/](/file/content/123/t/)/[test_file.txt](/file/content/123/t/test_file.txt)') + assert(context['this_commit'] == commit) def test_context_dot_file(): file = MagicMock() diff --git a/tests/log_page_test.py b/tests/log_page_test.py index 041544e..da00fd0 100644 --- a/tests/log_page_test.py +++ b/tests/log_page_test.py @@ -2,13 +2,13 @@ from g2h.log_page import LogPage from unittest.mock import MagicMock def test_init(): - page = LogPage('test/log', 'log test', None, None, None, '') + page = LogPage('test/log', 'log test', None, None, None, '', None) assert(page.name == 'log test') assert(page.out_file_path == 'test/log/l.md') assert(page.template.name == 'log.md') def test_context_no_commits(): - page = LogPage('test/log', 'log test', None, None, None, '') + page = LogPage('test/log', 'log test', None, None, None, '', None) context = page.context() assert(context['title'] == 'log test: Log') assert(context['commits'] == []) @@ -18,10 +18,11 @@ def test_context_no_branches_and_tags(): commit.summary = 'mock commit' commit.hexsha = 1234; commit.committed_datetime = 0 - page = LogPage('test/log', 'log test', [commit], None, None, '') + page = LogPage('test/log', 'log test', [commit], None, None, '', commit) context = page.context() assert(context['title'] == 'log test: Log') assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}]) + assert(context['this_commit'] == commit) def test_context_matching_branch_no_tags(): commit = MagicMock() @@ -31,7 +32,7 @@ def test_context_matching_branch_no_tags(): branch = MagicMock() branch.commit.hexsha = commit.hexsha branch.name = 'mock branch' - page = LogPage('test/log', 'log test', [commit], [branch], None, '') + page = LogPage('test/log', 'log test', [commit], [branch], None, '', None) context = page.context() assert(context['title'] == 'log test: Log') assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': ['mock branch'], 'summary': 'mock commit'}]) @@ -44,7 +45,7 @@ def test_context_unmatching_branch_no_tags(): branch = MagicMock() branch.commit.hexsha = 4321 branch.name = 'mock branch' - page = LogPage('test/log', 'log test', [commit], [branch], None, '') + page = LogPage('test/log', 'log test', [commit], [branch], None, '', None) context = page.context() assert(context['title'] == 'log test: Log') assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}]) @@ -57,7 +58,7 @@ def test_context_no_branch_matching_tag(): tag = MagicMock() tag.commit.hexsha = commit.hexsha tag.name = 'mock tag' - page = LogPage('test/log', 'log test', [commit], None, [tag], '') + page = LogPage('test/log', 'log test', [commit], None, [tag], '', None) context = page.context() assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': ['mock tag'], 'summary': 'mock commit'}]) @@ -69,7 +70,7 @@ def test_context_no_branch_no_matching_tag(): tag = MagicMock() tag.commit.hexsha = 4321 tag.name = 'mock tag' - page = LogPage('test/log', 'log test', [commit], None, [tag], '') + page = LogPage('test/log', 'log test', [commit], None, [tag], '', None) context = page.context() assert(context['title'] == 'log test: Log') assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}]) @@ -85,7 +86,7 @@ def test_context_no_matching_branch_no_matching_tag(): tag = MagicMock() tag.commit.hexsha = 4321 tag.name = 'mock tag' - page = LogPage('test/log', 'log test', [commit], [branch], [tag], '') + page = LogPage('test/log', 'log test', [commit], [branch], [tag], '', None) context = page.context() assert(context['title'] == 'log test: Log') assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': [], 'summary': 'mock commit'}]) @@ -101,7 +102,7 @@ def test_context_matching_branch_matching_tag(): tag = MagicMock() tag.commit.hexsha = commit.hexsha tag.name = 'mock tag' - page = LogPage('test/log', 'log test', [commit], [branch], [tag], '') + page = LogPage('test/log', 'log test', [commit], [branch], [tag], '', None) context = page.context() assert(context['title'] == 'log test: Log') assert(context['commits'] == [{'committed_datetime': 0, 'hexsha': 1234, 'refs': ['mock branch', 'mock tag'], 'summary': 'mock commit'}]) @@ -115,7 +116,7 @@ def test_multiple_commits(): commit2.summary = 'mock commit 2' commit2.hexsha = 2; commit2.committed_datetime = 1 - page = LogPage('test/log', 'log test', [commit1, commit2], None, None, '') + page = LogPage('test/log', 'log test', [commit1, commit2], None, None, '', None) context = page.context() assert(context['title'] == 'log test: Log') assert(context['commits'] == [ @@ -135,7 +136,7 @@ def test_multiple_commits_branch(): branch = MagicMock() branch.commit.hexsha = 1 branch.name = 'mock branch' - page = LogPage('test/log', 'log test', [commit1, commit2], [branch], None, '') + page = LogPage('test/log', 'log test', [commit1, commit2], [branch], None, '', None) context = page.context() assert(context['title'] == 'log test: Log') assert(context['commits'] == [ @@ -155,7 +156,7 @@ def test_multiple_commits_tag(): tag = MagicMock() tag.commit.hexsha = 1 tag.name = 'mock tag' - page = LogPage('test/log', 'log test', [commit1, commit2], None, [tag], '') + page = LogPage('test/log', 'log test', [commit1, commit2], None, [tag], '', None) context = page.context() assert(context['title'] == 'log test: Log') assert(context['commits'] == [ @@ -178,7 +179,7 @@ def test_multiple_commits_branch_and_tag(): tag = MagicMock() tag.commit.hexsha = 2 tag.name = 'mock tag' - page = LogPage('test/log', 'log test', [commit1, commit2], [branch], [tag], '') + page = LogPage('test/log', 'log test', [commit1, commit2], [branch], [tag], '', None) context = page.context() assert(context['title'] == 'log test: Log') assert(context['commits'] == [ diff --git a/tests/overview_page_test.py b/tests/overview_page_test.py index 1d94acf..d2b3f82 100644 --- a/tests/overview_page_test.py +++ b/tests/overview_page_test.py @@ -5,6 +5,7 @@ from g2h.overview_page import OverviewPage def test_init(): commit = Mock() commit.committed_datetime = '2025-04-01T12:34:56+00:00' + commit.hexsha = 'abc' page = OverviewPage('test/overview', 'overview test', 'test branch', 'test tag', 'overview/sub/dir', commit) context = page.context() assert(context['title'] == 'overview test') @@ -12,3 +13,4 @@ def test_init(): assert(context['tags'] == 'test tag') assert(context['content_subdir'] == 'overview/sub/dir') assert(context['latest_commit_date'] == '2025-04-01T12:34:56+00:00') + assert(context['this_commit'] == commit) diff --git a/tests/tree_page_test.py b/tests/tree_page_test.py index a298728..57084d1 100644 --- a/tests/tree_page_test.py +++ b/tests/tree_page_test.py @@ -54,6 +54,7 @@ def test_context_empty(): assert(context['subdir'] == '/123/t/tree/path') assert(context['title'] == 'tree test: Tree') assert(context['breadcrumbs'] == '[/](/123/t/)') + assert(context['this_commit'] == commit) def test_context_entries(): tree = MagicMock() |