From 4bec516a86ece8e198b45c81fabf28c6c2ea8818 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 21 Jan 2013 02:39:27 +0000 Subject: [PATCH] Support submenus Submenus on the left are indented and the parent directories show a trailing slash in the name. --- src/html.h | 4 +++- src/main.c | 22 ++++++++++++++++++++-- theme/html.ct | 16 ++++++++++++++-- theme/style.css | 4 ++++ 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/html.h b/src/html.h index a170dff..a2932a7 100644 --- a/src/html.h +++ b/src/html.h @@ -41,8 +41,10 @@ struct menu_t { /* Helper functions */ void href(const char *url); -void print_link(char *path, char *name, int cur); +void print_link(char *path, char *name, int cur, int dir); void print_menu(menu_t *menu, int first, int last); +void print_menu_start(void); +void print_menu_end(void); /* Global functions */ void print_header(page_t *page); diff --git a/src/main.c b/src/main.c index d3c7e12..3fad357 100644 --- a/src/main.c +++ b/src/main.c @@ -201,14 +201,32 @@ menu_t *get_menu(char *path) #endif } +int get_slashes(char *path) +{ + int slashes = 0; + for (int i = 0; path[i]; i++) { + if (path[i] == '/') + slashes += 1; + if (path[i] != '/' && !path[i+1]) + slashes *= -1; + } + return slashes; +} + void print_menu(menu_t *menu, int first, int last) { for (menu_t *cur = menu; cur; cur = cur->next) { if (first <= 0 && cur->show != SHOW_HIDDEN) print_link(cur->path, cur->name, - cur->show == SHOW_ACTIVE); - if (cur->kids && last != 0) + cur->show == SHOW_ACTIVE, + get_slashes(cur->path)); + if (cur->kids && last != 0) { + if (first == 0) + print_menu_start(); print_menu(cur->kids, first-1, last-1); + if (first == 0) + print_menu_end(); + } } } diff --git a/theme/html.ct b/theme/html.ct index 244375e..0a2d2e3 100644 --- a/theme/html.ct +++ b/theme/html.ct @@ -6,8 +6,20 @@ Content-Type: text/html;charset=UTF-8 <% } %> -<% void print_link(char *path, char *name, int cur) { %> - class="cur"<% } %>><%= name %> +<% void print_menu_start(void) { %> + +<% } %> + +<% void print_link(char *path, char *name, int cur, int dir) { %> + class="cur"<% } + %>><%= name %><% + if (dir > 1) { %>/<% } + %> <% } %> <% void print_page(page_t *page, menu_t *menu) { %> diff --git a/theme/style.css b/theme/style.css index 5d79eef..5bbd0e4 100644 --- a/theme/style.css +++ b/theme/style.css @@ -101,6 +101,10 @@ h2.nav .cur { font-weight: bold; } +h2.nav .nav { + margin-left: 1em; +} + /* Content */ .content { padding: 20px 20px 20px 220px; -- 2.43.2