stagit

Personal stagit fork
git clone git://git.alexwennerberg.com/stagit
Log | Files | Refs | README | LICENSE

commit 362577ba1fb7a0b538717f3c25e4d3659eb423ae
parent 1ce89a949a7373ffcf214539572c33afb9d7b247
Author: Armaan Bhojwani <me@armaanb.net>
Date:   Sun, 18 Apr 2021 13:21:54 -0400

Add desc file and fix table madness

Diffstat:
Mman/stagit-index.1 | 2++
Mresources/style.css | 19+++++++++++--------
Msrc/stagit-index.c | 36++++++++++++++++++++++++++++++++----
Msrc/stagit.c | 17++++++++---------
4 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/man/stagit-index.1 b/man/stagit-index.1 @@ -33,6 +33,8 @@ For changing the style of the page you can use the following files: favicon image. .It logo.png 32x32 logo. +.It desc, desc.md +A plaintext or markdown description to include on the index. .It style.css CSS stylesheet. .El diff --git a/resources/style.css b/resources/style.css @@ -70,6 +70,7 @@ table td { .desc { color: #555; + margin: 0.5em 0; } hr { @@ -100,17 +101,19 @@ pre a.d:hover { text-decoration: none; } -.url td:nth-child(2) { - padding-top: 0.2em; - padding-bottom: 0.9em; -} - -.url td:nth-child(2) span { - padding: 1px 5px; +.clone { + padding: 0.25em 0.5em; border: 1px solid #555; border-radius: 5px; + width: max-content; + margin: 0.5em 0; } -.url td:nth-child(2) span a { +.clone a { color: #555; } + +.logo { + float: left; + padding-right: 1em; +} diff --git a/src/stagit-index.c b/src/stagit-index.c @@ -8,6 +8,10 @@ #include <git2.h> +#ifdef HAS_CMARK +#include <cmark-gfm.h> +#endif + #include "cp.h" static git_repository *repo; @@ -75,11 +79,35 @@ writeheader(char *path) fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/png\" href=\"%sfavicon.png\" />\n", relpath); fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", relpath); fputs("</head>\n<body>\n", fp); - fprintf(fp, "<table>\n<tr><td><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></td>\n" - "<td><h1>", relpath); + fprintf(fp, "<img src=\"%slogo.png\" class=\"logo\" width=\"32\" height=\"32\" /></td>\n" + "<h1>", relpath); xmlencode(fp, description, strlen(description)); - fputs("</h1></td></tr><tr><td></td><td>\n" - "</td></tr>\n</table>\n<hr/>\n<div id=\"content\">\n" + fputs("</h1>\n", fp); + + FILE *longdesc = fopen("desc.md", "r"); + if (longdesc == NULL) longdesc = fopen("desc", "r"); + if (longdesc != NULL) { + char c = fgetc(longdesc); +#ifdef HAS_CMARK + char buf[2048]; + while (c != EOF) { + strncat(buf, &c, 1); + c = fgetc(longdesc); + } + char *md = cmark_markdown_to_html(buf, strlen(buf), CMARK_OPT_DEFAULT); + fprintf(fp, md, relpath); + free(md); +#else + fputs("<p>\n", fp); + while (c != EOF) { + fprintf(fp, &c, relpath); + c = fgetc(longdesc); + } +#endif + } + fclose(longdesc); + + fputs("</p>\n<hr/>\n<div id=\"content\">\n" "<table id=\"index\"><thead>\n" "<tr><td><b>Name</b></td><td><b>Description</b></td><td><b>Owner</b></td>" "<td><b>Last commit</b></td></tr>" diff --git a/src/stagit.c b/src/stagit.c @@ -387,22 +387,21 @@ writeheader(FILE *fp, const char *title) name, relpath); fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", relpath); fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%ssyntax.css\" />\n", relpath); - fputs("</head>\n<body>\n<table><tr><td>", fp); - fprintf(fp, "<a href=\"../%s\"><img alt=\"Home\" src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>", + fputs("</head>\n<body>\n", fp); + fprintf(fp, "<a href=\"../%s\"><img class=\"logo\" src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>", relpath, relpath); - fputs("</td><td><h1>", fp); + fputs("<h1>", fp); xmlencode(fp, strippedname, strlen(strippedname)); - fputs("</h1></td></tr><tr><td></td><td><span class=\"desc\">", fp); + fputs("</h1><p class=\"desc\">", fp); xmlencode(fp, description, strlen(description)); - fputs("</span></td></tr>", fp); + fputs("</p>", fp); if (cloneurl[0]) { - fputs("<tr class=\"url\"><td></td><td><span class=\"clone\">git clone <a href=\"", fp); + fputs("<p class=\"clone\">git clone <a href=\"", fp); xmlencode(fp, cloneurl, strlen(cloneurl)); fputs("\">", fp); xmlencode(fp, cloneurl, strlen(cloneurl)); - fputs("</a></span></td></tr>", fp); + fputs("</a></p>", fp); } - fputs("<tr><td></td><td>\n", fp); fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", relpath); fprintf(fp, "<a href=\"%sfiles.html\">Files</a> | ", relpath); fprintf(fp, "<a href=\"%srefs.html\">Refs</a>", relpath); @@ -417,7 +416,7 @@ writeheader(FILE *fp, const char *title) relpath, license); fprintf(fp, " | <a href=\"%s%s.tar.gz\">Download</a>", relpath, strippedname); - fputs("</td></tr></table>\n<hr/>\n<div id=\"content\">\n", fp); + fputs("<hr/>\n<div id=\"content\">\n", fp); } void