A static page generator for git repositories
git clone git://git.janzachar.dev/spgit.git
0from .repo import page1from .repo_file import tree as Tree2import markdown3import settings456def info(r: Repo) -> str:7 def unpack(s):8 out = "<ul>"9 for k,v in s.items():10 if type(v) is dict:11 out += f"<li>{k}:</li>"12 out += unpack(v)13 elif type(v) is list:14 out += f"<li>{k}: {' '.join(v)}</li>"15 else:16 out += f"<li>{k}: {v}</li>"17 out += "</ul>"18 return out1920 if not r.meta.info:21 return ""2223 return f"""24 <section id="info">25 <h2>info</h2>26 {unpack(r.meta.info)}27 </section>28 """2930def commits(r) -> str:31 out = '<h2>commits</h2><table>'3233 commits = list(r.repo.iter_commits(all=True, max_count=settings.COMMIT_COUNT))34 for c in commits:35 time = c.committed_datetime.date()36 message = c.message.split("\n")[0]37 if len(message) > 80:38 message = message[:80-3] + "..."3940 out += f"""41 <tr>42 <td>[{time}]</td>43 <td>{message}</td>44 </tr>45 """46 out += "</table>"4748 count = r.repo.head.commit.count()49 if settings.COMMIT_COUNT < count:50 out += f"<p> and {count - settings.COMMIT_COUNT} more..."5152 return '<section id="commits">' + out + '</section>'535455def readme(r: Repo) -> str:56 tree = r.repo.head.commit.tree57 if "README.md" not in tree:58 return ""5960 file = tree["README.md"].data_stream61 text = file.read().decode()62 return '<section id="readme">' + \63 markdown.markdown(text) + \64 '</section>'6566def files(r: Repo) -> str:67 tree = r.repo.head.commit.tree68 return f"""69 <section id="files">70 <h2>files</h2>71 {Tree(r, tree)}72 </section>73 """747576def gen(r: Repo) -> str:77 return page(r,78 info(r) +79 commits(r) +80 files(r) +81 "<hr>" +82 readme(r)83 )8485