roundabout,
created on Wednesday, 3 April 2024, 07:07:17 (1712128037),
received on Wednesday, 31 July 2024, 06:54:44 (1722408884)
Author identity: vlad <vlad.muntoiu@gmail.com>
e9142f339311fbe18a3c0be541596ee5e21f7db5
jinja_utils.py
@@ -27,3 +27,8 @@ def decode(value: bytes, codec: str = "UTF-8", errors: str = "strict"):
@app.template_filter("markdown")
def decode(value: str):
return Markup(markdown.make_html(markdown.tokenise(value)))
@app.template_filter("parse_diff_location")
def decode(value: str):
return [tuple(int(j) for j in i.lstrip("-+").split(",")) for i in value.removeprefix("@@ ").removesuffix(" @@").split(" ")]
static/style.css
@@ -15,6 +15,7 @@
--color-insertion-text: currentColor;
--color-deletion: #D5000066;
--color-deletion-text: currentColor;
--color-code-line-number: #455A64;
}
.big-button {
@@ -384,18 +385,6 @@ header {
padding: 8px 1em;
}
ins {
background: var(--color-insertion);
color: var(--color-insertion-text);
text-decoration: none;
}
del {
background: var(--color-deletion);
color: var(--color-deletion-text);
text-decoration: none;
}
.interrupt-top {
--mask: conic-gradient(from 135deg at top, #0000, #000 0 90deg,#0000 90deg) 50%/16px 100%;
padding-top: calc(var(--padding-code) + 8px);
@@ -404,5 +393,64 @@ del {
}
.diff-position {
text-align: center;
width: 100%;
background: var(--color-code-line-number);
color: var(--color-code-text);
padding: 8px;
}
.code-view {
white-space: normal;
padding: 0;
display: grid;
grid-auto-rows: min-content;
width: 100%;
overflow: auto;
}
.inner-wrapper {
display: inline-block;
}
.code-view :is(code, ins, del, x-codeline) {
white-space: pre;
font: inherit;
color: inherit;
background: inherit;
display: inline;
padding: 0;
margin: 0;
width: 100%;
}
.code-view > :is(code, ins, del, x-codeline):first-child::before {
padding-top: 1em;
}
.code-view > :is(code, ins, del, x-codeline):last-child::before {
padding-bottom: 1em;
}
.ln::before {
content: attr(data-ln);
display: inline-block;
width: 8ch;
box-sizing: content-box;
text-align: right;
padding-right: 1ch;
margin-right: 1ch;
background: var(--color-code-line-number);
position: sticky;
left: 0;
}
ins, .code-view > ins {
background: var(--color-insertion);
color: var(--color-insertion-text);
text-decoration: none;
}
del, .code-view > del {
background: var(--color-deletion);
color: var(--color-deletion-text);
text-decoration: none;
}
templates/repository/repo-commit.html
@@ -1,4 +1,4 @@
{% extends "default.html" %}
{% extends "repo.html" %}
{% set active_page = "log" %}
@@ -10,17 +10,40 @@
<x-frame style="--width: 896px;" class="flexible-space">
{% for file in diff %}
<h2>{{ file }}</h2>
{% set vars = namespace(i=0) %}
{% set vars = namespace(original_line=0, modified_line=0, hunk_started=false) %}
{% for line in diff[file] %}
{% if line.startswith("@@") %}
{% break %}
{% if vars.hunk_started %}
</pre> <!-- Close the previous pre block if this isn't the first hunk -->
{% endif %}
{% set vars.hunk_started = true %}
{% set diff_location = line|parse_diff_location %}
{% set vars.original_line = diff_location[0][0] %}
{% set vars.modified_line = diff_location[1][0] %}
<h3 class="diff-position">{{ line }}</h3>
<!-- Intentionally not displaying hunk headers directly -->
<pre class="code-view"> <!-- Start a new pre block for hunk content -->
{% elif vars.hunk_started %}
{% if line.startswith("+") %}
<ins class="ln" data-ln="{{ vars.modified_line }} +">{{ line[1:] }}</ins>
{% set vars.modified_line = vars.modified_line + 1 %}
{% elif line.startswith("-") %}
<del class="ln" data-ln="{{ vars.original_line }} -">{{ line[1:] }}</del>
{% set vars.original_line = vars.original_line + 1 %}
{% else %}
{% if line %}
<x-codeline class="ln" data-ln="{{ vars.modified_line }} ">{{ line }}</x-codeline>
{% endif %}
{% if not line.startswith("@@") %}
{% set vars.original_line = vars.original_line + 1 %}
{% set vars.modified_line = vars.modified_line + 1 %}
{% endif %}
{% endif %}
{% endif %}
{% set vars.i = vars.i+1 %}
{% endfor %}
<h4 class="diff-position">{{ diff[file][vars.i] }}</h4>
{% set vars.i = vars.i+1 %}
<pre class="interrupt-top">{% for line in diff[file][vars.i:] %}
{% if line[0] == "+" %}<ins>{{ line }}</ins>{% elif line[0] == "-" %}<del>{{ line }}</del>{% else %}{{ line }}{% endif %}{% endfor %}</pre>
{% if vars.hunk_started %}
</pre> <!-- Ensure the last pre block is closed -->
{% endif %}
{% endfor %}
</x-frame>
</x-vbox>