diff options
Diffstat (limited to 'notYetAnotherWiki.lua')
-rwxr-xr-x | notYetAnotherWiki.lua | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index d592d06..c7b205d 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua | |||
@@ -24,11 +24,16 @@ local Sites, Files, Subs = {}, {}, {} | |||
24 | -- Useful functions, part 0. | 24 | -- Useful functions, part 0. |
25 | 25 | ||
26 | -- A simple table.subtable = subtable wont work, you end up with a reference so that changes to the later get applaid to the former. | 26 | -- A simple table.subtable = subtable wont work, you end up with a reference so that changes to the later get applaid to the former. |
27 | local copyTable = function(t, strip) | 27 | local derefiTable = function(t, strip) |
28 | local argh = {} | 28 | local argh = {} |
29 | for l, y in ipairs(t) do if (l ~= y.name) and strip then table.insert(argh, y) end end | 29 | for l, y in ipairs(t) do if (l ~= y.name) and strip then table.insert(argh, y) end end |
30 | return argh | 30 | return argh |
31 | end | 31 | end |
32 | local derefTable = function(t, strip) | ||
33 | local argh = {} | ||
34 | for l, y in pairs(t) do argh[l] = y end | ||
35 | return argh | ||
36 | end | ||
32 | 37 | ||
33 | 38 | ||
34 | -- String together the bits array into a path string. | 39 | -- String together the bits array into a path string. |
@@ -79,7 +84,7 @@ for name, file in pairs(Files) do | |||
79 | path = path .. d | 84 | path = path .. d |
80 | if nil == Subs[path] then Subs[path] = {files = {}, subs = {}} end | 85 | if nil == Subs[path] then Subs[path] = {files = {}, subs = {}} end |
81 | if i < ln then Subs[path].subs[bits[i + 1]] = bits[i + 1] end | 86 | if i < ln then Subs[path].subs[bits[i + 1]] = bits[i + 1] end |
82 | Subs[path].bits = copyTable(bits, true) | 87 | Subs[path].bits = derefiTable(bits, true) |
83 | if i < ln then table.remove(Subs[path].bits, #bits) end | 88 | if i < ln then table.remove(Subs[path].bits, #bits) end |
84 | end | 89 | end |
85 | 90 | ||
@@ -97,10 +102,14 @@ for name, file in pairs(Files) do | |||
97 | Files[name] = nil | 102 | Files[name] = nil |
98 | else | 103 | else |
99 | -- Ordinary md file, stash it's metadata and parsed body. | 104 | -- Ordinary md file, stash it's metadata and parsed body. |
100 | h = io.open(name .. '.body', 'r') | 105 | -- I need cmark-gfm, coz lcmark doesn't support tables and stuff, it only does basic cmark. |
106 | -- Have to strip out the metadata first, coz cmark-gfm doesn't grok that. | ||
107 | h = io.popen('cp "' .. name .. '.md" "' .. name .. '02" ; csplit -ksz -f "' .. name .. '" "' .. name .. '.md" "/^---$/+1" "{1}" 2>/dev/null ; rm "' .. name .. '00" ; rm "' .. name .. '01" 2>/dev/null') | ||
108 | if nil ~= h then h:close() end | ||
109 | h = io.popen('cmark-gfm -t html -e footnotes -e table -e strikethrough -e autolink -e tagfilter -e tasklist "' .. name .. '02" ; rm "' .. name .. '02"') | ||
101 | if nil ~= h then body = h:read('*a') ; h:close() end | 110 | if nil ~= h then body = h:read('*a') ; h:close() end |
102 | file.metadata = metadata | 111 | Files[name].metadata = metadata |
103 | file.body = body | 112 | Files[name].body = body |
104 | table.insert(Subs[path].files, bit) | 113 | table.insert(Subs[path].files, bit) |
105 | end | 114 | end |
106 | end | 115 | end |
@@ -113,23 +122,26 @@ end | |||
113 | -- NOTE - only looking for the .md files we scanned for before, any stray HTML, html, HTM, and htm files will get ignored. | 122 | -- NOTE - only looking for the .md files we scanned for before, any stray HTML, html, HTM, and htm files will get ignored. |
114 | local whichPage = function(f) | 123 | local whichPage = function(f) |
115 | local fl = '' | 124 | local fl = '' |
116 | if (nil ~= Subs[f]) and (nil ~= Subs[f].files) then | 125 | if nil ~= Subs[f] then |
117 | if 1 == #(Subs[f].files) then fl = Subs[f].files[1] else | 126 | if nil ~= Subs[f].whichPage then return Subs[f].whichPage end |
118 | -- Standard files to search for. | 127 | if nil ~= Subs[f].files then |
119 | for i, v in ipairs{'about', 'readme', 'index', 'homepage', 'mainpage', 'webhome'} do | 128 | if 1 == #(Subs[f].files) then fl = Subs[f].files[1] else |
120 | for j, w in ipairs(Subs[f].files) do | 129 | -- Standard files to search for. |
121 | if v == string.lower(w) then | 130 | for i, v in ipairs{'about', 'readme', 'index', 'homepage', 'mainpage', 'webhome'} do |
122 | fl = w | 131 | for j, w in ipairs(Subs[f].files) do |
123 | break | 132 | if v == string.lower(w) then |
133 | fl = w | ||
134 | break | ||
135 | end | ||
124 | end | 136 | end |
137 | if '' ~= fl then break end | ||
125 | end | 138 | end |
126 | if '' ~= fl then break end | 139 | -- If nothing else, just grab the first one. |
140 | if ('' == fl) and (nil ~= Subs[f].files[1]) then fl = Subs[f].files[1] end | ||
127 | end | 141 | end |
128 | -- If nothing else, just grab the first one. | ||
129 | if ('' == fl) and (nil ~= Subs[f].files[1]) then fl = Subs[f].files[1] end | ||
130 | end | 142 | end |
131 | end | 143 | end |
132 | if '' ~= fl then fl = fl .. '.HTML' end | 144 | if '' ~= fl then fl = fl .. '.HTML' ; Subs[f].whichPage = fl end |
133 | return fl | 145 | return fl |
134 | end | 146 | end |
135 | 147 | ||
@@ -167,7 +179,7 @@ end | |||
167 | -- Loop through the files we found and actually create their HTML files. | 179 | -- Loop through the files we found and actually create their HTML files. |
168 | for name, file in pairs(Files) do | 180 | for name, file in pairs(Files) do |
169 | local path, result = '', '' | 181 | local path, result = '', '' |
170 | local body, metadata = Files[name].body, Files[name].metadata | 182 | local body, metadata = Files[name].body, derefTable(Files[name].metadata, true) |
171 | local bits, bit = Files[name].bits, Files[name].bit | 183 | local bits, bit = Files[name].bits, Files[name].bit |
172 | local ln = #bits | 184 | local ln = #bits |
173 | 185 | ||
@@ -237,7 +249,6 @@ for name, file in pairs(Files) do | |||
237 | 249 | ||
238 | -- Figure out this pages menu links. | 250 | -- Figure out this pages menu links. |
239 | metadata.menu = '' | 251 | metadata.menu = '' |
240 | if nil == metadata.title then metadata.title = metadata.pagetitle end | ||
241 | if nil == metadata.title then metadata.title = bit end | 252 | if nil == metadata.title then metadata.title = bit end |
242 | if nil ~= Subs[path].files then table.sort(Subs[path].files, function(a, b) return (string.lower(a) < string.lower(b)) end) end | 253 | if nil ~= Subs[path].files then table.sort(Subs[path].files, function(a, b) return (string.lower(a) < string.lower(b)) end) end |
243 | for i, f in ipairs(Subs[path].files) do | 254 | for i, f in ipairs(Subs[path].files) do |
@@ -298,6 +309,7 @@ for name, file in pairs(Files) do | |||
298 | result = lcmark.apply_template(template, metadata) | 309 | result = lcmark.apply_template(template, metadata) |
299 | end | 310 | end |
300 | else | 311 | else |
312 | print('No template for ' .. name) | ||
301 | result = body | 313 | result = body |
302 | end | 314 | end |
303 | 315 | ||
@@ -312,8 +324,8 @@ for name, file in pairs(Files) do | |||
312 | end | 324 | end |
313 | end | 325 | end |
314 | 326 | ||
315 | else | 327 | -- else |
316 | print('') | 328 | -- print('') |
317 | end | 329 | end |
318 | end | 330 | end |
319 | 331 | ||