[wiki] [sites] build-page improvements || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Fri, 04 Jan 2019 16:26:26 +0100

commit d940b763dd74e2438ebef3bbe7a2220eee592c48
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri Jan 4 16:25:43 2019 +0100

    build-page improvements
    
    - fix crash (off-by-one) when there are more than 1024 directories.
    - add depth parameter to recursive menu_panel() function and indent menus,
      this is kindof useless at the moment, but will be useful for the gopher
      version.
    - minor style fixes.

diff --git a/build-page.c b/build-page.c
index 386f30a1..f62a820a 100644
--- a/build-page.c
+++ b/build-page.c
_AT_@ -22,22 +22,22 @@ char *html_header =
         "<!doctype html>
"
         "<html>
"
         "<head>
"
- " <meta charset=\"utf-8\"/>
"
- " <title>%s | suckless.org software that sucks less</title>
"
- " <link rel=\"stylesheet\" type=\"text/css\" href=\"//suckless.org/pub/style.css\"/>
"
+ " <meta charset=\"utf-8\"/>
"
+ " <title>%s | suckless.org software that sucks less</title>
"
+ " <link rel=\"stylesheet\" type=\"text/css\" href=\"//suckless.org/pub/style.css\"/>
"
         "</head>
"
         "
"
         "<div id=\"header\">
"
- " <a href=\"//suckless.org/\"><img src=\"//suckless.org/logo.svg\"/></a>
"
- " <a id=\"headerLink\" href=\"//suckless.org/\">suckless.org</a>
"
- " <span id=\"headerSubtitle\">%s</span>
"
+ " <a href=\"//suckless.org/\"><img src=\"//suckless.org/logo.svg\"/></a>
"
+ " <a id=\"headerLink\" href=\"//suckless.org/\">suckless.org</a>
"
+ " <span id=\"headerSubtitle\">%s</span>
"
         "</div>
";
 
 char *html_nav_bar =
- "<span class=\"right\">
"
- " <a href=\"//dl.suckless.org\">download</a>
"
- " <a href=\"//git.suckless.org\">source</a>
"
- "</span>
";
+ " <span class=\"right\">
"
+ " <a href=\"//dl.suckless.org\">download</a>
"
+ " <a href=\"//git.suckless.org\">source</a>
"
+ " </span>
";
 
 char *html_footer = "<div id=\"footer\">
"
         "<span class=\"right\">
"
_AT_@ -217,19 +217,21 @@ qsort_strcmp(const void *a, const void *b)
 }
 
 void
-menu_panel(char *domain, char *page, char *this)
+menu_panel(char *domain, char *page, char *this, int depth)
 {
         DIR *dp;
         struct dirent *de;
         char newdir[PATH_MAX];
         char *d_list[DIR_MAX];
         char **d;
- size_t d_len = 0;
+ size_t d_len;
+ int i;
 
         if ((dp = opendir(this ? this : ".")) == NULL)
                 die_perror("opendir: %s", this ? this : ".");
 
- while (d_len < LEN(d_list) && (de = readdir(dp)))
+ d_len = 0;
+ while (d_len + 1 < LEN(d_list) && (de = readdir(dp)))
                 d_list[d_len++] = de->d_name;
         d_list[d_len] = NULL;
 
_AT_@ -242,16 +244,26 @@ menu_panel(char *domain, char *page, char *this)
                 if (!stat_isdir(newdir))
                         continue;
 
- fputs(" <li><a", stdout);
+ for (i = 0; i < depth + 1; ++i)
+ fputs(" ", stdout);
+ fputs("<li><a", stdout);
                 if (page && !strncmp(newdir, page, strlen(newdir)))
                         fputs(" class=\"thisPage\"", stdout);
                 printf(" href=\"//%s/%s\">", domain, newdir);
                 print_name(*d);
                 fputs("/</a>", stdout);
                 if (page && !strncmp(newdir, page, strlen(newdir))) {
- puts(" <ul>");
- menu_panel(domain, page, newdir);
- puts(" </ul>");
+ fputs("
", stdout);
+ for (i = 0; i < depth + 2; ++i)
+ fputs(" ", stdout);
+ /* TODO: empty <ul></ul> is printed for subitems */
+ puts("<ul>");
+ menu_panel(domain, page, newdir, depth + 1);
+ for (i = 0; i < depth + 2; ++i)
+ fputs(" ", stdout);
+ fputs("</ul>
", stdout);
+ for (i = 0; i < depth + 1; ++i)
+ fputs(" ", stdout);
                 }
                 puts("</li>");
         }
_AT_@ -265,8 +277,7 @@ print_menu_panel(char *domain, char *page)
         if (!page)
                 fputs(" class=\"thisPage\"", stdout);
         puts(" href=\"/\">about</a></li>");
- menu_panel(domain, page, NULL);
-
+ menu_panel(domain, page, NULL, 0);
         puts(" </ul>");
         puts("</div>");
 }
Received on Fri Jan 04 2019 - 16:26:26 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 04 2019 - 16:36:26 CET