ctucx.git: stagit

ctucx' stagit fork

commit 2780792a7bf3beb1e1c1fa6c3c24652823cef72a
parent acafafc259281ec2def25a905b61e8b4eeaee524
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 24 May 2022 11:43:15 +0200

writefilestree: refactor html output
1 file changed, 19 insertions(+), 15 deletions(-)
M
stagit.c
|
34
+++++++++++++++++++---------------
diff --git a/stagit.c b/stagit.c
@@ -1020,16 +1020,20 @@ writefilestree(FILE *fp, git_tree *tree, const char *path)
 	size_t count, i, lc, filesize;
 	int r, rf, ret, is_obj_tree;
 
+
 	if (strlen(path) > 0) {
-		fputs("<h2>Directory: ", fp);
+		fputs("<div class=\"breadcrumb\">path: /", fp);
 		xmlencode(fp, path, strlen(path));
-		fputs("</h2>\n", fp);
+		fputs("</div>", fp);
 	}
 
-	fputs("<table id=\"files\"><thead>\n<tr>"
-			"<td><b>Mode</b></td><td><b>Name</b></td>"
-			"<td class=\"num\" align=\"right\"><b>Size</b></td>"
-			"</tr>\n</thead><tbody>\n", fp);
+	fputs("<table class=\"files\"><thead><tr>"
+			"<td>Mode</td>"
+			"<td>Name</td>"
+			"<td>Size</td>"
+			"<td></td>"
+			"</tr></thead>"
+			"<tbody>", fp);
 
 	if (strlen(path) > 0) {
 		if (strlcpy(tmp, path, sizeof(tmp)) >= sizeof(tmp))

@@ -1045,9 +1049,10 @@ writefilestree(FILE *fp, git_tree *tree, const char *path)
 			else
 				++parent;
 		}
+
 		fputs("<tr><td>d---------</td><td><a class=\"dir\" href=\"../", fp);
-		xmlencode(fp, parent, strlen(parent));
-		fputs(".html\">..</a></td><td class=\"num\" align=\"right\"></td></tr>\n", fp);
+		xmlencodeline(fp, parent, strlen(parent));
+		fputs(".html\">..</a></td><td></td></tr>", fp);
 	}
 
 	count = git_tree_entrycount(tree);

@@ -1106,19 +1111,18 @@ writefilestree(FILE *fp, git_tree *tree, const char *path)
 
 			fputs("<tr><td>", fp);
 			fputs(filemode(git_tree_entry_filemode(entry)), fp);
-			fputs("</td><td><a ", fp);
-			if (git_object_type(obj) == GIT_OBJ_TREE)
-				fputs("class=\"dir\" ", fp);
-			fprintf(fp, "href=\"%s", relpath);
+			fprintf(fp, "</td><td><a href=\"%s", relpath);
 			percentencode(fp, filepath, strlen(filepath));
 			fputs("\">", fp);
 			xmlencode(fp, entryname, strlen(entryname));
-			fputs("</a></td><td class=\"num\" align=\"right\">", fp);
+			fputs("</a></td><td>", fp);
 			if (!is_obj_tree) {
 				fprintf(fp, "%s", format_bytes(filesize));
 				if (filesize < 1024) fputs("&nbsp;", fp);
 			}
-			fputs("</td></tr>\n", fp);
+			fprintf(fp, "</td><td><a href=\"%s", relpath);
+			percentencode(fp, rawpath, strlen(rawpath));
+			fputs("\">plain</a></td>", fp);
 			git_object_free(obj);
 		} else if (git_tree_entry_type(entry) == GIT_OBJ_COMMIT) {
 			/* commit object in tree is a submodule */

@@ -1128,7 +1132,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path)
 			fputs("</a> @ ", fp);
 			git_oid_tostr(oid, sizeof(oid), git_tree_entry_id(entry));
 			xmlencode(fp, oid, strlen(oid));
-			fputs("</td><td class=\"num\" align=\"right\"></td></tr>\n", fp);
+			fputs("</td><td></td></tr>\n", fp);
 		}
 	}