aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authordvs12024-12-27 18:45:08 +1000
committerdvs12024-12-27 18:45:08 +1000
commit7e9cedd15210f43da4576447b306199fb0ba07ef (patch)
tree29afdd593809c3b1abda16d69190b316522f3f9c
parentHopefully fixed up the trail now. (diff)
downloadnotYetAnotherWiki-7e9cedd15210f43da4576447b306199fb0ba07ef.zip
notYetAnotherWiki-7e9cedd15210f43da4576447b306199fb0ba07ef.tar.gz
notYetAnotherWiki-7e9cedd15210f43da4576447b306199fb0ba07ef.tar.bz2
notYetAnotherWiki-7e9cedd15210f43da4576447b306199fb0ba07ef.tar.xz
Still heavily twveaking the menu / header / trail code.
Almost perphekt.
-rwxr-xr-xnotYetAnotherWiki.lua99
1 files changed, 62 insertions, 37 deletions
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua
index 3146341..793a0a0 100755
--- a/notYetAnotherWiki.lua
+++ b/notYetAnotherWiki.lua
@@ -22,66 +22,93 @@ for l in io.popen('find ' .. directory .. ' -name "*.md" -type f,l -printf "%P\n
22end 22end
23 23
24for i, l in pairs(all) do 24for i, l in pairs(all) do
25 local bit, dir, file, parent, path = '', '', '', '', '' 25 local dir, file, parent, path = '', '', '', '', ''
26 local bits = {} 26 local bits = {}
27 local last = 1 27 local last = 1
28 for i = 1, #l do 28 for j = 1, #l do
29 local c = string.sub(l, i, i) 29 local c = string.sub(l, j, j)
30 if '/' == c then 30 if '/' == c then
31 bit = string.sub(l, last, i - 1) 31 table.insert(bits, string.sub(l, last, j - 1))
32 if 0 == ln then 32 last = j + 1
33 parent = bit
34 end
35 table.insert(bits, bit)
36 last = i + 1
37 end 33 end
38 end 34 end
39 bit = string.sub(l, last) 35 file = string.sub(l, last)
40 bit = string.gsub(bit, '%.md$', '') 36 file = string.gsub(file, '%.md$', '')
41 table.insert(bits, bit)
42 37
43 local ln = #bits 38 local ln = #bits
44 local base = table.concat(bits, '/') 39 if 0 < ln then
45 if 1 < ln then 40 dir = bits[ln]
46 dir = bits[ln - 1] 41 path = table.concat(bits, '/', 1, ln)
47 parent = table.concat(bits, '/', 1, ln - 2) 42 if 1 < ln then parent = table.concat(bits, '/', 1, ln - 1) end
48 end 43 end
49 if 0 < ln then path = table.concat(bits, '/', 1, ln - 1) end
50 local file = bit
51 44
52 local files = {name = file, URL = '<p><a href="' .. file .. '.HTML">' .. file .. '</a></p>'} 45 local files = {name = file, URL = '<p><a href="' .. file .. '.HTML">' .. file .. '</a></p>', }
53 if nil == sites[path] then sites[path] = {files = {files}} 46 if nil == sites[path] then sites[path] = {files = {files}}
54 elseif nil == sites[path].files then sites[path].files = {files} 47 elseif nil == sites[path].files then sites[path].files = {files}
55 else table.insert(sites[path].files, files) 48 else table.insert(sites[path].files, files)
56 end 49 end
57 sites[path].depth = ln - 1 50
58 sites[path].parent = parent 51 if '' ~= dir then
59 sites[path].dir = dir 52-- FIXME - not sure why this is needed anymore, but it fails building subs without it. Just slows things down otherwise.
60 sites[path].bits = bits 53 files = {name = dir, URL = '<a href="' .. dir .. '/">' .. dir .. '</a> &nbsp; ', }
61 table.sort(sites[path].files, function(a, b) return (a.name <= b.name) end) 54 if nil == sites[parent] then sites[parent] = {subs = {[files.name] = files}}
62 55 elseif nil == sites[parent].subs then sites[parent].subs = {[files.name] = files}
63 files = {name = dir, URL = '<a href="' .. dir .. '/">' .. dir .. '</a> &nbsp; '} 56 else sites[parent].subs[files.name] = files
64 if nil == sites[parent] then sites[parent] = {subs = {[files.name] = files}} 57 end
65 elseif nil == sites[parent].subs then sites[parent].subs = {[files.name] = files}
66 else sites[parent].subs[files.name] = files
67 end 58 end
59
68end 60end
69 61
70for k, v in pairs(sites) do 62for k, v in pairs(sites) do
71 local st = {} 63 local bit, dir, file, parent, path = '', '', '', '', ''
64 local bits = {}
65 local last = 1
66 for j = 1, #k do
67 local c = string.sub(k, j, j)
68 if '/' == c then
69 table.insert(bits, string.sub(k, last, j - 1))
70 last = j + 1
71 end
72 end
73 sites[k].parent = table.concat(bits, '/')
74 table.insert(bits, string.sub(k, last))
75 sites[k].bits = bits
76 if nil ~= sites[k].files then table.sort(sites[k].files, function(a, b) return (a.name <= b.name) end) end
77
78 dir = bits[#bits - 1]
79 file = bits[#bits]
80 if nil ~= sites[dir] then
81 if nil == sites[dir].subs then sites[dir].subs = {} end
82 last = nil
83 for j, g in pairs(sites[dir].subs) do
84 if (g.name == dir) or (g.name == file) then
85 last = j
86 break
87 end
88 end
89 if nil == last then
90 sites[dir].subs[file] = {name = file, URL = '<a href="' .. file .. '/">' .. file .. '</a> &nbsp; '}
91 end
92 end
93
94 bits = {}
72 if nil ~= v.subs then 95 if nil ~= v.subs then
73 for l, w in pairs(v.subs) do 96 for l, w in pairs(v.subs) do
74 table.insert(st, w) 97 table.insert(bits, w)
75 end 98 end
76 table.sort(st, function(a, b) return (a.name <= b.name) end) 99 table.sort(bits, function(a, b) return (a.name <= b.name) end)
77 v.subs = st 100 v.subs = bits
78 end 101 end
102end
103
104
105for k, v in pairs(sites) do
79 106
80 if nil ~= v.files then 107 if nil ~= v.files then
81 for l, w in pairs(v.files) do 108 for l, w in pairs(v.files) do
82 local path = v.parent 109 local path = v.parent
83 if '' ~= path then path = path .. '/' end 110 if '' ~= path then path = path .. '/' end
84 path = path .. v.dir 111 path = path .. v.bits[#(v.bits)]
85 if '' ~= path then path = path .. '/' end 112 if '' ~= path then path = path .. '/' end
86 local file = path .. w.name .. '.md' 113 local file = path .. w.name .. '.md'
87 if (nil ~= file) and ('' ~= file) then io.write('Parsing ' .. file .. ' -> ') end 114 if (nil ~= file) and ('' ~= file) then io.write('Parsing ' .. file .. ' -> ') end
@@ -117,13 +144,11 @@ for k, v in pairs(sites) do
117 end 144 end
118 end 145 end
119 146
120 local num = v.depth 147 local num = #(v.bits)
121 local trail = '<a href="' .. string.rep('../', num) .. '">home</a> &nbsp; ' 148 local trail = '<a href="' .. string.rep('../', num) .. '">home</a> &nbsp; '
122 local p = v.parent 149 local p = v.parent
123 for i = 1, num do 150 for i = 1, num do
124 trail = trail .. '<a href="' .. string.rep('../', num - i) .. '">' .. v.bits[i] .. '</a> &nbsp; ' 151 trail = trail .. '<a href="' .. string.rep('../', num - i) .. '">' .. v.bits[i] .. '</a> &nbsp; '
125-- p = w[parent]
126-- if nil == p then break end
127 end 152 end
128 trail = trail .. w.name 153 trail = trail .. w.name
129 metadata.trail = trail 154 metadata.trail = trail