sgw | Static git web (fork of stagit) |
| download: https://git.y1.nz/archives/sgw.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 2976b0675172e5a69caffeb120a14f885bc2309d parent de7a3cdf912037e812e0ca8d31fea51ce6c20770 Author: Emma Weaver <emma@waeaves.com> Date: Wed, 17 Jun 2026 20:06:02 -0400 Added category headers Diffstat:
| M | config.h | 9 | +++++---- |
| M | index.c | 27 | +++++++++++++++++---------- |
| M | main.c | 3 | +++ |
| M | opt.c | 30 | +++++++++++++++++++++++------- |
| M | opt.h | 10 | ++++++---- |
| M | sgw.1 | 14 | ++++++++++++-- |
6 files changed, 66 insertions(+), 27 deletions(-)
diff --git a/config.h b/config.h @@ -18,12 +18,13 @@ #define INDEX_DEST "index.html" /* what projects' titles link to */ #define INDEX_REPO_LINK readme == NULL ? "files.html" : "files/%s.html", readme -/* title of the index page */ -#define INDEX_TITLE "Emma's Repositories" +#define INDEX_TITLE "Emma's Code" /* shown at the top of index page */ -#define INDEX_HEADER "<span>" \ +#define INDEX_HEADER "<p>" \ "<a href=\"https://y1.nz\">y1.nz</a>" \ -"</span>" +"</p> <p>" \ + "<b>GIT.Y1.NZ</b> - make yourself at home." \ +"</p>" /********* repository page configurations ************/ /* the relative path to save each repository's page to */ diff --git a/index.c b/index.c @@ -10,7 +10,7 @@ #include "config.h" -// TODO extract these to a shared location (main.h?) +// TODO extract these to a shared location (index.h) #define SPUTF(f, s) fputs((s), (f)) #define put_xml(fp, s) put_xml_len((fp), (s), strlen(s)) @@ -42,15 +42,9 @@ put_index_header(FILE *fp) "</head>" "\n" "<body>" "\n" ); fprintf(fp, INDEX_HEADER); - SPUTF(fp, "<table><tbody>" "<tr><td>" "<h1>"); - put_xml(fp, INDEX_TITLE); SPUTF( fp, - "</h1>" "</td></tr>" "</tbody>" "</table>" "\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>Last commit</b></td></tr>" - "</thead><tbody>" "\n" + "<div id=\"content\">" "\n" ); } @@ -59,11 +53,25 @@ put_index_footer(FILE *fp) { SPUTF( fp, - "</tbody>" "\n" "</table>" "\n" "</div>" "\n" + "</tbody></table>" "\n" "</div>" "\n" "</body>" "\n" "</html>" "\n" ); } +void +put_index_category(FILE *fp, const char *category, int first) +{ + if (!first) SPUTF(fp, "</tbody></table><br>" "\n"); + + SPUTF(fp, "<table><tbody>" "\n"); + + if (category != NULL) { + SPUTF(fp, "<tr></tr>" "<tr><td colspan=3><b>"); + put_xml(fp, category); + SPUTF(fp, "</b></td></tr>" "\n"); + } +} + int put_index_log( FILE *fp, @@ -89,7 +97,6 @@ put_index_log( author = git_commit_author(commit); - // TODO make this link reflect the repo page configuration SPUTF(fp, "<tr><td><a href=\""); put_absolute_path(fp, ""); fprintf(fp, INDEX_REPO_LINK); diff --git a/main.c b/main.c @@ -100,6 +100,7 @@ static char index_fname[255] = "index.html"; void find_owner(); int put_index_log(FILE *fp, git_repository *repo, const char *description, const char *repo_name, const char *readme); void put_index_header(FILE *fp); +void put_index_category(FILE *fp, const char *category, int first); void put_index_footer(FILE *fp); void @@ -1857,6 +1858,8 @@ main(int argc, const char *argv[]) if (opt.index) begin_index(); for (i = 0; i < opt.repo_count; i++) { + if (opt.categories[i] != NULL) + put_index_category(index_fp, opt.categories[i], i == 0); result = write_repo_pages(opt.repo_dirs[i]); if(result > 0) return 1; } diff --git a/opt.c b/opt.c @@ -12,7 +12,7 @@ parse_opt(Opt *opt, const char *cur, const char *next) int index; char flag; - if (cur[0] != '-') return OPT_LAST; + if (cur[0] != '-') return OPT_REPO; for (index = 1;;) { flag = cur[index]; if (flag == '\0') break; @@ -22,7 +22,9 @@ parse_opt(Opt *opt, const char *cur, const char *next) case 'p': opt->pages = 1; break; case 'o': opt->out_dir = next; return OPT_SKIP; case 'b': opt->base_url = next; return OPT_SKIP; - case 'c': opt->cache = next; return OPT_SKIP; + case 'c': + opt->categories[opt->repo_count] = next; + return OPT_SKIP; default: ERROR("Unrecognized flag: -%c." "\n\n", flag); } @@ -46,6 +48,10 @@ parse_opts(Opt *opt, int argc, const char * argv[]) opt->pages = 0; opt->base_url = ""; opt->out_dir = ""; + opt->categories = malloc(MAX_REPOS * sizeof(char *)); + opt->repo_dirs = malloc(MAX_REPOS * sizeof(char *)); + + opt->categories[0] = NULL; for (index = 1;;) { cur = argv[index]; @@ -54,15 +60,25 @@ parse_opts(Opt *opt, int argc, const char * argv[]) switch (parse_opt(opt, cur, next)) { case OPT_SKIP: index++; break; case OPT_FAIL: return OPT_FAIL; - case OPT_LAST: - opt->repo_dirs = argv + index; - opt->repo_count = argc - index; - return OPT_GOOD; + case OPT_REPO: + opt->repo_dirs[opt->repo_count] = cur; + opt->repo_count++; + opt->categories[opt->repo_count] = NULL; + break; } index++; if(index >= argc) break; } - ERROR("Must specify at least one repository." "\n\n"); + if (opt->repo_count == 0) + ERROR("Must specify at least one repository." "\n\n"); + + return OPT_GOOD; } +void +free_opts(Opt *opt) +{ + free(opt->categories); + free(opt->repo_dirs); +} diff --git a/opt.h b/opt.h @@ -1,18 +1,20 @@ +#define MAX_REPOS 200 + #define FLAG_NONE 0 #define OPT_GOOD 0 #define OPT_FAIL 1 #define OPT_SKIP 2 -#define OPT_LAST 3 +#define OPT_REPO 3 #define ERROR(...) { fprintf(stderr, __VA_ARGS__); return OPT_FAIL; } #define USAGE \ -"Usage: %s [-i] [-p] [-o DIR] [-b URL] [-c DIR] REPO [REPO2 [...]]" "\n" \ +"Usage: %s [-i] [-p] [-o DIR] [-b URL] [-c CATEGORY] REPO [REPO2 [...]]" "\n" \ " -i: generate index file" "\n" \ " -p: generate repository pages" "\n" \ " -o: specify output dir" "\n" \ " -b: specify base url" "\n" \ -" -c: specify cache dir" "\n" +" -c: add index category (multiple allowed, between repos)" "\n" #define PRINT_USAGE(argv0) fprintf(stderr, USAGE, argv0); @@ -21,12 +23,12 @@ typedef struct _ { int index; /* 0 or 1 */ int pages; /* 0 or 1 */ - const char *cache; const char *out_dir; const char *base_url; int repo_count; const char **repo_dirs; + const char **categories; } Opt; int parse_opts(Opt *opt, int argc, const char *argv[]); diff --git a/sgw.1 b/sgw.1 @@ -10,8 +10,9 @@ .Op Fl p .Op Fl o Ar outdir .Op Fl b Ar baseurl +.Op Fl c Ar category .Ar repo -.Op Ar repo2 Op ... +.Op Ar repo2 ... .Sh DESCRIPTION .Nm writes a webpage consisting of index and repository @@ -24,7 +25,9 @@ are as follows: .Bl -tag -width Ds .It Fl i If present, generate an index page. The exact file this page is -saved to is defined by config.h at compile time. +saved to is defined by config.h at compile time. The index page +lists the specified repositories, sorted by most-to-least recent +commit in HEAD. .It Fl p If present, generate the specified repositories' pages. .It Fl o Ar outdir @@ -37,6 +40,13 @@ Links within the generated webpages include this path, to allow the webpage to be served from the .Ar baseurl subdirectory. +.It Fl c Ar category +This argument may only be used with +.Ar i , +and may be used multiple times. It allows the specification +of category headings, displayed on the index page. The +repositories are shown on the index page under the most recently +specified category. Each category is sorted independently. .El .Pp The program will return with a failing status if neither of
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.