From 7e9cedd15210f43da4576447b306199fb0ba07ef Mon Sep 17 00:00:00 2001 From: dvs1 Date: Fri, 27 Dec 2024 18:45:08 +1000 Subject: Still heavily twveaking the menu / header / trail code. Almost perphekt. --- notYetAnotherWiki.lua | 99 ++++++++++++++++++++++++++++++++------------------- 1 file 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 end for i, l in pairs(all) do - local bit, dir, file, parent, path = '', '', '', '', '' + local dir, file, parent, path = '', '', '', '', '' local bits = {} local last = 1 - for i = 1, #l do - local c = string.sub(l, i, i) + for j = 1, #l do + local c = string.sub(l, j, j) if '/' == c then - bit = string.sub(l, last, i - 1) - if 0 == ln then - parent = bit - end - table.insert(bits, bit) - last = i + 1 + table.insert(bits, string.sub(l, last, j - 1)) + last = j + 1 end end - bit = string.sub(l, last) - bit = string.gsub(bit, '%.md$', '') - table.insert(bits, bit) + file = string.sub(l, last) + file = string.gsub(file, '%.md$', '') local ln = #bits - local base = table.concat(bits, '/') - if 1 < ln then - dir = bits[ln - 1] - parent = table.concat(bits, '/', 1, ln - 2) + if 0 < ln then + dir = bits[ln] + path = table.concat(bits, '/', 1, ln) + if 1 < ln then parent = table.concat(bits, '/', 1, ln - 1) end end - if 0 < ln then path = table.concat(bits, '/', 1, ln - 1) end - local file = bit - local files = {name = file, URL = '
'} + local files = {name = file, URL = '', } if nil == sites[path] then sites[path] = {files = {files}} elseif nil == sites[path].files then sites[path].files = {files} else table.insert(sites[path].files, files) end - sites[path].depth = ln - 1 - sites[path].parent = parent - sites[path].dir = dir - sites[path].bits = bits - table.sort(sites[path].files, function(a, b) return (a.name <= b.name) end) - - files = {name = dir, URL = '' .. dir .. ' '} - if nil == sites[parent] then sites[parent] = {subs = {[files.name] = files}} - elseif nil == sites[parent].subs then sites[parent].subs = {[files.name] = files} - else sites[parent].subs[files.name] = files + + if '' ~= dir then +-- FIXME - not sure why this is needed anymore, but it fails building subs without it. Just slows things down otherwise. + files = {name = dir, URL = '' .. dir .. ' ', } + if nil == sites[parent] then sites[parent] = {subs = {[files.name] = files}} + elseif nil == sites[parent].subs then sites[parent].subs = {[files.name] = files} + else sites[parent].subs[files.name] = files + end end + end for k, v in pairs(sites) do - local st = {} + local bit, dir, file, parent, path = '', '', '', '', '' + local bits = {} + local last = 1 + for j = 1, #k do + local c = string.sub(k, j, j) + if '/' == c then + table.insert(bits, string.sub(k, last, j - 1)) + last = j + 1 + end + end + sites[k].parent = table.concat(bits, '/') + table.insert(bits, string.sub(k, last)) + sites[k].bits = bits + if nil ~= sites[k].files then table.sort(sites[k].files, function(a, b) return (a.name <= b.name) end) end + + dir = bits[#bits - 1] + file = bits[#bits] + if nil ~= sites[dir] then + if nil == sites[dir].subs then sites[dir].subs = {} end + last = nil + for j, g in pairs(sites[dir].subs) do + if (g.name == dir) or (g.name == file) then + last = j + break + end + end + if nil == last then + sites[dir].subs[file] = {name = file, URL = '' .. file .. ' '} + end + end + + bits = {} if nil ~= v.subs then for l, w in pairs(v.subs) do - table.insert(st, w) + table.insert(bits, w) end - table.sort(st, function(a, b) return (a.name <= b.name) end) - v.subs = st + table.sort(bits, function(a, b) return (a.name <= b.name) end) + v.subs = bits end +end + + +for k, v in pairs(sites) do if nil ~= v.files then for l, w in pairs(v.files) do local path = v.parent if '' ~= path then path = path .. '/' end - path = path .. v.dir + path = path .. v.bits[#(v.bits)] if '' ~= path then path = path .. '/' end local file = path .. w.name .. '.md' if (nil ~= file) and ('' ~= file) then io.write('Parsing ' .. file .. ' -> ') end @@ -117,13 +144,11 @@ for k, v in pairs(sites) do end end - local num = v.depth + local num = #(v.bits) local trail = 'home ' local p = v.parent for i = 1, num do trail = trail .. '' .. v.bits[i] .. ' ' --- p = w[parent] --- if nil == p then break end end trail = trail .. w.name metadata.trail = trail -- cgit v1.1