diff options
| author | Christoph Schlosser <christoph@linux.com> | 2025-08-24 17:10:11 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christoph@linux.com> | 2025-08-24 17:10:11 +0200 |
| commit | 9bd3fd1bce788dce610ad7276ce1f1634019c380 (patch) | |
| tree | 59898b74445bf4a9e751b4b7bec46f85a7ad43d8 /g2h/log_page.py | |
| parent | 66dfe0e665ebeb0dce1ff290b77245e4a9fadd88 (diff) | |
| download | git2hugo-9bd3fd1bce788dce610ad7276ce1f1634019c380.tar.gz | |
g2h: Add unit tests and restructure class layout
Instead of having a large generator class use individual pages
Diffstat (limited to 'g2h/log_page.py')
| -rw-r--r-- | g2h/log_page.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/g2h/log_page.py b/g2h/log_page.py new file mode 100644 index 0000000..684a758 --- /dev/null +++ b/g2h/log_page.py @@ -0,0 +1,43 @@ +import os + +from .page import Page + +def ref_names_for_commit(refs, commit_sha): + ref_names = [] + if refs is None: + return ref_names + for ref in refs: + if ref.commit.hexsha == commit_sha: + ref_names.append(ref.name) + + return ref_names + +class LogPage(Page): + def __init__(self, out_dir, name, commits, branches, tags): + super(LogPage, self).__init__('log.md', out_dir, 'l.md', name) + self.commits = commits + self.branches = branches + self.tags = tags + + def _commits_with_refs(self): + commits_context = [] + for commit in self.commits: + refs = ref_names_for_commit(self.branches, commit.hexsha) + ref_names_for_commit(self.tags, commit.hexsha) + commit_context = { + 'committed_datetime': commit.committed_datetime, + 'refs': refs, + 'summary': commit.summary + } + commits_context.append(commit_context) + return commits_context + + def context(self): + commits_context = [] + if self.commits is not None: + commits_context = self._commits_with_refs() + + return { + 'commits': commits_context, + 'title': self.name + ': Log' + } + |