]> Pileus Git - site/blobdiff - src/main.c
Support hidden pages
[site] / src / main.c
index 8cfc49ca52378a3a48afd6c357dc166e8ada3d0f..d3c7e12dcdae01b3f5162f5d34ea5e979c170a85 100644 (file)
@@ -136,10 +136,15 @@ menu_t *get_menu_rec(char *prefix, char **parts)
                }
                char *pathval = g_key_file_get_string(conf, entries[i], "path", NULL);
                char *nameval = g_key_file_get_string(conf, entries[i], "name", NULL);
+               int   hideval = g_key_file_get_boolean(conf, entries[i], "hide", NULL);
                if (pathval) next->path = pathval;
                if (nameval) next->name = nameval;
                if (!next->path) next->path = g_strdup(entries[i]);
                if (!next->name) next->name = g_strdup(entries[i]);
+               if (hideval)
+                       next->show = SHOW_HIDDEN;
+               if (!parts[0] && !strcmp(next->base, "index"))
+                       next->show = SHOW_ACTIVE;
                cur = cur->next = next;
        }
        g_strfreev(entries);
@@ -153,6 +158,8 @@ menu_t *get_menu_rec(char *prefix, char **parts)
                        continue;
                if ((next = get_menu_entry(prefix, entries[i])))
                        cur = cur->next = next;
+               if (!strcmp(cur->base, "index"))
+                       cur->show = SHOW_HIDDEN;
        }
        g_strfreev(entries);
        g_key_file_free(conf);
@@ -165,8 +172,6 @@ menu_t *get_menu_rec(char *prefix, char **parts)
                        cur->kids = get_menu_rec(cur->path, parts+1);
                        cur->show = SHOW_ACTIVE;
                }
-               if (!strcmp(cur->base, "index"))
-                       cur->show = SHOW_HIDDEN;
        }
 
 error:
@@ -199,9 +204,7 @@ menu_t *get_menu(char *path)
 void print_menu(menu_t *menu, int first, int last)
 {
        for (menu_t *cur = menu; cur; cur = cur->next) {
-               if (cur->show == SHOW_HIDDEN)
-                       continue;
-               if (first <= 0)
+               if (first <= 0 && cur->show != SHOW_HIDDEN)
                        print_link(cur->path, cur->name,
                                cur->show == SHOW_ACTIVE);
                if (cur->kids && last != 0)
@@ -247,13 +250,15 @@ static void do_regular(page_t *page, const char *file)
                else
                        page->html = markdown_to_string(page->text, 0, 0);
        } else {
-               page->html = g_strdup("Page not found");
+               page->error = g_strdup("403 Forbidden");
+               page->html  = g_strdup("Page not accessable\n");
        }
 }
 
 static void do_notfound(page_t *page, const char *path)
 {
-       page->html = "Page not found";
+       page->error = g_strdup("404 Not Found");
+       page->html  = g_strdup("Page not found\n");
 }
 
 static char *clean(const char *src)
@@ -277,9 +282,7 @@ static char *clean(const char *src)
 /* Main */
 int main(int argc, char **argv)
 {
-       char *path = clean(getenv("PATH_INFO") ?: "/aweather/");
-
-       print_header();
+       char *path = clean(getenv("PATH_INFO") ?: "/");
 
        page_t *page = get_page(path);
        menu_t *menu = get_menu(path);
@@ -303,6 +306,7 @@ int main(int argc, char **argv)
        g_free(index);
        g_free(file);
 
+       print_header(page);
        print_page(page, menu);
 
        return 0;