(22 hours ago)commit 002c72a: refactored subdirectories
| author | Tanner Stenson <tanner@brickware.sh> |
| date | Wed Jan 7 23:37:31 2026 -0500 |
refactored subdirectories
commit 002c72a991c852a2affbbea9ccd4a542b6390c86
Author: Tanner Stenson <tanner@brickware.sh>
Date: Wed Jan 7 23:37:31 2026 -0500
refactored subdirectories
diff --git a/marrow-static.c b/marrow-static.c
index 0b4b4a6..ee5d9cb 100644
--- a/marrow-static.c
+++ b/marrow-static.c
@@ -173,16 +173,17 @@ generate_html_header(FILE *out, const char *repo_name, const char *suffix) {
/* Header with breadcrumb navigation */
fprintf(out, "<div class=\"header\"><h1>");
- /* Count slashes in repo_name to determine directory depth */
- int32_t repo_depth = 0;
+ /* Count path segments in repo_name (e.g., "user/project.git" = 2 segments) */
+ int32_t repo_segments = 1; /* At least one segment */
for (const char *p = repo_name; *p; p++) {
- if ('/' == *p) repo_depth++;
+ if ('/' == *p) repo_segments++;
}
/* Root "git" link - go up through branch/commit structure AND repo path */
fprintf(out, "<a href=\"");
- /* From branch/main/tree or commit/hash/summary (3 levels) up through repo path */
- for (int32_t i = 0; i < 3 + repo_depth; i++) {
+ /* From branch/main/tree or commit/hash/summary (3 levels) up through repo path segments */
+ int32_t git_levels = 3 + repo_segments;
+ for (int32_t i = 0; i < git_levels; i++) {
fprintf(out, "../");
}
fprintf(out, "\">git</a>");
@@ -193,31 +194,24 @@ generate_html_header(FILE *out, const char *repo_name, const char *suffix) {
snprintf(path_copy, sizeof(path_copy), "%s", repo_name);
char *token = strtok(path_copy, "/");
+ int32_t current_segment = 0;
while (token) {
fprintf(out, " / ");
- /* Calculate how many more segments remain */
- char *remaining = strtok(NULL, "/");
- int32_t remaining_segments = 0;
- if (remaining) {
- remaining_segments = 1;
- for (char *p = remaining; *p; p++) {
- if ('/' == *p) remaining_segments++;
- }
- }
-
/* Create link */
fprintf(out, "<a href=\"");
- /* Go up 3 levels (branch/main/tree) plus remaining segments in path */
- for (int32_t i = 0; i < 3 + remaining_segments; i++) {
+ /* Go up 3 levels (branch/main/tree) plus segments after this one */
+ int32_t levels_up = 3 + (repo_segments - current_segment - 1);
+ for (int32_t i = 0; i < levels_up; i++) {
fprintf(out, "../");
}
fprintf(out, "\">");
html_escape(out, token);
fprintf(out, "</a>");
- token = remaining;
+ current_segment++;
+ token = strtok(NULL, "/");
}
}
@@ -1538,18 +1532,17 @@ generate_directory_index(const char *output_dir, const char *git_base_path,
/* Generate header */
generate_directory_index_header(out, relative_dir_path);
- /* Generate subdirectories table if any exist OR if we need parent link */
- int32_t show_dirs_table = (dirs.count > 0) || (relative_dir_path && relative_dir_path[0]);
+ /* Generate combined table with directories and repositories */
+ int32_t show_table = (dirs.count > 0) || (repos.count > 0) || (relative_dir_path && relative_dir_path[0]);
- if (show_dirs_table) {
- fprintf(out, "<h2>directories</h2>\n");
+ if (show_table) {
fprintf(out, "<table>\n");
- fprintf(out, "<thead><tr><th>name</th><th>description</th></tr></thead>\n");
+ fprintf(out, "<thead><tr><th>name</th><th>description</th><th>last update</th><th>clone</th></tr></thead>\n");
fprintf(out, "<tbody>\n");
/* Add parent directory link if not root */
if (relative_dir_path && relative_dir_path[0]) {
- fprintf(out, "<tr><td><a href=\"../\">../</a></td><td>parent directory</td></tr>\n");
+ fprintf(out, "<tr><td><a href=\"../\">../</a></td><td>parent directory</td><td></td><td></td></tr>\n");
}
/* List subdirectories */
@@ -1562,20 +1555,10 @@ generate_directory_index(const char *output_dir, const char *git_base_path,
if (dirs.entries[i].readme_snippet[0]) {
html_escape(out, dirs.entries[i].readme_snippet);
}
- fprintf(out, "</td></tr>\n");
+ fprintf(out, "</td><td></td><td></td></tr>\n");
}
- fprintf(out, "</tbody>\n");
- fprintf(out, "</table>\n\n");
- }
-
- /* Generate repositories table if any exist */
- if (repos.count > 0) {
- fprintf(out, "<h2>repositories</h2>\n");
- fprintf(out, "<table>\n");
- fprintf(out, "<thead><tr><th>name</th><th>description</th><th>last update</th><th>clone</th></tr></thead>\n");
- fprintf(out, "<tbody>\n");
-
+ /* List repositories */
for (size_t i = 0; i < repos.count; i++) {
/* Extract just the basename for display */
const char *basename = strrchr(repos.repos[i].name, '/');