diff options
author | Oscar Benedito <oscar@oscarbenedito.com> | 2020-07-31 16:56:52 +0200 |
---|---|---|
committer | Oscar Benedito <oscar@oscarbenedito.com> | 2020-08-11 01:38:01 +0200 |
commit | 1fdbc7e8ef4025e50678261ca670daca85ac298c (patch) | |
tree | 3b0862499e130b2e266877a6da8d4dd1ba2ea305 /stagit.c | |
parent | 0a81a2fac1b84fb5ee9870fafb3d62975eaf0f96 (diff) |
Add about page for repos with REAMDE
This commits adds a new dependency: md4c (https://github.com/mity/md4c).
Now stagit will generate an about page for each repo with a README,
converting it to HTML if it is a Markdown file.
Diffstat (limited to 'stagit.c')
-rw-r--r-- | stagit.c | 37 |
1 files changed, 33 insertions, 4 deletions
@@ -13,6 +13,7 @@ #include <unistd.h> #include <git2.h> +#include <md4c-html.h> #include "compat.h" @@ -375,15 +376,14 @@ writeheader(FILE *fp, const char *title) fputs("</a></td></tr>", fp); } fputs("<tr><td></td><td>\n", fp); + if (readme) + fprintf(fp, "<a href=\"%sabout.html\">About</a> | ", relpath); 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); if (submodules) fprintf(fp, " | <a href=\"%sfile/%s.html\">Submodules</a>", relpath, submodules); - if (readme) - fprintf(fp, " | <a href=\"%sfile/%s.html\">README</a>", - relpath, readme); if (license) fprintf(fp, " | <a href=\"%sfile/%s.html\">LICENSE</a>", relpath, license); @@ -1064,6 +1064,12 @@ usage(char *argv0) exit(1); } +void +process_output_md(const char* text, unsigned int size, void* fp) +{ + fprintf((FILE *)fp, "%.*s", size, text); +} + int main(int argc, char *argv[]) { @@ -1074,7 +1080,7 @@ main(int argc, char *argv[]) char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p; char tmppath[64] = "cache.XXXXXXXXXXXX", buf[BUFSIZ]; size_t n; - int i, fd; + int i, fd, r; for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { @@ -1190,6 +1196,7 @@ main(int argc, char *argv[]) if (!git_revparse_single(&obj, repo, readmefiles[i]) && git_object_type(obj) == GIT_OBJ_BLOB) readme = readmefiles[i] + strlen("HEAD:"); + r = i; git_object_free(obj); } @@ -1198,6 +1205,28 @@ main(int argc, char *argv[]) submodules = ".gitmodules"; git_object_free(obj); + /* about page */ + if (readme) { + fp = efopen("about.html", "w"); + writeheader(fp, "About"); + git_revparse_single(&obj, repo, readmefiles[r]); + const char *s = git_blob_rawcontent((git_blob *)obj); + if (r == 1) { + git_off_t len = git_blob_rawsize((git_blob *)obj); + fputs("<div class=\"md\">", fp); + if (md_html(s, len, process_output_md, fp, MD_FLAG_TABLES | MD_FLAG_TASKLISTS | + MD_FLAG_PERMISSIVEEMAILAUTOLINKS | MD_FLAG_PERMISSIVEURLAUTOLINKS, 0)) + fprintf(stderr, "Error parsing markdown\n"); + fputs("</div>\n", fp); + } else { + fputs("<pre id=\"about\">", fp); + xmlencode(fp, s, strlen(s)); + fputs("</pre>\n", fp); + } + writefooter(fp); + fclose(fp); + } + /* log for HEAD */ fp = efopen("log.html", "w"); relpath = ""; |