the repository which powers this website
Implement themed commit page
| -rw-r--r-- | cgit.mk | 2 | ||||
| -rw-r--r-- | cmd.c | 3 | ||||
| -rw-r--r-- | themed/commit.html | 65 | ||||
| -rw-r--r-- | themed/themed.in.css | 108 | ||||
| -rw-r--r-- | ui-commit.c | 2 | ||||
| -rw-r--r-- | ui-commit.h | 2 |
6 files changed, 178 insertions, 4 deletions
@@ -129,7 +129,7 @@ $(CGIT_PREFIX).depend: $(CGIT_PREFIX)themed/.depend: @mkdir -p $@ -$(CGIT_PREFIX)themed/themed.c: $(CGIT_PREFIX)themed/base.html $(CGIT_PREFIX)themed/index.html $(CGIT_PREFIX)themed/log.html $(CGIT_PREFIX)themed/refs.html +$(CGIT_PREFIX)themed/themed.c: $(CGIT_PREFIX)themed/base.html $(CGIT_PREFIX)themed/index.html $(CGIT_PREFIX)themed/commit.html $(CGIT_PREFIX)themed/log.html $(CGIT_PREFIX)themed/refs.html cd $(CGIT_PREFIX)themed; python -m htmlcc $^ > $@ $(CGIT_PREFIX)themed/themed.css: $(CGIT_PREFIX)themed/themed.in.css @@ -79,7 +79,8 @@ static void blob_fn(void) static void commit_fn(void) { - cgit_print_commit(ctx.qry.oid, ctx.qry.path); + //cgit_print_commit(ctx.qry.oid, ctx.qry.path); + cgit_print_commit(); } static void diff_fn(void) diff --git a/themed/commit.html b/themed/commit.html new file mode 100644 index 00000000..d7fafde9 --- /dev/null +++ b/themed/commit.html @@ -0,0 +1,65 @@ +{! #include "../ui-diff.h" !} + +{% page cgit_print_commit %} +{! + char *hex = ctx.qry.oid; + if (!hex) { hex = ctx.qry.head; } + + struct object_id oid; + if (repo_get_oid(the_repository, hex, &oid)) { + die("Bad object id"); + } + struct commit *commit = lookup_commit_reference(the_repository, &oid); + if (!commit) { + die("Bad commit reference"); + } + struct commitinfo *info = cgit_parse_commit(commit); + + ctx.page.title = fmtalloc("%s - %s", info->subject, ctx.page.title); +!} +{! page_start(); !} +{! repo_header(); !} + <main class="max-w-[1280px] mx-auto py-4">{# Main content #} +{! repo_description_panel(); !} +{! repo_summary_bar(); !} + <div class="grid grid-cols-1 border border-gray-300 rounded-md divide-y divide-gray-300 mb-4"> + {# Commit info box #} + <div class="px-3 py-2 flex items-top"> + <div class="flex-1"> + {# Description panel #} + <p class="text-lg font-semibold">{{ info->subject }}</p> + </div> + <div class="py-2"> + <a href="{! cgit_shared_repolink_url_with_delimiter("tree", ctx.qry.head, ctx.qry.vpath); !}id={{ oid_to_hex(&commit->object.oid) }}" class="p-2 text-sm text-white bg-blue-500 rounded-md hover:bg-blue-600">Browse Source</a> + </div> + </div> + <div class="px-3 py-2 rounded-b-md bg-gray-50 flex gap-x-1 items-center"> + <img src="{! gravatar_url(info->author_email); !}?s=24"> + <span class="font-semibold text-sm">{{ info->author }}</span> + <span class="font-gray-500 text-sm">{! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago</span> + <div class="flex-1"></div> + <span class="font-gray-500 text-sm"> + {! char short_commit_id[8]; !} + {% for struct commit_list *p = commit->parents; p; p = p->next %} + {! struct commit *parent = lookup_commit_reference(the_repository, &p->item->object.oid); !} + {% if parent %} + {! memcpy(short_commit_id, oid_to_hex(&p->item->object.oid), 7); !} + {! short_commit_id[7] = '\0'; !} + parent <a href="{! cgit_shared_repolink_url_with_delimiter("commit", ctx.qry.head, ctx.qry.vpath); !}id={{ oid_to_hex(&p->item->object.oid) }}" class="font-mono text-blue-500 hover:text-blue-600 hover:underline">{{ short_commit_id }}</a> + · + {% endif %} + {% endfor %} + {! memcpy(short_commit_id, oid_to_hex(&commit->object.oid), 7); !} + {! short_commit_id[7] = '\0'; !} + commit <a href="{! cgit_shared_repolink_url_with_delimiter("commit", ctx.qry.head, ctx.qry.vpath); !}id={{ oid_to_hex(&commit->object.oid) }}" class="font-mono text-blue-500 hover:text-blue-600 hover:underline">{{ short_commit_id }}</a> + </span> + </div> + </div> + <div class="diff-panel"> + {# Diff panel #} + {! cgit_print_diff(ctx.qry.oid, NULL, NULL, 0, 0); !} + </div> + </main> +{! cgit_free_commitinfo(info); !} +{! page_end(); !} +{% endpage %} diff --git a/themed/themed.in.css b/themed/themed.in.css index c1214d32..9ab4c729 100644 --- a/themed/themed.in.css +++ b/themed/themed.in.css @@ -7,3 +7,111 @@ :root { font-size: 11pt; } + +.diff-panel { + a { + @apply text-blue-500 hover:text-blue-600 hover:underline; + } + + /* From cgit.css */ + + div.diffstat-header { + font-weight: bold; + } + + table.diffstat { + border-collapse: collapse; + border: solid 1px #aaa; + background-color: #eee; + } + + table.diffstat th { + font-weight: normal; + text-align: left; + text-decoration: underline; + padding: 0.1em 1em 0.1em 0.1em; + font-size: 100%; + } + + table.diffstat td { + padding: 0.2em 0.2em 0.1em 0.1em; + font-size: 100%; + border: none; + } + + table.diffstat td.mode { + white-space: nowrap; + } + + table.diffstat td span.modechange { + padding-left: 1em; + color: red; + } + + table.diffstat td.add a { + color: green; + } + + table.diffstat td.del a { + color: red; + } + + table.diffstat td.upd a { + color: blue; + } + + table.diffstat td.graph { + width: 500px; + vertical-align: middle; + } + + table.diffstat td.graph table { + border: none; + } + + table.diffstat td.graph td { + padding: 0px; + border: 0px; + height: 7pt; + } + + table.diffstat td.graph td.add { + background-color: #5c5; + } + + table.diffstat td.graph td.rem { + background-color: #c55; + } + + div.diffstat-summary { + color: #888; + padding-top: 0.5em; + } + + table.diff { + width: 100%; + } + + table.diff td { + @apply font-mono; + white-space: pre; + } + + table.diff td div.head { + font-weight: bold; + margin-top: 1em; + color: black; + } + + table.diff td div.hunk { + color: #009; + } + + table.diff td div.add { + color: green; + } + + table.diff td div.del { + color: red; + } +} diff --git a/ui-commit.c b/ui-commit.c index 972e9bc4..26b8cf78 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -15,7 +15,7 @@ #include "ui-diff.h" #include "ui-log.h" -void cgit_print_commit(char *hex, const char *prefix) +void _orig_cgit_print_commit(char *hex, const char *prefix) { struct commit *commit, *parent; struct commitinfo *info, *parent_info; diff --git a/ui-commit.h b/ui-commit.h index 8198b4ba..68ccf4c1 100644 --- a/ui-commit.h +++ b/ui-commit.h @@ -1,6 +1,6 @@ #ifndef UI_COMMIT_H #define UI_COMMIT_H -extern void cgit_print_commit(char *hex, const char *prefix); +extern void cgit_print_commit(); #endif /* UI_COMMIT_H */ |