]> Pileus Git - site/commitdiff
Support submenus
authorAndy Spencer <andy753421@gmail.com>
Mon, 21 Jan 2013 02:39:27 +0000 (02:39 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 21 Jan 2013 02:39:27 +0000 (02:39 +0000)
Submenus on the left are indented and the parent directories show a
trailing slash in the name.

src/html.h
src/main.c
theme/html.ct
theme/style.css

index a170dff1c5f191710643fb8690b5f13c22993d67..a2932a7962b4a8d46db0d60c35c8eb294f3ba40a 100644 (file)
@@ -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);
index d3c7e12dcdae01b3f5162f5d34ea5e979c170a85..3fad35719ead2eaa0c59b83ee9b7d12133df1f4d 100644 (file)
@@ -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();
+               }
        }
 }
 
index 244375ee84fe2bca585e4cbc7a33138dd1a16d14..0a2d2e3b55038fe98e501e17f1b6c1abc6ef80f7 100644 (file)
@@ -6,8 +6,20 @@ Content-Type: text/html;charset=UTF-8
 
 <% } %>
 
-<% void print_link(char *path, char *name, int cur) { %>
-       <a href="<% href(path); %>"<% if (cur) { %> class="cur"<% } %>><%= name %></a>
+<% void print_menu_start(void) { %>
+       <div class="nav">
+<% } %>
+
+<% void print_menu_end(void) { %>
+       </div>
+<% } %>
+
+<% void print_link(char *path, char *name, int cur, int dir) { %>
+       <a href="<% href(path); %>"<%
+               if (cur) { %> class="cur"<% }
+       %>><%= name %><%
+               if (dir > 1) { %>/<% }
+       %></a>
 <% } %>
 
 <% void print_page(page_t *page, menu_t *menu) { %>
index 5d79eef39259a8c26437e241654376a8912dc783..5bbd0e4d9b3318fe3f630cf426d2558f1a9fdd14 100644 (file)
@@ -101,6 +101,10 @@ h2.nav .cur {
        font-weight:   bold;
 }
 
+h2.nav .nav {
+       margin-left:   1em;
+}
+
 /* Content */
 .content {
        padding:       20px 20px 20px 220px;