aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/notYetAnotherWiki.lua
diff options
context:
space:
mode:
authordvs12024-12-16 20:54:10 +1000
committerdvs12024-12-16 20:54:10 +1000
commit38883f20665f5dc81a3aa568e6d6d8749cab4c9f (patch)
treef9e3ce877ccb96841afc48e99f0033c747550df5 /notYetAnotherWiki.lua
parentLet's see if I can use emoji. (diff)
downloadnotYetAnotherWiki-38883f20665f5dc81a3aa568e6d6d8749cab4c9f.zip
notYetAnotherWiki-38883f20665f5dc81a3aa568e6d6d8749cab4c9f.tar.gz
notYetAnotherWiki-38883f20665f5dc81a3aa568e6d6d8749cab4c9f.tar.bz2
notYetAnotherWiki-38883f20665f5dc81a3aa568e6d6d8749cab4c9f.tar.xz
TODO-- Implement smart menus.
Diffstat (limited to 'notYetAnotherWiki.lua')
-rwxr-xr-xnotYetAnotherWiki.lua83
1 files changed, 59 insertions, 24 deletions
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua
index 9fa3178..cfe7459 100755
--- a/notYetAnotherWiki.lua
+++ b/notYetAnotherWiki.lua
@@ -2,7 +2,7 @@
2 2
3local lcmark = require("lcmark") 3local lcmark = require("lcmark")
4 4
5local createHTML = function(cm, file, menu) 5local createHTML = function(cm, file, header, menu)
6-- cm = string.gsub(cm, '._ ', '.  ') 6-- cm = string.gsub(cm, '._ ', '.  ')
7 if nil ~= file then print('About to parse file ' .. file) end 7 if nil ~= file then print('About to parse file ' .. file) end
8 local result = '' 8 local result = ''
@@ -19,6 +19,7 @@ local createHTML = function(cm, file, menu)
19 templateFile = nil 19 templateFile = nil
20 else 20 else
21 metadata.menu = menu 21 metadata.menu = menu
22 metadata.header = header
22 end 23 end
23 metadata.body = lcmark.apply_template(bod, metadata) 24 metadata.body = lcmark.apply_template(bod, metadata)
24 25
@@ -55,43 +56,77 @@ local createHTML = function(cm, file, menu)
55end 56end
56 57
57 58
58local cm = '' 59local cm, filename, header, menu = '', '', '', ''
59local filename = '' 60local site = {}
60local menu = ''
61 61
62for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do
63 local s = {}
64 local f = ''
65 local c = 1
66 for p in string.gmatch(l, '(%w+)/') do
67 table.insert(s, p)
68 c = c + #p + 1
69 end
70 local full = string.sub(l, c, -1)
71 local base = string.gsub(full, '%.md$', '')
72 table.insert(s, base)
62 73
63local h = io.open('menu.md', 'r') 74 if 'menu' == s[#s] then
64if nil ~= h then 75 local h = io.open(l, 'r')
65 print('Found menu.md') 76 if nil ~= h then
66 menu = createHTML(h:read('*a')) 77 print('Found ' .. l)
67 h:close() 78 menu = createHTML(h:read('*a'))
68 menu = string.gsub(menu, 'ul>', 'menu>') 79 h:close()
80 menu = string.gsub(menu, 'ul>', 'menu>')
81 end
82 else
83 if 1 ~= #s then
84 site[l] = s
85 else
86 site[l] = base
87 end
88 end
69end 89end
70 90
91-- TODO - Only do these first things if menu.md doesn't exist, the second for headers.md
92--if '' == menu then
93 for k, v in pairs(site) do
94 if 'string' == type(v) then
95 local m = '[' .. v .. '](' .. v .. '.HTML)\n'
96 menu = menu .. string.gsub(createHTML(m), 'ul>', 'menu>')
97 else
98 local path = ''
99 for i, w in ipairs(v) do
100 path = path .. w .. '/'
101 end
102 header = header .. '<a href="' .. string.sub(path, 1, -2) .. '.HTML">' .. v[1] .. '</a> &nbsp; '
103 end
104 end
105--end
71 106
72if 0 ~= #arg then 107
73 for i,a in ipairs(arg) do 108if 0 == #arg then
74 if filename == '' then filename = a end 109 for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do
75 local h = io.open(a, 'r') 110 cm = ''
111 local h = io.open(l, 'r')
76 if nil ~= h then 112 if nil ~= h then
77 cm = cm .. h:read('*a') 113 createHTML(h:read('*a'), l, header, menu)
78 h:close() 114 h:close()
79 else 115 else
80 print('oops! No such file ' .. a) 116 print('oops! No such file ' .. l)
81 end 117 end
82 end 118 end
83 if filename == '' then filename = 'test.md' end
84 createHTML(cm, filename, menu)
85else 119else
86 local sticks = io.popen('find . -name "*.md" -type f -printf "%P\n"') 120 for i,a in ipairs(arg) do
87 for l in sticks:lines() do 121 if filename == '' then filename = a end
88 cm = '' 122 local h = io.open(a, 'r')
89 local h = io.open(l, 'r')
90 if nil ~= h then 123 if nil ~= h then
91 createHTML(h:read('*a'), l, menu) 124 cm = cm .. h:read('*a')
92 h:close() 125 h:close()
93 else 126 else
94 print('oops! No such file ' .. l) 127 print('oops! No such file ' .. a)
95 end 128 end
96 end 129 end
130 if filename == '' then filename = 'test.md' end
131 createHTML(cm, filename, header, menu)
97end 132end