[hobbit] Feature request: better default navigation experience
Henrik Stoerner
henrik at hswn.dk
Fri Sep 1 14:21:18 CEST 2006
On Thu, Aug 31, 2006 at 04:46:22PM -0500, T.J. Yang wrote:
> I implemented your suggestion on my test server with lots of manually
> editing.
This patch will build the menu-entry definitions automatically. It
won't update your menu_items.js file, but since it only needs changing
when new pages/subpages are added, I guess that can be done manually.
To use it, run bbgen with the "--menufile=/tmp/menu.inc" option (use
any filename you like), and bbgen will then dump the menu-items for the
tree structure of the webpages. Edit your menu_items.js file and include
the generated menu entries into the main file.
Regards,
Henrik
-------------- next part --------------
--- bbdisplay/bbgen.c 2006/05/25 14:57:06 1.224
+++ bbdisplay/bbgen.c 2006/09/01 12:09:34
@@ -42,6 +42,7 @@
dispsummary_t *dispsums = NULL; /* Summaries we received and display */
int bb_color, bb2_color, bbnk_color; /* Top-level page colors */
int fqdn = 1; /* Hobbit FQDN setting */
+char *menufn = NULL;
time_t reportstart = 0;
time_t reportend = 0;
@@ -86,6 +87,55 @@
NULL };
+void dump_page_tree(FILE *fd, bbgen_page_t *head, char *path)
+{
+ static int level = 0;
+ bbgen_page_t *walk;
+
+ level++;
+
+ for (walk = head; (walk); walk = walk->next) {
+ int i;
+
+ if (walk->parent) {
+
+ fprintf(fd, "\t");
+ for (i=0; (i<level); i++) fprintf(fd, " ");
+
+ if (walk->subpages) {
+ fprintf(fd, "['%s', null, null,\n", walk->title);
+ }
+ else {
+ char *url;
+
+ url = (char *)malloc(strlen(getenv("BBWEB")) + strlen(path) + strlen(walk->name) + 10);
+ sprintf(url, "%s/%s/%s/", getenv("BBWEB"), path, walk->name);
+
+ fprintf(fd, "['%s', '%s'],\n", walk->title, cleanurl(url));
+ xfree(url);
+ }
+ }
+
+ if (walk->subpages) {
+ char *mypath;
+
+ mypath = (char *)malloc(strlen(path) + strlen(walk->name) + 2);
+ sprintf(mypath, "%s/%s", path, walk->name);
+ dump_page_tree(fd, walk->subpages, mypath);
+ xfree(mypath);
+
+ if (walk->parent) {
+ fprintf(fd, "\t");
+ for (i=0; (i<level); i++) fprintf(fd, " ");
+ fprintf(fd, "],\n");
+ }
+ }
+ }
+
+ level--;
+}
+
+
int main(int argc, char *argv[])
{
char *pagedir;
@@ -447,6 +497,10 @@
printf("\n");
exit(0);
}
+ else if (argnmatch(argv[i], "--menufile=")) {
+ char *lp = strchr(argv[i], '=');
+ menufn = strdup(lp+1);
+ }
else if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-?") == 0)) {
printf("bbgen for Hobbit version %s\n\n", VERSION);
@@ -574,6 +628,16 @@
pagehead = load_bbhosts(pageset);
add_timestamp("Load bbhosts done");
+ if (menufn) {
+ FILE *fd;
+
+ fd = fopen(menufn, "w");
+ if (fd) {
+ dump_page_tree(fd, pagehead, "");
+ fclose(fd);
+ }
+ }
+
if (!embedded) {
/* Remove old acknowledgements */
delete_old_acks();
More information about the Xymon
mailing list