Browse Source

Worked on project homepage

main
root 5 months ago
parent
commit
411656e5af
  1. 8
      README.md
  2. 3
      cutegit/core.py
  3. 18
      cutegit/git/backend.py
  4. 68
      cutegit/static/highlight.css
  5. 36
      cutegit/templates/repository/index.html
  6. 16
      cutegit/views.py
  7. 2
      setup.py

8
README.md

@ -24,7 +24,7 @@ $ FLASK_ENV=cutegit:app flask run
## TODOs and ideas
- [Git] ~~repository list~~
- [Git] Non-git metadata (~~category, description, public/private~~, clone URL)
- [Git] ~~Non-git metadata (category, description, public/private, clone URL)~~
- [Core] Login / Logout for accessing private repositories
- [Git] metadata (branches, default branch, ~~commit count~~)
- [Git] commit list (short messages, hashes, details blocks to full commit message)
@ -32,8 +32,10 @@ $ FLASK_ENV=cutegit:app flask run
- [Git] structured commit diff display
- [Git] raw object display
- [Git] formatted object display
- [Git] README.md auto-render
- [Git] ~~README.md auto-render~~
- [Git] Render cache (redis, probably)
- [Core] Config to hide or show authors, defaults to hiding
- [Core] Additional metadata configuration (e.g. links and such)
- [Core] Markdown support in description
- [Core] RSS feed for project list
- [Core] RSS feed for git log of a given project branch
- [Core] "Wiki"

3
cutegit/core.py

@ -1,3 +1,6 @@
from flask import Flask
app = Flask(__name__)
# TODO: Configuration
app.config['clone_url'] = 'styx.artemix.space:git'

18
cutegit/git/backend.py

@ -8,19 +8,19 @@ from pygit2 import Repository as _Repository, GitError
class Repository(_Repository):
file_cache: dict
value_cache: dict
def __init__(self, path=None, flags=0):
super().__init__(path, flags)
self.file_cache = {}
self.value_cache = {}
def get_name(self) -> str:
return Path(self.path).name
def get_from_file(self, file: str, default_value: Optional[str] = None, fresh=False) -> Optional[str]:
path = Path(self.path) / file
if file in self.file_cache and not fresh:
return self.file_cache[file]
if file in self.value_cache and not fresh:
return self.value_cache[file]
if path.is_file():
with open(path, 'r') as f:
@ -28,9 +28,9 @@ class Repository(_Repository):
else:
content = default_value
self.file_cache[file] = content
self.value_cache[file] = content
return self.file_cache[file]
return self.value_cache[file]
def get_category(self) -> str:
return self.get_from_file('category', '')
@ -38,6 +38,12 @@ class Repository(_Repository):
def get_description(self) -> str:
return self.get_from_file('description', '*No description*')
def get_readme(self) -> Optional[str]:
if self.is_empty:
return None
tree = self.revparse_single(self.head.name).tree
return tree['README.md'].data.decode() if 'README.md' in tree else None
def is_public(self) -> bool:
return (Path(self.path) / 'git-daemon-export-ok').is_file()

68
cutegit/static/highlight.css

@ -0,0 +1,68 @@
.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */

36
cutegit/templates/repository/index.html

@ -1 +1,35 @@
<h1>{{ name }}</h1>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='highlight.css') }}">
<header>
<nav>
<a href="{{ url_for('homepage') }}">CuteGit</a>
&rsaquo;
<a href="{{ url_for('repository_index', repo=name) }}">{{ name }}</a>:
{{ repo.get_description() }}
</nav>
<nav class="sub-nav">
<ul>
<li><a href="{{ url_for('repository_index', repo=name) }}">Summary</a></li>
<li><a href="{{ url_for('repository_index', repo=name) }}">Branches &amp; tags</a></li>
<li><a href="{{ url_for('repository_index', repo=name) }}">Updates feed</a></li>
</ul>
</nav>
</header>
<aside class="metadata">
<label>Clone URL: <input type="url" value="{{ name|clone_url }}" readonly/></label>
</aside>
<main>
{% set readme = repo.get_readme() %}
{% if readme %}
<details open>
<summary>README.md</summary>
{% autoescape false %}
{{ readme|md }}
{% endautoescape %}
</details>
{% endif %}
</main>

16
cutegit/views.py

@ -1,6 +1,9 @@
from datetime import datetime, timedelta
from pathlib import Path
from time import time
from flask import current_app
from markdown import markdown
from pygit2 import Repository, Reference, GIT_SORT_REVERSE, GIT_SORT_TOPOLOGICAL
from .core import app
@ -56,3 +59,16 @@ def date_iso8601(v):
@app.template_filter('git_count_commits')
def count_commits_on_ref(ref: Reference, repo: Repository):
return len(list(repo.walk(ref.target, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE)))
@app.template_filter('md')
def md(v: str) -> str:
return markdown(v, extensions=['codehilite', 'fenced_code', 'footnotes', 'toc'], extension_configs={
'footnotes': {'UNIQUE_IDS': True},
'toc': {'permalink': True},
})
@app.template_filter('clone_url')
def clone_url(repo: str) -> str:
return Path(current_app.config['clone_url']) / repo

2
setup.py

@ -20,6 +20,8 @@ setup(
install_requires=[
'Flask',
'pygit2',
'markdown',
'Pygments',
],
classifiers=[
'Environment :: Console',

Loading…
Cancel
Save