From e1b24b557d00407fb96755c34a8956afff56a51a Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 26 Sep 2026 08:38:40 -1000 Subject: Add stable markup hooks for site themes --- source/ui-tree.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'source/ui-tree.c') diff --git a/source/ui-tree.c b/source/ui-tree.c index 4d829fe..5b0cdea 100644 --- a/source/ui-tree.c +++ b/source/ui-tree.c @@ -197,13 +197,13 @@ static bool print_object(const struct object_id *oid, const char *path, cgit_set_title_from_path(path); cgit_print_layout_start(); - htmlf("blob: %s (", oid_to_hex(oid)); + htmlf("
blob: %s (", oid_to_hex(oid)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); if (ctx.repo->enable_blame && !is_binary) { html(") ("); cgit_blame_link("blame", NULL, NULL, ctx.qry.head, rev, path); } - html(")\n"); + html(")
\n"); if (is_binary) print_binary_buffer(buf, size); @@ -300,7 +300,14 @@ static void print_ls_row(const struct object_id *oid, const char *pathname, } } - html(""); + if (S_ISGITLINK(mode)) + html(""); + else if (S_ISDIR(mode)) + html(""); + else if (S_ISLNK(mode)) + html(""); + else + html(""); cgit_print_filemode(mode); html(""); if (S_ISGITLINK(mode)) { @@ -309,9 +316,14 @@ static void print_ls_row(const struct object_id *oid, const char *pathname, print_dir_chain(oid, name, walk->rev, &fullpath); } else { char *ext = strrchr(name, '.'); + strbuf_addstr(&class, "ls-blob"); - if (ext) - strbuf_addf(&class, " %s", ext + 1); + // The extension becomes a class a stylesheet can pick files out + // by, prefixed so that a name such as x.button cannot land on a + // class of the theme's own. + if (ext && ext[1] && strspn(ext + 1, "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-") == strlen(ext + 1)) + strbuf_addf(&class, " ext-%s", ext + 1); cgit_tree_link(name, NULL, class.buf, ctx.qry.head, walk->rev, fullpath.buf); } // A target longer than any path is no link, and reading it would pull @@ -404,18 +416,18 @@ static void ls_flush(struct walk_tree_context *walk) static void ls_head(void) { cgit_print_layout_start(); - html("\n"); + html("
\n\n"); html(""); - html(""); - html(""); - html(""); + html(""); + html(""); + html(""); html(""); html("\n"); } static void ls_tail(void) { - html("
ModeNameSizeModeNameSize
\n"); + html("\n\n"); cgit_print_layout_end(); } -- cgit v2.8.0