[wiki] [sites] Fix: Don't print unnecessary ul tags || David Gričar

From: <git_AT_suckless.org>
Date: Thu, 19 Mar 2020 03:11:46 +0100

commit 4f69a8f35d71d480295fcf6c3cd0c977b3e2544d
Author: David Gričar <suckless_AT_coppie.xyz>
Date: Thu Mar 19 03:07:37 2020 +0100

    Fix: Don't print unnecessary ul tags
    
    This will make website code even cleaner as build-page should no
    longer print empty ul tags if selected menu item has no subdirectories.

diff --git a/build-page.c b/build-page.c
index 1e882d71..f07ef4a8 100644
--- a/build-page.c
+++ b/build-page.c
_AT_@ -206,6 +206,32 @@ qsort_strcmp(const void *a, const void *b)
         return strcmp(*(const char **)a, *(const char **)b);
 }
 
+int
+last_dir(char *this)
+{
+ DIR *dp;
+ struct dirent *de;
+ char newdir[PATH_MAX];
+ int dir;
+
+ if ((dp = opendir(this ? this : ".")) == NULL)
+ die_perror("opendir: %s", this ? this : ".");
+
+ dir = 0;
+ while (dir == 0 && (de = readdir(dp))) {
+ if (*de->d_name == '.')
+ continue;
+ snprintf(newdir, sizeof(newdir), this ? "%2$s/%1$s" : "%s", de->d_name, this);
+ if (!stat_isdir(newdir))
+ continue;
+
+ dir = 1;
+ }
+ closedir(dp);
+
+ return !dir;
+}
+
 void
 menu_panel(char *domain, char *page, char *this, int depth)
 {
_AT_@ -251,11 +277,10 @@ menu_panel(char *domain, char *page, char *this, int depth)
                         fputs("/</a>", stdout);
                 }
 
- if (highlight) {
+ if (highlight && !last_dir(newdir)) {
                         putchar('
');
                         for (i = 0; i < depth + 2; ++i)
                                 putchar(' ');
- /* TODO: empty <ul></ul> is printed for subitems */
                         puts("<ul>");
                         menu_panel(domain, page, newdir, depth + 1);
                         for (i = 0; i < depth + 2; ++i)
Received on Thu Mar 19 2020 - 03:11:46 CET

This archive was generated by hypermail 2.3.0 : Thu Mar 19 2020 - 03:12:47 CET