stagit

[fork]
git clone git://bvnf.space/stagit.git
Log | Files | Refs | README | LICENSE

commit 3e5bc183d10d513934dc9d4fbde4668b7dac44e0
parent 13a569440b4fec162612d06bdfc79562b2f81afc
Author: aabacchus <ben@bvnf.space>
Date:   Thu,  3 Mar 2022 01:38:35 +0000

stagit-index: allow embedding custom elements onto index page

Diffstat:
MREADME | 2+-
Mstagit-index.1 | 11++++++++++-
Mstagit-index.c | 52++++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 55 insertions(+), 10 deletions(-)

diff --git a/README b/README @@ -152,7 +152,7 @@ Features - Detect submodules (.gitmodules file) from HEAD and link it as a webpage. - Atom feed of the commit log (atom.xml). - Atom feed of the tags/refs (tags.xml). -- Make index page for multiple repositories with stagit-index. +- Make index page for multiple repositories with stagit-index with custom elements. - After generating the pages (relatively slow) serving the files is very fast, simple and requires little resources (because the content is static), only a HTTP file server is required. diff --git a/stagit-index.1 b/stagit-index.1 @@ -1,4 +1,4 @@ -.Dd August 2, 2021 +.Dd March 3, 2022 .Dt STAGIT-INDEX 1 .Os .Sh NAME @@ -6,6 +6,8 @@ .Nd static git index page generator .Sh SYNOPSIS .Nm +.Op Fl p Ar pre_body +.Op Fl P Ar post_body .Op Ar repodir... .Sh DESCRIPTION .Nm @@ -15,6 +17,12 @@ The repos in the index are in the same order as the arguments .Ar repodir specified. .Pp +The +.Ar pre_body +and +.Ar post_body +arguments may be the names of HTML files to be inserted before and after the table, respectively. +.Pp The basename of the directory is used as the repository name. The suffix ".git" is removed from the basename, this suffix is commonly used for "bare" repos. @@ -40,6 +48,7 @@ CSS stylesheet. .Bd -literal cd htmlroot stagit-index path/to/gitrepo1 path/to/gitrepo2 > index.html +stagit-index -p myheader.html path/to/gitrepo1 > home.html .Ed .Sh SEE ALSO .Xr stagit 1 diff --git a/stagit-index.c b/stagit-index.c @@ -93,7 +93,23 @@ printtimeshort(FILE *fp, const git_time *intime) } void -writeheader(FILE *fp) +writecustom(char *fn, FILE *fp) { + if (fn == NULL) + return; + FILE *from = fopen(fn, "r"); + if (from == NULL) { + perror(fn); + return; + } + size_t n = 0; + char buf[100] = {'\0'}; + while ((n = fread(buf, 1, 100, from)) > 0) + fwrite(buf, 1, n, fp); + fclose(from); +} + +void +writeheader(char *fn, FILE *fp) { fputs("<!DOCTYPE html>\n" "<html>\n<head>\n" @@ -104,6 +120,7 @@ writeheader(FILE *fp) 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); + writecustom(fn, fp); fprintf(fp, "<table>\n<tr><td><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></td>\n" "<td><span class=\"desc\">", relpath); xmlencode(fp, description, strlen(description)); @@ -116,9 +133,11 @@ writeheader(FILE *fp) } void -writefooter(FILE *fp) +writefooter(char *fn, FILE *fp) { - fputs("</tbody>\n</table>\n</div>\n</body>\n</html>\n", fp); + fputs("</tbody>\n</table>\n</div>\n", fp); + writecustom(fn, fp); + fputs("</body>\n</html>\n", fp); } int @@ -177,9 +196,26 @@ main(int argc, char *argv[]) char path[PATH_MAX], repodirabs[PATH_MAX + 1]; const char *repodir; int i, ret = 0; + char *prefile, *postfile; + prefile = postfile = NULL; + + int c; + while ((c = getopt(argc, argv, "P:p:")) != -1) { + switch (c) { + case 'P': + postfile = optarg; + break; + case 'p': + prefile = optarg; + break; + default: + fprintf(stderr, "%s [-p pre_body] [-P post_body] [repodir...]\n", argv[0]); + return 1; + } + } - if (argc < 2) { - fprintf(stderr, "usage: %s [repodir...]\n", argv[0]); + if (argc - optind < 1) { + fprintf(stderr, "usage: %s [-p pre_body] [-P post_body] [repodir...]\n", argv[0]); return 1; } @@ -196,9 +232,9 @@ main(int argc, char *argv[]) err(1, "pledge"); #endif - writeheader(stdout); + writeheader(prefile, stdout); - for (i = 1; i < argc; i++) { + for (i = optind; i < argc; i++) { repodir = argv[i]; if (!realpath(repodir, repodirabs)) err(1, "realpath"); @@ -246,7 +282,7 @@ main(int argc, char *argv[]) } writelog(stdout); } - writefooter(stdout); + writefooter(postfile, stdout); /* cleanup */ git_repository_free(repo);