Implement themed summary page

This commit is contained in:
RunasSudo 2025-05-14 23:32:04 +10:00
parent afd1d440d6
commit b9891a9f17
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
4 changed files with 121 additions and 4 deletions

13
cgit.mk
View File

@ -98,6 +98,13 @@ CGIT_OBJ_NAMES += ui-tree.o
CGIT_OBJ_NAMES += themed/themed.o CGIT_OBJ_NAMES += themed/themed.o
CGIT_OBJ_NAMES += themed/mincrypt_sha256.o CGIT_OBJ_NAMES += themed/mincrypt_sha256.o
CGIT_THEMED_INPUTS += $(CGIT_PREFIX)themed/base.html
CGIT_THEMED_INPUTS += $(CGIT_PREFIX)themed/index.html
CGIT_THEMED_INPUTS += $(CGIT_PREFIX)themed/commit.html
CGIT_THEMED_INPUTS += $(CGIT_PREFIX)themed/log.html
CGIT_THEMED_INPUTS += $(CGIT_PREFIX)themed/refs.html
CGIT_THEMED_INPUTS += $(CGIT_PREFIX)themed/summary.html
CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES)) CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES))
# Only cgit.c reference CGIT_VERSION so we only rebuild its objects when the # Only cgit.c reference CGIT_VERSION so we only rebuild its objects when the
@ -129,11 +136,11 @@ $(CGIT_PREFIX).depend:
$(CGIT_PREFIX)themed/.depend: $(CGIT_PREFIX)themed/.depend:
@mkdir -p $@ @mkdir -p $@
$(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 $(CGIT_PREFIX)themed/themed.c: $(CGIT_THEMED_INPUTS)
cd $(CGIT_PREFIX)themed; python -m htmlcc $^ > $@ cd $(CGIT_PREFIX)themed; python -m htmlcc $^ > $@
$(CGIT_PREFIX)themed/themed.css: $(CGIT_PREFIX)themed/themed.in.css $(CGIT_PREFIX)themed/themed.css: $(CGIT_PREFIX)themed/themed.in.css $(CGIT_THEMED_INPUTS)
cd $(CGIT_PREFIX)themed; tailwindcss -i $^ -o $@ cd $(CGIT_PREFIX)themed; tailwindcss -i $< -o $@
$(CGIT_PREFIX)CGIT-CFLAGS: FORCE $(CGIT_PREFIX)CGIT-CFLAGS: FORCE
@FLAGS='$(subst ','\'',$(CGIT_CFLAGS))'; \ @FLAGS='$(subst ','\'',$(CGIT_CFLAGS))'; \

98
themed/summary.html Normal file
View File

@ -0,0 +1,98 @@
{! #include "../ui-blob.h" !}
{% block ls_item_impl(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *cbdata) %}
{!
unsigned long size = 0;
if (!S_ISGITLINK(mode)) {
oid_object_info(the_repository, oid, &size);
}
!}
<div class="pl-3 pr-1 py-2 border-t border-gray-300">
{% if S_ISDIR(mode) %}
{# Heroicons solid folder #}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-5 text-blue-400 mt-[0.1rem]"><path d="M19.5 21a3 3 0 0 0 3-3v-4.5a3 3 0 0 0-3-3h-15a3 3 0 0 0-3 3V18a3 3 0 0 0 3 3h15ZM1.5 10.146V6a3 3 0 0 1 3-3h5.379a2.25 2.25 0 0 1 1.59.659l2.122 2.121c.14.141.331.22.53.22H19.5a3 3 0 0 1 3 3v1.146A4.483 4.483 0 0 0 19.5 9h-15a4.483 4.483 0 0 0-3 1.146Z" /></svg>
{% else %}
{# Heroicons outline document #}
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-5 text-gray-500 mt-[0.1rem]"><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" /></svg>
{% endif %}
</div>
<div class="pr-3 py-2 border-t border-gray-300"><a href="{! cgit_shared_repolink_url("tree", ctx.qry.head, pathname); !}" class="hover:text-blue-600 hover:underline">{{ pathname }}</a></div>
<div class="pr-3 py-2 border-t border-gray-300 text-gray-500 font-mono">{! cgit_print_filemode(mode); !}</div>
<div class="pr-3 py-2 border-t border-gray-300 text-gray-500 text-end">{% if !S_ISDIR(mode) %}{{ size|%ld }}{% endif %}</div>
{% endblock %}
{!
int ls_item(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *cbdata) {
ls_item_impl(oid, base, pathname, mode, cbdata);
return 0;
}
!}
{% page cgit_print_summary %}
{! 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-[auto_1fr_auto_auto] border border-gray-300 rounded-md mb-4">
{# Latest commit panel (specify rounded-t-md so background does not cover border) #}
{!
// Get latest commit
struct object_id oid;
if (repo_get_oid(the_repository, ctx.qry.head, &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);
!}
<div class="col-span-4 rounded-t-md bg-gray-50 px-3 py-2 flex gap-x-1">
<img src="{! gravatar_url(info->author_email); !}?s=24">
<span class="font-semibold">{{ info->author }}</span>
<a href="{! cgit_shared_repolink_url_with_delimiter("commit", ctx.qry.head, ctx.qry.vpath); !}id={{ oid_to_hex(&commit->object.oid) }}" class="ml-2 text-gray-500 hover:text-blue-600 hover:underline">{{ info->subject }}</a>
<div class="flex-1"></div>
{! char short_commit_id[8]; !}
{! memcpy(short_commit_id, oid_to_hex(&commit->object.oid), 7); !}
{! short_commit_id[7] = '\0'; !}
<span class="text-gray-500"><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 hover:text-blue-600 hover:underline">{{ short_commit_id }}</a> &middot; {! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago</span>
</div>
{# Files #}
{!
const struct object_id *tree_oid = get_commit_tree_oid(commit);
struct tree *tree = parse_tree_indirect(tree_oid);
struct pathspec paths = {
.nr = 0
};
read_tree(the_repository, tree, &paths, ls_item, NULL);
!}
</div>
{% if ctx.repo->readme.nr > 0 %}
{!
char *filename = ctx.repo->readme.items[0].string;
char *ref = ctx.repo->readme.items[0].util;
!}
<div class="flex flex-col border border-gray-300 rounded-md">
{# Readme panel #}
<div class="rounded-t-md bg-gray-50 px-3 py-2 flex gap-x-1 items-center">
{# Heroicons micro book-open #}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="size-4"><path d="M7.25 3.688a8.035 8.035 0 0 0-4.872-.523A.48.48 0 0 0 2 3.64v7.994c0 .345.342.588.679.512a6.02 6.02 0 0 1 4.571.81V3.688ZM8.75 12.956a6.02 6.02 0 0 1 4.571-.81c.337.075.679-.167.679-.512V3.64a.48.48 0 0 0-.378-.475 8.034 8.034 0 0 0-4.872.523v9.268Z" /></svg>
<span class="font-semibold text-sm">{{ filename }}</span>
</div>
{# Readme content #}
<div class="rendered-file p-7 border-t border-gray-300">
{!
cgit_open_filter(ctx.repo->about_filter, filename);
if (ref) {
cgit_print_file(filename, ref, 1);
} else {
html_include(filename);
}
cgit_close_filter(ctx.repo->about_filter);
!}
</div>
</div>
{% endif %}
</main>
{! page_end(); !}
{% endpage %}

View File

@ -8,6 +8,18 @@
font-size: 11pt; font-size: 11pt;
} }
.rendered-file {
a {
@apply hover:underline;
}
:not(h1, h2, h3, h4, h5, h6) > a {
@apply text-blue-500 hover:text-blue-600;
}
ul {
@apply list-disc;
}
}
.diff-panel { .diff-panel {
a { a {
@apply text-blue-500 hover:text-blue-600 hover:underline; @apply text-blue-500 hover:text-blue-600 hover:underline;

View File

@ -40,7 +40,7 @@ static void print_url(const char *url)
html("</a></td></tr>\n"); html("</a></td></tr>\n");
} }
void cgit_print_summary(void) void _orig_cgit_print_summary(void)
{ {
int columns = 3; int columns = 3;