git.y1.nz

sgw

Static git web (fork of stagit)
download: https://git.y1.nz/archives/sgw.tar.gz
README | Files | Log | Refs | LICENSE

commit 975cb19e36676e3654c66cdd1869a3e06feeb3bb
parent 3d3e4e3456fa762aaa84db25f8663ba387e1caa3
Author: Emma Weaver <emma@y1.nz>
Date:   Tue,  4 Aug 2026 08:19:36 -0500

Added repo index (/repo/index.html) pages

Diffstat:
MMakefile4++--
Mconfig.h26+++++++++++++++++---------
Mindex.c4+---
Mmain.c37+++++++++++++++++++++++++++++++------
4 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile @@ -19,7 +19,7 @@ index.o: index.c config.h config.mk clean: rm -f opt.o files.o index.o sgw -install: sgw config.mk +install: sgw mkdir -p $(PREFIX)/bin cp -f sgw $(PREFIX)/bin chmod 755 $(PREFIX)/bin/sgw @@ -27,7 +27,7 @@ install: sgw config.mk sed "s/VERSION/$(VERSION)/g" < sgw.1 > $(MANPREFIX)/man1/sgw.1 chmod 644 $(MANPREFIX)/man1/sgw.1 -uninstall: config.mk +uninstall: rm -f $(PREFIX)/bin/sgw rm -f $(MANPREFIX)/man1/sgw.1 diff --git a/config.h b/config.h @@ -3,23 +3,26 @@ /********* global configurations ************/ /* url of the stylesheet */ #define STYLE_HREF "/style.css" + /* whether to generate a page for each dir in a repo */ #define DIR_PAGES 1 + /* where to truncate the commit history */ #define MAX_COMMITS 10 + /* where to check for license files */ #define LICENSE_FILES "HEAD:LICENSE", "HEAD:LICENSE.md", \ "HEAD:LICENSE.txt", "HEAD:COPYING" /* where to check for readme files */ #define README_FILES "HEAD:README", "HEAD:README.md" -/********* index page configurations ************/ +/********* index (of repos) page configurations ************/ /* the relative path to save to index page to */ #define INDEX_DEST "index.html" -/* what projects' titles link to */ -#define INDEX_REPO_LINK data->readme == NULL ? "files.html" : "files/%s.html", data->readme + /* title of the index page */ #define INDEX_TITLE "Emma's Repositories" + /* shown at the top of index page */ #define INDEX_HEADER "<span>" \ "<a href=\"https://y1.nz\">y1.nz</a>" \ @@ -28,14 +31,19 @@ /********* repository page configurations ************/ /* the relative path to save each repository's page to */ #define PAGE_DEST "%s", data->repo_name + /* shown at the top of each repo page */ #define PAGE_HEADER "<span> <a href=\"/\">git.y1.nz</a> </span>" + +/* shown at the top of each repo page */ +#define REPO_INDEX_CONTENTS "<p><i>" \ + "These pages are intended as an accessible preview of the " \ + "repository. To get a fuller picture, download the source " \ + "code." \ +"</i></p>" + /* label shown before download/clone link */ #define PAGE_ACCESS_LABEL "download" -/* shown at the bottom of each repo page */ -#define PAGE_FOOTER "<p><i>" \ - "This webpage is intended to be an accessible preview of this " \ - "repository. To get a fuller picture, clone it and use the " \ - "git CLI." \ -"</i></p>" +/* shown at the bottom of each repo page */ +#define PAGE_FOOTER "&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;" diff --git a/index.c b/index.c @@ -88,10 +88,8 @@ 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); + put_absolute_path(fp, "index.html"); SPUTF(fp, "\">"); put_xml(fp, data->repo_name); SPUTF(fp, "</a></td><td>"); diff --git a/main.c b/main.c @@ -126,8 +126,6 @@ get_index_page_path(char *buf, size_t buf_size, const char *dir, char *name) if (chars < 0 || (size_t) (index += chars) >= buf_size) goto page_path_err; - printf("Index page path: %s" "\n", buf); - return; page_path_err: @@ -972,6 +970,15 @@ put_log_html(FILE *fp) } void +put_repo_index_html(FILE *fp) +{ + put_header(fp, "Repository Index"); + + fprintf(fp, REPO_INDEX_CONTENTS); +} + + +void print_commit_atom(FILE *fp, struct CommitInfo *ci, const char *tag) { fputs("<entry>\n", fp); @@ -1546,6 +1553,21 @@ put_refs(FILE *fp) } void +write_repo_index_page() +{ + FILE *fp; + char fname[PATH_MAX]; + + get_page_path(fname, sizeof(fname), opt.out_dir, "index.html"); + fp = fopen_w(fname); + + put_repo_index_html(fp); + + check_file_error(fp, fname, 'w'); + fclose(fp); +} + +void write_log_page() { FILE *fp; @@ -1618,6 +1640,7 @@ write_repo_pages(const char* dir) } if (opt.pages) { + write_repo_index_page(data); write_log_page(data); walk_git_tree(data); write_refs_page(data); @@ -1633,17 +1656,15 @@ write_repo_pages(const char* dir) void begin_index() { - printf("Start index header" "\n"); + printf("Writing index page..." "\n"); get_index_page_path( index_fname, sizeof(index_fname), opt.out_dir, INDEX_DEST ); - printf("Mid index header" "\n"); index_fp = fopen_w(index_fname); put_index_header(index_fp); - printf("Finish index header" "\n"); } void @@ -1685,18 +1706,22 @@ main(int argc, const char *argv[]) return 1; } + printf("Opening repository..." "\n"); init_lib_git(); /* actually write all the pages! */ if (opt.index) begin_index(); + printf("Writing repositories..." "\n"); for (i = 0; i < opt.repo_count; i++) { - printf("REpo %d" "\n", i); + printf("%d/%d...", i+1, opt.repo_count); fflush(stdout); result = write_repo_pages(opt.repo_dirs[i]); if(result > 0) return 1; } + printf("\n"); if (opt.index) end_index(); git_libgit2_shutdown(); + printf("All done!" "\n"); return 0; }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.