From 8f42a2ea6c961b6ea8002c8408503da5e09d713d Mon Sep 17 00:00:00 2001 From: Sunur Efe Vural Date: Mon, 27 Jan 2020 09:16:08 -0500 Subject: [PATCH] Remove html file extension from links. Based on the suggestions of "Cool URIs don't change"[1] remove the file extension from href attributes. For example, `href="file/README.html"` becomes `href="file/README"`. This does not change the actual file names. Therefore, the server should handle the appropriate rewrites. One can achieve this with a try_files` directive on a Nginx server. [1] --- stagit-index.c | 2 +- stagit.c | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/stagit-index.c b/stagit-index.c index 59a12d6..757f974 100644 --- a/stagit-index.c +++ b/stagit-index.c @@ -124,7 +124,7 @@ writelog(FILE *fp) fputs("", fp); + fputs("/log\">", fp); xmlencode(fp, stripped_name, strlen(stripped_name)); fputs("", fp); xmlencode(fp, description, strlen(description)); diff --git a/stagit.c b/stagit.c index dcac016..110fe06 100644 --- a/stagit.c +++ b/stagit.c @@ -371,17 +371,17 @@ writeheader(FILE *fp, const char *title) fputs("", fp); } fputs("\n", fp); - fprintf(fp, "Log | ", relpath); - fprintf(fp, "Files | ", relpath); - fprintf(fp, "Refs", relpath); + fprintf(fp, "Log | ", relpath); + fprintf(fp, "Files | ", relpath); + fprintf(fp, "Refs", relpath); if (submodules) - fprintf(fp, " | Submodules", + fprintf(fp, " | Submodules", relpath, submodules); if (readme) - fprintf(fp, " | README", + fprintf(fp, " | README", relpath, readme); if (license) - fprintf(fp, " | LICENSE", + fprintf(fp, " | LICENSE", relpath, license); fputs("\n
\n
\n", fp); } @@ -427,11 +427,11 @@ writeblobhtml(FILE *fp, const git_blob *blob) void printcommit(FILE *fp, struct commitinfo *ci) { - fprintf(fp, "commit %s\n", + fprintf(fp, "commit %s\n", relpath, ci->oid, ci->oid); if (ci->parentoid[0]) - fprintf(fp, "parent %s\n", + fprintf(fp, "parent %s\n", relpath, ci->parentoid, ci->parentoid); if (ci->author) { @@ -534,11 +534,11 @@ printshowfile(FILE *fp, struct commitinfo *ci) delta = git_patch_get_delta(patch); fprintf(fp, "diff --git a/old_file.path, strlen(delta->old_file.path)); - fputs(".html\">", fp); + fputs("\">", fp); xmlencode(fp, delta->old_file.path, strlen(delta->old_file.path)); fprintf(fp, " b/new_file.path, strlen(delta->new_file.path)); - fprintf(fp, ".html\">"); + fprintf(fp, "\">"); xmlencode(fp, delta->new_file.path, strlen(delta->new_file.path)); fprintf(fp, "\n"); @@ -584,7 +584,7 @@ writelogline(FILE *fp, struct commitinfo *ci) printtimeshort(fp, &(ci->author->when)); fputs("", fp); if (ci->summary) { - fprintf(fp, "", relpath, ci->oid); + fprintf(fp, "", relpath, ci->oid); xmlencode(fp, ci->summary, strlen(ci->summary)); fputs("", fp); } @@ -623,7 +623,7 @@ writelog(FILE *fp, const git_oid *oid) git_oid_tostr(oidstr, sizeof(oidstr), &id); r = snprintf(path, sizeof(path), "commit/%s.html", oidstr); if (r < 0 || (size_t)r >= sizeof(path)) - errx(1, "path truncated: 'commit/%s.html'", oidstr); + errx(1, "path truncated: 'commit/%s'", oidstr); r = access(path, F_OK); /* optimization: if there are no log lines to write and @@ -693,7 +693,7 @@ printcommitatom(FILE *fp, struct commitinfo *ci) xmlencode(fp, ci->summary, strlen(ci->summary)); fputs("\n", fp); } - fprintf(fp, "", + fprintf(fp, "", ci->oid); if (ci->author) { @@ -863,7 +863,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path) r = snprintf(filepath, sizeof(filepath), "file/%s.html", entrypath); if (r < 0 || (size_t)r >= sizeof(filepath)) - errx(1, "path truncated: 'file/%s.html'", entrypath); + errx(1, "path truncated: 'file/%s'", entrypath); if (!git_tree_entry_to_object(&obj, repo, entry)) { switch (git_object_type(obj)) { @@ -888,7 +888,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path) fputs("", fp); fputs(filemode(git_tree_entry_filemode(entry)), fp); fprintf(fp, "", fp); xmlencode(fp, entrypath, strlen(entrypath)); fputs("", fp); @@ -899,7 +899,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path) fputs("\n", fp); git_object_free(obj); } else if (!git_submodule_lookup(&module, repo, entryname)) { - fprintf(fp, "m---------", + fprintf(fp, "m---------", relpath); xmlencode(fp, entrypath, strlen(entrypath)); git_submodule_free(module); -- 2.25.0