diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Add stable markup hooks for site themes
Diffstat (limited to 'source/ui-tree.c')
-rw-r--r--source/ui-tree.c32
1 file changed, 22 insertions, 10 deletions
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("<div class='blob-header'>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(")</div>\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("<tr><td class='ls-mode'>");
+ if (S_ISGITLINK(mode))
+ html("<tr class='mod'><td class='ls-mode'>");
+ else if (S_ISDIR(mode))
+ html("<tr class='dir'><td class='ls-mode'>");
+ else if (S_ISLNK(mode))
+ html("<tr class='link'><td class='ls-mode'>");
+ else
+ html("<tr class='blob'><td class='ls-mode'>");
cgit_print_filemode(mode);
html("</td><td>");
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("<table class='list'>\n");
+ html("<table class='list tree' aria-label='Files'>\n<tbody class='tree'>\n");
html("<tr class='nohover'>");
- html("<th class='left ls-mode'>Mode</th>");
- html("<th class='left'>Name</th>");
- html("<th class='right'>Size</th>");
+ html("<th class='left ls-mode' scope='col'>Mode</th>");
+ html("<th class='left' scope='col'>Name</th>");
+ html("<th class='right' scope='col'>Size</th>");
html("<th class='ls-links'></th>");
html("</tr>\n");
}
static void ls_tail(void)
{
- html("</table>\n");
+ html("</tbody>\n</table>\n");
cgit_print_layout_end();
}