stagit

static git page generator  https://git.ce9e.org
git clone https://git.ce9e.org/stagit.git

commit
8c1c1c0ce8aee0f053a29195f828eb5186144b3b
parent
f4941a7511106dfee7bcecbcb7a7ab5c4c799b7f
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-03-30 06:35
some html changes

Diffstat

M stagit.c 151 +++++++++++++++++++++++++++++++++----------------------------

1 files changed, 81 insertions, 70 deletions


diff --git a/stagit.c b/stagit.c

@@ -314,50 +314,61 @@ printtimeshort(FILE *fp, const git_time *intime)
  314   314 void
  315   315 write_header(FILE *fp, const char *title)
  316   316 {
  317    -1 	fputs("<!DOCTYPE html>\n"
  318    -1 		"<html>\n<head>\n"
  319    -1 		"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
  320    -1 		"<title>", fp);
   -1   317 	fputs("<!DOCTYPE html>\n", fp);
   -1   318 	fputs("<html>\n", fp);
   -1   319 	fputs("<head>\n", fp);
   -1   320 	fputs("<meta charset=\"UTF-8\"><title>", fp);
  321   321 	xmlencode(fp, title, strlen(title));
  322   322 	if (title[0] && reponame[0])
  323   323 		fputs(" - ", fp);
  324   324 	xmlencode(fp, reponame, strlen(reponame));
  325    -1 	if (description[0])
  326    -1 		fputs(" - ", fp);
  327    -1 	xmlencode(fp, description, strlen(description));
  328    -1 	fputs(fp, "</title>\n");
   -1   325 	if (description[0]) {
   -1   326 		fputs(": ", fp);
   -1   327 		xmlencode(fp, description, strlen(description));
   -1   328 	}
   -1   329 	fputs("</title>\n", fp);
  329   330 	if (favicon[0])
  330   331 		fprintf(fp, "<link rel=\"icon\" type=\"image/png\" href=\"%s\" />\n", favicon);
  331    -1 	fprintf(fp, "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"%s Atom Feed\" href=\"%satom.xml\" />\n",
  332    -1 		reponame, relpath);
   -1   332 	fputs("<link rel=\"alternate\" type=\"application/atom+xml\" title=\"", fp);
   -1   333 	xmlencode(fp, reponame, strlen(reponame));
   -1   334 	fprintf(fp, " Atom Feed\" href=\"%satom.xml\" />\n", relpath);
  333   335 	if (stylesheet[0])
  334   336 		fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />\n", stylesheet);
  335    -1 	fputs("</head>\n<body>\n<table><tr><td>", fp);
   -1   337 	fputs("</head>\n", fp);
   -1   338 	fputs("<body>\n", fp);
   -1   339 	fputs("<header>\n", fp);
  336   340 	if (logo[0])
  337    -1 		fprintf(fp, "<a href=\"../%s\"><img src=\"%s\" alt=\"\" width=\"32\" height=\"32\" /></a>",
  338    -1 						relpath, logo);
  339    -1 	fputs("</td><td><h1>", fp);
   -1   341 		fprintf(fp, "<a href=\"%s..\"><img src=\"%s\" alt=\"\" width=\"32\" height=\"32\" /></a>",
   -1   342 			relpath, logo);
   -1   343 	fputs("<div>\n", fp);
   -1   344 	fputs("<h1>", fp);
  340   345 	xmlencode(fp, reponame, strlen(reponame));
  341    -1 	fputs("</h1><span class=\"desc\">", fp);
  342    -1 	xmlencode(fp, description, strlen(description));
  343    -1 	fputs("</span></td></tr>", fp);
   -1   346 	fputs("</h1>\n", fp);
   -1   347 	if (description[0]) {
   -1   348 		fputs("<div class=\"desc\">", fp);
   -1   349 		xmlencode(fp, description, strlen(description));
   -1   350 		fputs("</div>", fp);
   -1   351 	}
  344   352 	if (cloneurl[0]) {
  345    -1 		fputs("<tr class=\"url\"><td></td><td>git clone <a href=\"", fp);
   -1   353 		fputs("<div class=\"cloneurl\">git clone ", fp);
  346   354 		xmlencode(fp, cloneurl, strlen(cloneurl));
  347    -1 		fputs("\">", fp);
  348    -1 		xmlencode(fp, cloneurl, strlen(cloneurl));
  349    -1 		fputs("</a></td></tr>", fp);
   -1   355 		xmlencode(fp, reponame, strlen(reponame));
   -1   356 		fputs("</div>\n", fp);
  350   357 	}
  351    -1 	fputs("<tr><td></td><td>\n", fp);
  352    -1 	fprintf(fp, "<a href=\"%sfiles.html\">Files</a> | ", relpath);
  353    -1 	fprintf(fp, "<a href=\"%slog.html\">Log</a>", relpath);
  354    -1 	fputs("</td></tr></table>\n<hr/>\n<div id=\"content\">\n", fp);
   -1   358 	fputs("<nav>\n", fp);
   -1   359 	fprintf(fp, "<a href=\"%s.\">Files</a> |\n", relpath);
   -1   360 	fprintf(fp, "<a href=\"%slog.html\">Log</a>\n", relpath);
   -1   361 	fputs("</nav>\n", fp);
   -1   362 	fputs("</div>\n", fp);
   -1   363 	fputs("</header>\n", fp);
   -1   364 	fputs("<hr/>\n", fp);
   -1   365 	fputs("<main id=\"content\">\n", fp);
  355   366 }
  356   367 
  357   368 void
  358   369 write_footer(FILE *fp)
  359   370 {
  360    -1 	fputs("</div>\n</body>\n</html>\n", fp);
   -1   371 	fputs("</main>\n</body>\n</html>\n", fp);
  361   372 }
  362   373 
  363   374 void
@@ -428,20 +439,24 @@ write_commit_file(FILE *fp, struct deltainfo *di, size_t i)
  428   439 	const git_diff_hunk *hunk;
  429   440 	const git_diff_line *line;
  430   441 	size_t nhunks, nhunklines, j, k;
   -1   442 	const char *tag;
  431   443 
  432   444 	delta = git_patch_get_delta(di->patch);
  433   445 	nhunks = git_patch_num_hunks(di->patch);
  434   446 
  435   447 	fprintf(fp, "<h2 id=\"h%zu\">\n", i);
  436    -1 	fprintf(fp, "<b>diff --git a/<a id=\"h%zu\" href=\"%sfile/", i, relpath);
   -1   448 	fputs("diff --git\n", fp);
   -1   449 	fprintf(fp, "a/<a href=\"%sblob/", relpath);
  437   450 	xmlencode(fp, delta->old_file.path, strlen(delta->old_file.path));
  438    -1 	fputs(".html\">", fp);
   -1   451 	fputs("\">", fp);
  439   452 	xmlencode(fp, delta->old_file.path, strlen(delta->old_file.path));
  440    -1 	fprintf(fp, "</a> b/<a href=\"%sfile/", relpath);
   -1   453 	fputs("</a>\n", fp);
   -1   454 	fprintf(fp, "b/<a href=\"%sblob/", relpath);
  441   455 	xmlencode(fp, delta->new_file.path, strlen(delta->new_file.path));
  442    -1 	fprintf(fp, ".html\">");
   -1   456 	fputs("\">", fp);
  443   457 	xmlencode(fp, delta->new_file.path, strlen(delta->new_file.path));
  444    -1 	fprintf(fp, "</a></b>\n");
   -1   458 	fputs("</a>\n", fp);
   -1   459 	fputs("</h2>\n", fp);
  445   460 
  446   461 	if (delta->flags & GIT_DIFF_FLAG_BINARY) {
  447   462 		fputs("Binary files differ.\n", fp);
@@ -451,6 +466,7 @@ write_commit_file(FILE *fp, struct deltainfo *di, size_t i)
  451   466 	if (nhunks == 0)
  452   467 		return;
  453   468 
   -1   469 	fputs("<pre class=\"diff\">\n", fp);
  454   470 	for (j = 0; j < nhunks; j++) {
  455   471 		if (git_patch_get_hunk(&hunk, &nhunklines, di->patch, j))
  456   472 			break;
@@ -460,19 +476,15 @@ write_commit_file(FILE *fp, struct deltainfo *di, size_t i)
  460   476 		for (k = 0; k < nhunklines; k++) {
  461   477 			if (git_patch_get_line_in_hunk(&line, di->patch, j, k))
  462   478 				break;
  463    -1 			if (line->old_lineno == -1)
  464    -1 				fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" id=\"h%zu-%zu-%zu\" class=\"i\">+",
  465    -1 					i, j, k, i, j, k);
  466    -1 			else if (line->new_lineno == -1)
  467    -1 				fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" id=\"h%zu-%zu-%zu\" class=\"d\">-",
  468    -1 					i, j, k, i, j, k);
  469    -1 			else
  470    -1 				fputc(' ', fp);
  471    -1 			xmlencode(fp, line->content, line->content_len);
  472    -1 			if (line->old_lineno == -1 || line->new_lineno == -1)
  473    -1 				fputs("</a>", fp);
   -1   479 			tag = line->old_lineno == -1 ? "ins" : line->new_lineno == -1 ? "del" : "span";
   -1   480 			fprintf(fp, "<%s class=\"line\" id=\"h%zu-%zu-%zu\">", tag, i, j, k);
   -1   481 			fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" tabindex=\"-1\">%5i %5i</a> ",
   -1   482 				i, j, k, line->old_lineno, line->new_lineno);
   -1   483 			xmlencode(fp, line->content, line->content_len - 1);
   -1   484 			fprintf(fp, "</%s>\n", tag);
  474   485 		}
  475   486 	}
   -1   487 	fputs("</pre>\n", fp);
  476   488 }
  477   489 
  478   490 void
@@ -481,28 +493,28 @@ write_commit(FILE *fp, struct commitinfo *ci)
  481   493 	size_t i;
  482   494 	struct commitstats *cs = commitinfo_getstats(ci);
  483   495 
  484    -1 	fprintf(fp, "<b>commit</b> <a href=\"%scommit/%s.html\">%s</a>\n",
  485    -1 		relpath, ci->oid, ci->oid);
  486    -1 
   -1   496 	fputs("<dl>\n", fp);
   -1   497 	fprintf(fp, "<dt>commit</dt><dd><a href=\"%scommit/%s.html\">%s</a></dd>\n",
   -1   498 			relpath, ci->oid, ci->oid);
  487   499 	if (ci->parentoid[0])
  488    -1 		fprintf(fp, "<b>parent</b> <a href=\"%scommit/%s.html\">%s</a>\n",
   -1   500 		fprintf(fp, "<dt>parent</dt><dd><a href=\"%scommit/%s.html\">%s</a></dd>\n",
  489   501 			relpath, ci->parentoid, ci->parentoid);
  490    -1 
  491   502 	if (ci->author) {
  492    -1 		fputs("<b>Author:</b> ", fp);
   -1   503 		fputs("<dt>Author</dt><dd>", fp);
  493   504 		xmlencode(fp, ci->author->name, strlen(ci->author->name));
  494   505 		fputs(" &lt;<a href=\"mailto:", fp);
  495   506 		xmlencode(fp, ci->author->email, strlen(ci->author->email));
  496   507 		fputs("\">", fp);
  497   508 		xmlencode(fp, ci->author->email, strlen(ci->author->email));
  498    -1 		fputs("</a>&gt;\n<b>Date:</b>   ", fp);
   -1   509 		fputs("</a>&gt;</dd>\n<dt>Date</dt><dd>", fp);
  499   510 		printtimeshort(fp, &(ci->author->when));
  500    -1 		fputc('\n', fp);
   -1   511 		fputs("</dd>\n", fp);
  501   512 	}
   -1   513 	fputs("</dl>\n", fp);
  502   514 	if (ci->msg) {
  503    -1 		fputc('\n', fp);
   -1   515 		fputs("<pre>", fp);
  504   516 		xmlencode(fp, ci->msg, strlen(ci->msg));
  505    -1 		fputc('\n', fp);
   -1   517 		fputs("</pre>\n", fp);
  506   518 	}
  507   519 
  508   520 	if (!cs->deltas)
@@ -523,15 +535,15 @@ write_commit(FILE *fp, struct commitinfo *ci)
  523   535 	for (i = 0; i < cs->ndeltas; i++) {
  524   536 		write_commit_statline(fp, cs->deltas[i], i);
  525   537 	}
  526    -1 	fprintf(fp, "</table></pre><pre>%zu file%s changed, %zu insertion%s(+), %zu deletion%s(-)\n",
  527    -1 		cs->ndeltas,  cs->ndeltas  == 1 ? "" : "s",
  528    -1 		cs->addcount, cs->addcount == 1 ? "" : "s",
  529    -1 		cs->delcount, cs->delcount == 1 ? "" : "s");
  530   538 
  531   539 	fputs("</table>\n", fp);
  532   540 	fputs("<p>", fp);
   -1   541 	fprintf(fp, "<p>%zu file%s changed, %zu insertion%s, %zu deletion%s</p>\n",
   -1   542 		cs->ndeltas, cs->ndeltas == 1 ? "" : "s",
   -1   543 		cs->addcount, cs->addcount  == 1 ? "" : "s",
   -1   544 		cs->delcount, cs->delcount  == 1 ? "" : "s");
  533   545 	fputs("</p>\n", fp);
  534    -1 	fputs("<hr/>", fp);
   -1   546 	fputs("<hr/>\n", fp);
  535   547 
  536   548 	for (i = 0; i < cs->ndeltas; i++) {
  537   549 		write_commit_file(fp, cs->deltas[i], i);
@@ -555,14 +567,14 @@ void
  555   567 write_log_line(FILE *fp, struct commitinfo *ci)
  556   568 {
  557   569 	fputs("<tr><td>", fp);
  558    -1 	if (ci->author)
  559    -1 		printtimeshort(fp, &(ci->author->when));
  560    -1 	fputs("</td><td>", fp);
  561    -1 	if (ci->summary) {
   -1   570 	if (ci->author) {
  562   571 		fprintf(fp, "<a href=\"%scommit/%s.html\">", relpath, ci->oid);
  563    -1 		xmlencode(fp, ci->summary, strlen(ci->summary));
   -1   572 		printtimeshort(fp, &(ci->author->when));
  564   573 		fputs("</a>", fp);
  565   574 	}
   -1   575 	fputs("</td><td class=\"text\">", fp);
   -1   576 	if (ci->summary)
   -1   577 		xmlencode(fp, ci->summary, strlen(ci->summary));
  566   578 	fputs("</td><td>", fp);
  567   579 	if (ci->author)
  568   580 		xmlencode(fp, ci->author->name, strlen(ci->author->name));
@@ -660,22 +672,21 @@ copy_blob(git_object *obj, const char *fpath)
  660   672 void
  661   673 write_files_header(FILE *fp)
  662   674 {
  663    -1 	fputs("<table id=\"files\"><thead>\n<tr>"
  664    -1 		"<td><b>Name</b></td>"
  665    -1 		"<td class=\"num\" align=\"right\"><b>Size</b></td>"
  666    -1 		"</tr>\n</thead><tbody>\n", fp);
   -1   675 	fputs("<table id=\"files\">\n", fp);
   -1   676 	fputs("<thead>\n", fp);
   -1   677 	fputs("<tr><th>Name</th><th class=\"num\">Size</th></tr>\n", fp);
   -1   678 	fputs("</thead>\n", fp);
   -1   679 	fputs("<tbody>\n", fp);
  667   680 }
  668   681 
  669   682 void
  670   683 write_files_line(FILE *fp, char *entrypath, char *filepath, uintmax_t size)
  671   684 {
  672    -1 	fprintf(fp, "<tr><td><a href=\"%s", relpath);
   -1   685 	fputs("<tr><td><a href=\"", fp);
  673   686 	xmlencode(fp, filepath, strlen(filepath));
  674   687 	fputs("\">", fp);
  675   688 	xmlencode(fp, entrypath, strlen(entrypath));
  676    -1 	fputs("</a></td><td class=\"num\" align=\"right\">", fp);
  677    -1 	fprintf(fp, "%juB", (uintmax_t)size);
  678    -1 	fputs("</td></tr>\n", fp);
   -1   689 	fprintf(fp, "</a></td><td class=\"num\">%juB</td></tr>\n", size);
  679   690 }
  680   691 
  681   692 void