root/swish_website/lib/config/expand

Revision 1654, 3.7 kB (checked in by whmoseley, 4 years ago)

I blame this all on my quick fingers and vim.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 [%  # From chapter 11 of Badger book.
2
3 # page.trail tracks path to the current page.
4 DEFAULT page.trail = [ ];
5 DEFAULT navigation = {};
6
7 this_level = 0;
8 first_item = 0;
9
10 # List of menu items we're constructing.
11 map.items = [ ];
12
13
14 # Walk through item names in map.menu.
15 FOREACH id IN map.menu;
16
17     # Allow for there to be a missing page entry (setting the name to the menu id)
18     SET map.page = {} UNLESS map.page;
19     SET map.page.$id = { name = id } UNLESS map.page.$id;
20     SET map.page.$id.name = id UNLESS map.page.$id.name;
21     item = map.page.$id;
22
23
24
25     # Add location data.
26     item.id   = id;
27
28     # Check for external link
29     IF item.external;
30         item.url = item.external;
31
32     ELSE;
33         item.path = path ? "$path/$id" : id;
34
35         item.extension = item.defined('extension') ? item.extension : '.html';
36         item.indexname = item.defined('indexname') ? item.indexname : 'index.html';
37
38         UNLESS item.file;
39             item.file = item.menu
40                       ? "${item.path}/${item.indexname}"
41                       : "${item.path}${item.extension}";
42         END;
43
44
45
46         # Here's a hack to deal with geneating just HTML docs (abslinks is the flag)
47         # Want all links to go to http://swish-e.org.  That's set in site.url.root
48         # The exception is when geneating links for the docs pages, which then
49         # the links are relative to the current directory.
50
51         IF this.abslinks && item.path.match("^docs");
52             item.url = item.file.replace('^docs/','./');
53
54             # Adjust the name of the current page for item.hot check below
55             SET page.file = "docs/$page.file" UNLESS page.file.match('^docs/');
56
57         ELSE;
58             SET item.hidden = 1 IF this.abslinks;  # This removes the non-doc items from the menu
59             item.url = "$site.url.root/$item.file";
60
61         END;
62
63
64         # When buidling pod-only then the docs/ section is moved up to root, which
65         # will clash with the real root.  So need to excluded this checking with
66         # generating pods.
67
68         IF !this.abslinks || item.path.match("^docs");
69
70             # Is this item on the path to the current page?
71             item.hot  = page.file.match("^(../)?$item.path");
72             item.subs = item.hot and item.menu.size;
73             item.here = (item.file == page.file);
74         END;
75
76
77     END;
78
79
80     # Now build navigation and add this item to its parent's list of items
81     # How navigation works depends on how you define next/prev and things like that
82     # Here we just take'em as them come
83     # Some of this would be easier if the list was flat.
84
85     UNLESS item.hidden;
86
87
88         # Very first link ("Top" for Mozilla)
89         SET navigation.Start = item UNLESS navigation.Start;
90
91         # Should these be limited to the current level  Currently: yes
92         # Happens because recursion is locallizing last_item.
93
94         SET navigation.Prev  = last_item IF last_item && item.here;
95         SET navigation.Next  = item IF last_item && last_item.here;
96         SET last_item = item;  # save for next time
97
98         SET navigation.Up    = page.trail.last IF page.trail.last && item.here;
99
100         page.trail.push( item ) IF item.hot;
101
102         # First and Last are a bit more complex
103         SET this_level = item IF item.here;
104         SET first_item = item UNLESS first_item;
105
106
107         # Add this item to it's parent's list (recursive menu)
108         map.items.push(item);
109     END;
110
111
112     # Recursively process any sub menus
113
114     IF item.menu;
115         INCLUDE config/expand
116             map  = item
117             path = item.path;
118     END;
119
120
121 END;  # Foreach
122
123
124 IF this_level && !( navigation.First || navigation.Last );
125 #IF this_level;
126     SET navigation.First = first_item IF first_item && !first_item.here;
127     SET navigation.Last  = last_item UNLESS last_item.here;
128 END;
129
130
131
132 -%]
Note: See TracBrowser for help on using the browser.