commit 17e68fe3ad88042864fc7959498fa743fb2eacbf
parent 7a812ea9c3fb3ad923ddc96b85acc4e4595d6db5
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 26 May 2022 18:04:24 +0200
parent 7a812ea9c3fb3ad923ddc96b85acc4e4595d6db5
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 26 May 2022 18:04:24 +0200
stagit-index: refactor html output
1 file changed, 41 insertions(+), 28 deletions(-)
diff --git a/stagit-index.c b/stagit-index.c @@ -12,12 +12,12 @@ static git_repository *repo; static const char *relpath = ""; -static char description[255] = "Oscar Benedito's Git repositories"; +static char description[255]; static char *pagename = ""; static char *email = ""; +static char *category = ""; static char *name = ""; static char owner[255]; -static char category[255]; /* Handle read or write errors for a FILE * stream */ void @@ -98,33 +98,41 @@ printtimeshort(FILE *fp, const git_time *intime) void writeheader(FILE *fp) { - fputs("<!DOCTYPE html>\n" - "<html>\n<head>\n" - "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" - "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n" + fputs("<!DOCTYPE html>\n<html><head>" + "<meta charset=\"utf-8\">" + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" + "<link href=\"/style.css\" rel=\"stylesheet\">" "<title>", fp); - xmlencode(fp, description, strlen(description)); - fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/svg+xml\" href=\"../%slogo.svg\" />\n", relpath); - fprintf(fp, "<link rel=\"alternate icon\" href=\"%sfavicon.ico\" />\n", relpath); - fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", relpath); - fputs("</head>\n<body id=\"home\">\n<h1>", fp); - xmlencode(fp, description, strlen(description)); - fputs("</h1>\n<div id=\"content\">\n" - "<h2 id=\"repositories\">Repositories</h2>\n" - "<div class=\"table-container\">\n<table id=\"index\"><thead>\n" - "<tr><td><b>Name</b></td><td><b>Description</b></td><td><b>Last commit</b></td></tr>" - "</thead><tbody>\n", fp); + + xmlencode(fp, pagename, strlen(pagename)); + + fputs("</title></head><body>\n<header><h1>", fp); + + xmlencode(fp, pagename, strlen(pagename)); + + fputs("</h1></header>\n<main>" + "<table class=\"repositories\"><thead><tr>" + "<td>Name</td>" + "<td>Description</td>" + "<td>Last commit</td>" + "</tr></thead><tbody>\n", fp); } void writefooter(FILE *fp) { - fputs("</tbody>\n</table>\n</div>\n" - "<h2 id=\"contribute\">Contribute</h2>\n" - "<p>The best way to contribute to my repositories is through e-mail, check out <a href=\"https://git-send-email.io\">git-send-email.io</a> if you don’t know how to do that. Send your patches to <a href=\"mailto:patches@oscarbenedito.com\">patches@oscarbenedito.com</a> and change the subject prefix to specify the repository you are sending the patch for. You can do that running the following command from the git repository:</p>\n" - "<pre><code>git config format.subjectPrefix \"PATCH <name-of-repository>\"</code></pre>\n" - "<p>You can also contribute on <a href=\"https://github.com/oscarbenedito\">GitHub</a> doing pull requests (all my public repositories are mirrored there, as well as <a href=\"https://git.sr.ht/~ob\">SourceHut</a>).</p>\n" - "</div>\n</body>\n</html>\n", fp); + fputs("</tbody></table>\n", fp); + + if (email[0]) fprintf(fp, "<h2 id=\"contribute\">Contribute</h2>" + "<p>The best way to contribute to my repositories is through e-mail, check out <a href=\"https://git-send-email.io\">git-send-email.io</a> if you don’t know how to do that. Send your patches to <a href=\"mailto:%s\">%s</a> and change the subject prefix to specify the repository you are sending the patch for. You can do that running the following command from the git repository:</p>" + "<pre><code>git config format.subjectPrefix \"PATCH <name-of-repository>\"</code></pre>\n" , email, email); + + static char *gen_time; + time_t now = time(&now); + gen_time = ctime(&now); + gen_time[24] = '\0'; + + fprintf(fp, "\n</main><footer><p>Generated on %s (UTC)</p></footer></body></html>", gen_time); } int @@ -155,7 +163,12 @@ writelog(FILE *fp) if (!strcmp(p, ".git")) *p = '\0'; - fputs("<tr class=\"repo\"><td><a href=\"", fp); + if(!category[0]) { + fputs("<tr><td><a href=\"", fp); + } else { + fputs("<tr><td class=\"sublevel-repo\"><a href=\"", fp); + } + percentencode(fp, stripped_name, strlen(stripped_name)); fputs("/\">", fp); xmlencode(fp, stripped_name, strlen(stripped_name)); @@ -222,10 +235,10 @@ main(int argc, char *argv[]) i++; if (i == argc) err(1, "missing argument"); - repodir = argv[i]; - fputs("<tr class=\"cat\"><td>", stdout); - xmlencode(stdout, repodir, strlen(repodir)); - fputs("</td><td></td><td></td></tr>\n", stdout); + category = argv[i]; + fputs("<tr><td class=\"reposection\" colspan=\"3\">", stdout); + xmlencode(stdout, category, strlen(category)); + fputs("</td></tr>", stdout); continue; }