From 38883f20665f5dc81a3aa568e6d6d8749cab4c9f Mon Sep 17 00:00:00 2001 From: dvs1 Date: Mon, 16 Dec 2024 20:54:10 +1000 Subject: TODO-- Implement smart menus. --- notYetAnotherWiki.lua | 83 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 24 deletions(-) (limited to 'notYetAnotherWiki.lua') diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index 9fa3178..cfe7459 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua @@ -2,7 +2,7 @@ local lcmark = require("lcmark") -local createHTML = function(cm, file, menu) +local createHTML = function(cm, file, header, menu) -- cm = string.gsub(cm, '._ ', '.  ') if nil ~= file then print('About to parse file ' .. file) end local result = '' @@ -19,6 +19,7 @@ local createHTML = function(cm, file, menu) templateFile = nil else metadata.menu = menu + metadata.header = header end metadata.body = lcmark.apply_template(bod, metadata) @@ -55,43 +56,77 @@ local createHTML = function(cm, file, menu) end -local cm = '' -local filename = '' -local menu = '' +local cm, filename, header, menu = '', '', '', '' +local site = {} +for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do + local s = {} + local f = '' + local c = 1 + for p in string.gmatch(l, '(%w+)/') do + table.insert(s, p) + c = c + #p + 1 + end + local full = string.sub(l, c, -1) + local base = string.gsub(full, '%.md$', '') + table.insert(s, base) -local h = io.open('menu.md', 'r') -if nil ~= h then - print('Found menu.md') - menu = createHTML(h:read('*a')) - h:close() - menu = string.gsub(menu, 'ul>', 'menu>') + if 'menu' == s[#s] then + local h = io.open(l, 'r') + if nil ~= h then + print('Found ' .. l) + menu = createHTML(h:read('*a')) + h:close() + menu = string.gsub(menu, 'ul>', 'menu>') + end + else + if 1 ~= #s then + site[l] = s + else + site[l] = base + end + end end +-- TODO - Only do these first things if menu.md doesn't exist, the second for headers.md +--if '' == menu then + for k, v in pairs(site) do + if 'string' == type(v) then + local m = '[' .. v .. '](' .. v .. '.HTML)\n' + menu = menu .. string.gsub(createHTML(m), 'ul>', 'menu>') + else + local path = '' + for i, w in ipairs(v) do + path = path .. w .. '/' + end + header = header .. '' .. v[1] .. '   ' + end + end +--end -if 0 ~= #arg then - for i,a in ipairs(arg) do - if filename == '' then filename = a end - local h = io.open(a, 'r') + +if 0 == #arg then + for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do + cm = '' + local h = io.open(l, 'r') if nil ~= h then - cm = cm .. h:read('*a') + createHTML(h:read('*a'), l, header, menu) h:close() else - print('oops! No such file ' .. a) + print('oops! No such file ' .. l) end end - if filename == '' then filename = 'test.md' end - createHTML(cm, filename, menu) else - local sticks = io.popen('find . -name "*.md" -type f -printf "%P\n"') - for l in sticks:lines() do - cm = '' - local h = io.open(l, 'r') + for i,a in ipairs(arg) do + if filename == '' then filename = a end + local h = io.open(a, 'r') if nil ~= h then - createHTML(h:read('*a'), l, menu) + cm = cm .. h:read('*a') h:close() else - print('oops! No such file ' .. l) + print('oops! No such file ' .. a) end end + if filename == '' then filename = 'test.md' end + createHTML(cm, filename, header, menu) end -- cgit v1.1