diff options
Diffstat (limited to 'notYetAnotherWiki.lua')
| -rwxr-xr-x | notYetAnotherWiki.lua | 178 |
1 files changed, 92 insertions, 86 deletions
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index f53691b..be41c3a 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua | |||
| @@ -6,10 +6,9 @@ | |||
| 6 | Normally I define functions and globals at the top, but here I'm interleaving them. | 6 | Normally I define functions and globals at the top, but here I'm interleaving them. |
| 7 | ]] | 7 | ]] |
| 8 | 8 | ||
| 9 | local Lunamark = require("lunamark") -- https://github.com/jgm/lunamark | 9 | local Lunamark = require'lunamark' -- https://github.com/jgm/lunamark |
| 10 | local Lpeg = require("lpeg") -- https://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html Lunamark uses this, so we can to. | 10 | local Lpeg = require'lpeg' -- https://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html Lunamark uses this, so we can to. |
| 11 | local RE = require("re") -- Part of lpeg. https://www.inf.puc-rio.br/~roberto/lpeg/re.html | 11 | local RE = require're' -- Part of lpeg. https://www.inf.puc-rio.br/~roberto/lpeg/re.html |
| 12 | |||
| 13 | 12 | ||
| 14 | --------------------------------------------------------------------------------- | 13 | --------------------------------------------------------------------------------- |
| 15 | -- Some global data. | 14 | -- Some global data. |
| @@ -34,9 +33,9 @@ local Files, Subs, xLinks = {}, {}, {} | |||
| 34 | local Context = {} -- Coz can't otherwise pass context through to the deeper Lunamark functions I'm overriding. | 33 | local Context = {} -- Coz can't otherwise pass context through to the deeper Lunamark functions I'm overriding. |
| 35 | 34 | ||
| 36 | local Template = '' | 35 | local Template = '' |
| 37 | local h = io.open("default.template", 'r') | 36 | local h = io.open('default.template', 'r') |
| 38 | if nil ~= h then | 37 | if nil ~= h then |
| 39 | Template = h:read('*a') | 38 | Template = h:read('*a') -- NOTE - Lua 5.3 changes to not need the *, but ignores it if it's there. |
| 40 | h:close() | 39 | h:close() |
| 41 | else | 40 | else |
| 42 | print('oops! No such file ' .. 'default.template') | 41 | print('oops! No such file ' .. 'default.template') |
| @@ -73,12 +72,12 @@ local stringBits = function(l) | |||
| 73 | local bits = {} | 72 | local bits = {} |
| 74 | local last = 1 | 73 | local last = 1 |
| 75 | for j = 1, #l do | 74 | for j = 1, #l do |
| 76 | if '/' == string.sub(l, j, j) then | 75 | if '/' == l:sub(j, j) then |
| 77 | table.insert(bits, string.sub(l, last, j - 1)) | 76 | table.insert(bits, l:sub(last, j - 1)) |
| 78 | last = j + 1 | 77 | last = j + 1 |
| 79 | end | 78 | end |
| 80 | end | 79 | end |
| 81 | return bits, string.sub(l, last) | 80 | return bits, l:sub(last) |
| 82 | end | 81 | end |
| 83 | 82 | ||
| 84 | 83 | ||
| @@ -97,7 +96,7 @@ local toFile = function(name, key, value) | |||
| 97 | end | 96 | end |
| 98 | Files[name].path = path | 97 | Files[name].path = path |
| 99 | -- Files[name].body = '' | 98 | -- Files[name].body = '' |
| 100 | if ("Foswiki" == bits[1]) or ("PmWiki" == bits[1]) then Files[name].ogWiki = bits[1] end | 99 | if ('Foswiki' == bits[1]) or ('PmWiki' == bits[1]) then Files[name].ogWiki = bits[1] end |
| 101 | end | 100 | end |
| 102 | if nil ~= key then Files[name][key] = value end | 101 | if nil ~= key then Files[name][key] = value end |
| 103 | for i, v in ipairs{'metadata', 'bits', } do | 102 | for i, v in ipairs{'metadata', 'bits', } do |
| @@ -105,7 +104,7 @@ local toFile = function(name, key, value) | |||
| 105 | end | 104 | end |
| 106 | -- Open the files and do the initial cleanups. | 105 | -- Open the files and do the initial cleanups. |
| 107 | local body = '' | 106 | local body = '' |
| 108 | if '.md' ~= string.sub(name, -3, -1) then | 107 | if '.md' ~= name:sub(-3, -1) then |
| 109 | h = io.open(name .. '.md', 'r') | 108 | h = io.open(name .. '.md', 'r') |
| 110 | if nil ~= h then | 109 | if nil ~= h then |
| 111 | -- print('Parsing ' .. name .. '.md') | 110 | -- print('Parsing ' .. name .. '.md') |
| @@ -168,7 +167,7 @@ local readMdMd = function(name, metadata) | |||
| 168 | return {} | 167 | return {} |
| 169 | else | 168 | else |
| 170 | for l in h1:lines() do | 169 | for l in h1:lines() do |
| 171 | for k, v in string.gmatch(l, "(%w+)%s*=%s*(.+)") do | 170 | for k, v in l:gmatch'(%w+)%s*=%s*(.+)' do |
| 172 | if nil == v then | 171 | if nil == v then |
| 173 | print(name .. ' ' .. k) | 172 | print(name .. ' ' .. k) |
| 174 | else | 173 | else |
| @@ -190,8 +189,8 @@ local commonLinky = function(l, body, u, url, beg, en, beg0, en0, bump) | |||
| 190 | -- if nil ~= md then | 189 | -- if nil ~= md then |
| 191 | if nil ~= md.realURL then url = md.realURL end | 190 | if nil ~= md.realURL then url = md.realURL end |
| 192 | -- end | 191 | -- end |
| 193 | body = string.sub(body, 1, beg - bump) .. url .. string.sub(body, en0 + 1) | 192 | body = body:sub(1, beg - bump) .. url .. body:sub(en0 + 1) |
| 194 | here = here + string.len(url) | 193 | here = here + url:len() |
| 195 | end | 194 | end |
| 196 | if 1 == bump then | 195 | if 1 == bump then |
| 197 | here = here + 1 | 196 | here = here + 1 |
| @@ -204,6 +203,10 @@ end | |||
| 204 | 203 | ||
| 205 | 204 | ||
| 206 | 205 | ||
| 206 | --[[ | ||
| 207 | ]] | ||
| 208 | |||
| 209 | |||
| 207 | --------------------------------------------------------------------------------- | 210 | --------------------------------------------------------------------------------- |
| 208 | -- Actually start doing things. | 211 | -- Actually start doing things. |
| 209 | 212 | ||
| @@ -217,7 +220,7 @@ end | |||
| 217 | 220 | ||
| 218 | -- Scan the sub folders looking for our files. | 221 | -- Scan the sub folders looking for our files. |
| 219 | local Folder = arg[1] | 222 | local Folder = arg[1] |
| 220 | toSub('') | 223 | toSub'' |
| 221 | if nil == Folder then Folder = '.' end | 224 | if nil == Folder then Folder = '.' end |
| 222 | --GlobalMetaData.root = Folder | 225 | --GlobalMetaData.root = Folder |
| 223 | 226 | ||
| @@ -233,12 +236,12 @@ if nil == Folder then Folder = '.' end | |||
| 233 | A left over .md.md file should have a redirect .HTML page created for it. | 236 | A left over .md.md file should have a redirect .HTML page created for it. |
| 234 | ]] | 237 | ]] |
| 235 | for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md.md" -xtype l -printf "%P\n"'):lines() do | 238 | for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md.md" -xtype l -printf "%P\n"'):lines() do |
| 236 | local metadata = readMdMd(string.sub(l, 1, -4), {}) | 239 | local metadata = readMdMd(l:sub(1, -4), {}) |
| 237 | if nil == metadata.realURL then | 240 | if nil == metadata.realURL then |
| 238 | metadata.realURL = string.sub(l, 1, -7) | 241 | metadata.realURL = l:sub(1, -7) |
| 239 | else | 242 | else |
| 240 | if metadata.realURL ~= string.sub(l, 1, -7) then | 243 | if metadata.realURL ~= l:sub(1, -7) then |
| 241 | metadata.realURL = string.sub(l, 1, -7) | 244 | metadata.realURL = l:sub(1, -7) |
| 242 | -- If this already exists, compare the timestamps, most recent wins. | 245 | -- If this already exists, compare the timestamps, most recent wins. |
| 243 | local time0 = io.popen('ls -l --time-style=+%s "' .. metadata.realURL .. '.md.md" | cut -d \' \' -f 6'):read('l') | 246 | local time0 = io.popen('ls -l --time-style=+%s "' .. metadata.realURL .. '.md.md" | cut -d \' \' -f 6'):read('l') |
| 244 | local time1 = io.popen('ls -l --time-style=+%s "' .. l .. '" | cut -d \' \' -f 6'):read('l') | 247 | local time1 = io.popen('ls -l --time-style=+%s "' .. l .. '" | cut -d \' \' -f 6'):read('l') |
| @@ -263,7 +266,7 @@ for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md | |||
| 263 | local tp = '_fos' | 266 | local tp = '_fos' |
| 264 | local metadata = readMdMd(l, {}) | 267 | local metadata = readMdMd(l, {}) |
| 265 | if nil ~= metadata then | 268 | if nil ~= metadata then |
| 266 | if "PmWiki" == metadata.ogWiki then tp = '_pm' end | 269 | if 'PmWiki' == metadata.ogWiki then tp = '_pm' end |
| 267 | if nil ~= metadata.ogFile then | 270 | if nil ~= metadata.ogFile then |
| 268 | local unsort = 'unsorted/' .. metadata.ogFile | 271 | local unsort = 'unsorted/' .. metadata.ogFile |
| 269 | local a, e = io.open(unsort .. tp .. '.md' , 'r') | 272 | local a, e = io.open(unsort .. tp .. '.md' , 'r') |
| @@ -274,10 +277,10 @@ for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md | |||
| 274 | os.execute('rm ' .. unsort .. tp .. '.md') | 277 | os.execute('rm ' .. unsort .. tp .. '.md') |
| 275 | a, e = io.open(unsort .. tp .. '.HTML', 'w') | 278 | a, e = io.open(unsort .. tp .. '.HTML', 'w') |
| 276 | if nil == a then print('Could not open ' .. unsort .. tp .. '.HTML' .. ' - ' .. e) else | 279 | if nil == a then print('Could not open ' .. unsort .. tp .. '.HTML' .. ' - ' .. e) else |
| 277 | local dst = string.sub(l, 1, -4) .. '.HTML' | 280 | local dst = l:sub(1, -4) .. '.HTML' |
| 278 | local cnt = 1 | 281 | local cnt = 1 |
| 279 | for j = 1, #metadata.ogFile do | 282 | for j = 1, #metadata.ogFile do |
| 280 | if '/' == string.sub(metadata.ogFile, j, j) then cnt = cnt + 1 end | 283 | if '/' == metadata.ogFile:sub(j, j) then cnt = cnt + 1 end |
| 281 | end | 284 | end |
| 282 | dst = string.rep('../', cnt) .. dst | 285 | dst = string.rep('../', cnt) .. dst |
| 283 | a:write( | 286 | a:write( |
| @@ -299,8 +302,8 @@ end | |||
| 299 | -- Look for copied pages from the other wikis. | 302 | -- Look for copied pages from the other wikis. |
| 300 | for l in io.popen('find -L ' .. Folder .. ' -name "*.HTM" -type f,l -printf "%P\n"'):lines() do | 303 | for l in io.popen('find -L ' .. Folder .. ' -name "*.HTM" -type f,l -printf "%P\n"'):lines() do |
| 301 | -- Only do this if .HTM is newer than .md, or .md doesn't exist. | 304 | -- Only do this if .HTM is newer than .md, or .md doesn't exist. |
| 302 | local htime = io.popen("date -ur " .. l .. " +%s"):read('l') | 305 | local htime = io.popen('date -ur ' .. l .. ' +%s'):read('l') |
| 303 | local mtime = io.popen("date -ur " .. string.sub(l, 1, -4) .. "md +%s 2>/dev/null"):read('l') | 306 | local mtime = io.popen('date -ur ' .. l:sub(1, -4) .. 'md +%s 2>/dev/null'):read('l') |
| 304 | if (nil == mtime) or (htime > mtime) then | 307 | if (nil == mtime) or (htime > mtime) then |
| 305 | print('pandoc converting ' .. l .. ' -> ' .. string.sub(l, 1, -4) .. 'md') | 308 | print('pandoc converting ' .. l .. ' -> ' .. string.sub(l, 1, -4) .. 'md') |
| 306 | os.execute('cp ' .. l .. ' ' .. l .. '_ORIGINAL0') | 309 | os.execute('cp ' .. l .. ' ' .. l .. '_ORIGINAL0') |
| @@ -309,20 +312,20 @@ os.execute('cp ' .. l .. ' ' .. l .. '_ORIGINAL0') | |||
| 309 | if nil ~= h then | 312 | if nil ~= h then |
| 310 | local body = h:read('*a') ; h:close() | 313 | local body = h:read('*a') ; h:close() |
| 311 | writeString(l .. '_ORIGINAL1', body) | 314 | writeString(l .. '_ORIGINAL1', body) |
| 312 | if 'Foswiki' == string.sub(l, 1, 7) then | 315 | if 'Foswiki' == l:sub(1, 7) then |
| 313 | -- Strip out the actual content. | 316 | -- Strip out the actual content. |
| 314 | local beg, en = RE.find(body, [['<div id="patternMainContents">']]) if nil ~= beg then body = string.sub(body, en + 1) end | 317 | local beg, en = RE.find(body, [['<div id="patternMainContents">']]) if nil ~= beg then body = body:sub(en + 1) end |
| 315 | beg, en = RE.find(body, [['<div class="patternContent">']]) if nil ~= beg then body = string.sub(body, en + 1) end | 318 | beg, en = RE.find(body, [['<div class="patternContent">']]) if nil ~= beg then body = body:sub(en + 1) end |
| 316 | beg, en = RE.find(body, [['<div class="foswikiTopic">']]) if nil ~= beg then | 319 | beg, en = RE.find(body, [['<div class="foswikiTopic">']]) if nil ~= beg then |
| 317 | if ' -- ' == string.sub(body, en + 1, en + 4) then | 320 | if ' -- ' == body:sub(en + 1, en + 4) then |
| 318 | beg, en = RE.find(body, '[%nl]', en + 4) | 321 | beg, en = RE.find(body, '[%nl]', en + 4) |
| 319 | body = string.sub(body, en + 1) | 322 | body = body:sub(en + 1) |
| 320 | end | 323 | end |
| 321 | end | 324 | end |
| 322 | beg, en = RE.find(body, [['<div class="patternInfo">']]) if nil ~= beg then body = string.sub(body, 1, beg - 1) end | 325 | beg, en = RE.find(body, [['<div class="patternInfo">']]) if nil ~= beg then body = body:sub(1, beg - 1) end |
| 323 | -- beg, en = RE.find(body, [['<div class="foswikiForm foswikiFormStep">']]) if nil ~= beg then body = string.sub(body, 1, en + 1) end | 326 | -- beg, en = RE.find(body, [['<div class="foswikiForm foswikiFormStep">']]) if nil ~= beg then body = body:sub(1, en + 1) end |
| 324 | beg, en = RE.find(body, [['<div class="foswikiAttachments foswikiFormStep" style="overflow:auto">']]) if nil ~= beg then body = string.sub(body, 1, beg - 1) end | 327 | beg, en = RE.find(body, [['<div class="foswikiAttachments foswikiFormStep" style="overflow:auto">']]) if nil ~= beg then body = body:sub(1, beg - 1) end |
| 325 | beg, en = RE.find(body, [['<div class="foswikiSearchResultsPager">']]) if nil ~= beg then body = string.sub(body, 1, beg - 1) end | 328 | beg, en = RE.find(body, [['<div class="foswikiSearchResultsPager">']]) if nil ~= beg then body = body:sub(1, beg - 1) end |
| 326 | -- Some clean ups. | 329 | -- Some clean ups. |
| 327 | local result = RE.compile( [[{~ | 330 | local result = RE.compile( [[{~ |
| 328 | ( | 331 | ( |
| @@ -346,17 +349,17 @@ writeString(l .. '_ORIGINAL1', body) | |||
| 346 | here = beg + 1 | 349 | here = beg + 1 |
| 347 | local beg0, en0 | 350 | local beg0, en0 |
| 348 | local url = nil | 351 | local url = nil |
| 349 | if '"' == string.sub(body, beg - 1, beg - 1) then | 352 | if '"' == body:sub(beg - 1, beg - 1) then |
| 350 | beg0, en0 = RE.find(body, [['"']], en) | 353 | beg0, en0 = RE.find(body, [['"']], en) |
| 351 | url = string.sub(body, en + 1, en0 - 1) | 354 | url = body:sub(en + 1, en0 - 1) |
| 352 | end | 355 | end |
| 353 | if "'" == string.sub(body, beg - 1, beg - 1) then | 356 | if "'" == body:sub(beg - 1, beg - 1) then |
| 354 | beg0, en0 = RE.find(body, [["'"]], en) | 357 | beg0, en0 = RE.find(body, [["'"]], en) |
| 355 | url = string.sub(body, en + 1, en0) | 358 | url = body:sub(en + 1, en0) |
| 356 | end | 359 | end |
| 357 | 360 | ||
| 358 | if nil ~= url then | 361 | if nil ~= url then |
| 359 | if ('pub/' == string.sub(url, 1, 4)) then | 362 | if ('pub/' == url:sub(1, 4)) then |
| 360 | -- FIXME? - evil hack? | 363 | -- FIXME? - evil hack? |
| 361 | url = 'Foswiki/' .. url | 364 | url = 'Foswiki/' .. url |
| 362 | --print('FOSWIKI HTM ' .. url) | 365 | --print('FOSWIKI HTM ' .. url) |
| @@ -376,7 +379,7 @@ writeString(l .. '_ORIGINAL1', body) | |||
| 376 | -- if nil ~= md then | 379 | -- if nil ~= md then |
| 377 | if nil ~= md.realURL then url = md.realURL end | 380 | if nil ~= md.realURL then url = md.realURL end |
| 378 | -- end | 381 | -- end |
| 379 | body = string.sub(body, 1, beg - 1) .. url .. string.sub(body, en0 + 1) | 382 | body = body:sub(1, beg - 1) .. url .. body:sub(en0 + 1) |
| 380 | here = here + #url | 383 | here = here + #url |
| 381 | end | 384 | end |
| 382 | beg, en = RE.find(body, [['https://fos.wiki.devuan.org/']], here) | 385 | beg, en = RE.find(body, [['https://fos.wiki.devuan.org/']], here) |
| @@ -384,12 +387,12 @@ writeString(l .. '_ORIGINAL1', body) | |||
| 384 | end | 387 | end |
| 385 | 388 | ||
| 386 | writeString(l .. '_NEW', body) | 389 | writeString(l .. '_NEW', body) |
| 387 | elseif 'PmWiki' == string.sub(l, 1, 6) then | ||
| 388 | local beg, en = RE.find(body, [['<!--PageText-->']]) if nil ~= beg then body = string.sub(body, en + 2) end | ||
| 389 | beg, en = RE.find(body, [["div id='wikitext'>"]]) if nil ~= beg then body = string.sub(body, en + 2) end | ||
| 390 | beg, en = RE.find(body, [["<div id='printfoot'>"]]) if nil ~= beg then body = string.sub(body, 1, beg - (2 + 9)) end -- There's a </div> to get rid of to. | ||
| 391 | beg, en = RE.find(body, [['<!--HTMLFooter-->']]) if nil ~= beg then body = string.sub(body, 1, beg - 2) end | ||
| 392 | local result = RE.compile( [[{~ | 390 | local result = RE.compile( [[{~ |
| 391 | elseif 'PmWiki' == l:sub(1, 6) then | ||
| 392 | local beg, en = RE.find(body, [['<!--PageText-->']]) if nil ~= beg then body = body:sub(en + 2) end | ||
| 393 | beg, en = RE.find(body, [["div id='wikitext'>"]]) if nil ~= beg then body = body:sub(en + 2) end | ||
| 394 | beg, en = RE.find(body, [["<div id='printfoot'>"]]) if nil ~= beg then body = body:sub(1, beg - (2 + 9)) end -- There's a </div> to get rid of to. | ||
| 395 | beg, en = RE.find(body, [['<!--HTMLFooter-->']]) if nil ~= beg then body = body:sub(1, beg - 2) end | ||
| 393 | ( | 396 | ( |
| 394 | {"class='categorylink'"} -> blank / | 397 | {"class='categorylink'"} -> blank / |
| 395 | {"class='createlink'"} -> blank / | 398 | {"class='createlink'"} -> blank / |
| @@ -425,11 +428,11 @@ writeString(l .. '_ORIGINAL1', body) | |||
| 425 | here = beg + 1 | 428 | here = beg + 1 |
| 426 | local beg0, en0 = RE.find(body, [["'"]], en) | 429 | local beg0, en0 = RE.find(body, [["'"]], en) |
| 427 | -- FIXME? - This might be working around a bug elsewhere. | 430 | -- FIXME? - This might be working around a bug elsewhere. |
| 428 | if "'" == string.sub(body, en0, en0) then en0 = en0 - 1 end | 431 | if "'" == body:sub(en0, en0) then en0 = en0 - 1 end |
| 429 | local url = string.sub(body, en + 1, en0) | 432 | local url = body:sub(en + 1, en0) |
| 430 | if '?n=' == string.sub(url, 1, 3) then | 433 | if '?n=' == url:sub(1, 3) then |
| 431 | url = string.sub(url, 4):gsub('[%a]+%.([%a-]+)', '%1_pm.HTML') | 434 | url = url:sub(4):gsub('[%a]+%.([%a-]+)', '%1_pm.HTML') |
| 432 | elseif ("'" == url) or ('uploads/' == string.sub(url, 1, 8)) then | 435 | elseif ("'" == url) or ('uploads/' == url:sub(1, 8)) then |
| 433 | -- FIXME - evil hack? Yep, evil hack, need to know the depth of the source, which isn't here. | 436 | -- FIXME - evil hack? Yep, evil hack, need to know the depth of the source, which isn't here. |
| 434 | url = 'PmWiki/' .. url | 437 | url = 'PmWiki/' .. url |
| 435 | else | 438 | else |
| @@ -444,19 +447,19 @@ writeString(l .. '_ORIGINAL1', body) | |||
| 444 | end | 447 | end |
| 445 | end | 448 | end |
| 446 | 449 | ||
| 447 | ok, rslt, status = os.execute('pandoc --wrap=preserve -f html -t commonmark_x --self-contained ' .. l .. '_NEW' .. ' >' .. string.sub(l, 1, -4) .. 'md') | 450 | os.execute('pandoc --wrap=preserve -f html -t commonmark_x --self-contained ' .. l .. '_NEW' .. ' >' .. l:sub(1, -4) .. 'md') |
| 448 | end | 451 | end |
| 449 | end | 452 | end |
| 450 | 453 | ||
| 451 | if '.' ~= Folder then | 454 | if '.' ~= Folder then |
| 452 | for l in io.popen('find -L . -name "*.md" -type f,l -printf "%P\n"'):lines() do | 455 | for l in io.popen('find -L . -name "*.md" -type f,l -printf "%P\n"'):lines() do |
| 453 | toFile(string.gsub(l, '%.md$', '')) | 456 | toFile(l:gsub('%.md$', '')) |
| 454 | end | 457 | end |
| 455 | end | 458 | end |
| 456 | 459 | ||
| 457 | -- Can add in a distant folder to, for putting it's results in the current folder. | 460 | -- Can add in a distant folder to, for putting it's results in the current folder. |
| 458 | for l in io.popen('find -L ' .. Folder .. ' -name "*.md" -type f,l -printf "%P\n"'):lines() do | 461 | for l in io.popen('find -L ' .. Folder .. ' -name "*.md" -type f,l -printf "%P\n"'):lines() do |
| 459 | local n = string.gsub(l, '%.md$', '') | 462 | local n = l:gsub('%.md$', '') |
| 460 | if nil == Files[n] then toFile(n) end | 463 | if nil == Files[n] then toFile(n) end |
| 461 | end | 464 | end |
| 462 | 465 | ||
| @@ -482,14 +485,14 @@ for name, file in pairs(Files) do | |||
| 482 | end | 485 | end |
| 483 | end | 486 | end |
| 484 | 487 | ||
| 485 | if '.md' == string.sub(name, -3, -1) then | 488 | if '.md' == name:sub(-3, -1) then |
| 486 | -- This is a metadata only file, no content, stash the matadata. | 489 | -- This is a metadata only file, no content, stash the matadata. |
| 487 | 490 | ||
| 488 | metadata = readMdMd(name, metadata) | 491 | metadata = readMdMd(name, metadata) |
| 489 | if '.md' == name then toSub(path, 'metadata', metadata) | 492 | if '.md' == name then toSub(path, 'metadata', metadata) |
| 490 | elseif '/.md' == string.sub(name, -4, -1) then toSub(path, 'metadata', metadata) | 493 | elseif '/.md' == name:sub(-4, -1) then toSub(path, 'metadata', metadata) |
| 491 | -- else toFile(string.sub(name, 1, -4), 'metadata', metadata) | 494 | -- else toFile(name:sub(1, -4), 'metadata', metadata) |
| 492 | else NewMeta[string.sub(name, 1, -4)] = metadata -- Coz we can't add to Files here. | 495 | else NewMeta[name:sub(1, -4)] = metadata -- Coz we can't add to Files here. |
| 493 | end | 496 | end |
| 494 | Files[name] = nil | 497 | Files[name] = nil |
| 495 | end | 498 | end |
| @@ -505,7 +508,7 @@ end | |||
| 505 | 508 | ||
| 506 | -- Fix up subs now we have all the file bits. | 509 | -- Fix up subs now we have all the file bits. |
| 507 | for name, file in pairs(Files) do | 510 | for name, file in pairs(Files) do |
| 508 | if '.md' ~= string.sub(name, -3, -1) then | 511 | if '.md' ~= name:sub(-3, -1) then |
| 509 | table.insert(Subs[file.path].files, file.bit) | 512 | table.insert(Subs[file.path].files, file.bit) |
| 510 | end | 513 | end |
| 511 | end | 514 | end |
| @@ -539,7 +542,7 @@ local whichPage = function(f) | |||
| 539 | -- Standard files to search for. | 542 | -- Standard files to search for. |
| 540 | for i, v in ipairs{'about', 'readme', 'index', 'homepage', 'mainpage', 'webhome'} do | 543 | for i, v in ipairs{'about', 'readme', 'index', 'homepage', 'mainpage', 'webhome'} do |
| 541 | for j, w in ipairs(Subs[f].files) do | 544 | for j, w in ipairs(Subs[f].files) do |
| 542 | if v == string.lower(w) then | 545 | if v == w:lower() then |
| 543 | fl = w | 546 | fl = w |
| 544 | break | 547 | break |
| 545 | end | 548 | end |
| @@ -631,7 +634,7 @@ for name, file in pairs(Files) do | |||
| 631 | if ('everything' ~= name) then | 634 | if ('everything' ~= name) then |
| 632 | local ln, fw, pw, ts = 'DUNNO', '', '', '' | 635 | local ln, fw, pw, ts = 'DUNNO', '', '', '' |
| 633 | local title, link = whichWiki(metadata) | 636 | local title, link = whichWiki(metadata) |
| 634 | link = string.gsub(link, 'https://', 'HTTPS://') -- Prevent this one from being converted. | 637 | link = link:gsub('https://', 'HTTPS://') -- Prevent this one from being converted. |
| 635 | if 'PmWiki' == metadata.ogWiki then pw = 'PmWiki [' .. title .. '](' .. link .. ')' end | 638 | if 'PmWiki' == metadata.ogWiki then pw = 'PmWiki [' .. title .. '](' .. link .. ')' end |
| 636 | if 'Foswiki' == metadata.ogWiki then fw = 'Foswiki [' .. title .. '](' .. link .. ')' end | 639 | if 'Foswiki' == metadata.ogWiki then fw = 'Foswiki [' .. title .. '](' .. link .. ')' end |
| 637 | if nil ~= metadata.timestamp then ts = metadata.timestamp end | 640 | if nil ~= metadata.timestamp then ts = metadata.timestamp end |
| @@ -647,7 +650,7 @@ for name, file in pairs(Files) do | |||
| 647 | end | 650 | end |
| 648 | end | 651 | end |
| 649 | end | 652 | end |
| 650 | table.sort(Pages, function(a, b) return (string.lower(a) < string.lower(b)) end) | 653 | table.sort(Pages, function(a, b) return (a:lower() < b:lower()) end) |
| 651 | for i, f in ipairs(Pages) do | 654 | for i, f in ipairs(Pages) do |
| 652 | Bdy = Bdy .. f | 655 | Bdy = Bdy .. f |
| 653 | end | 656 | end |
| @@ -667,7 +670,7 @@ SUBS = {} | |||
| 667 | for name, sub in pairs(Subs) do | 670 | for name, sub in pairs(Subs) do |
| 668 | table.insert(SUBS, sub) | 671 | table.insert(SUBS, sub) |
| 669 | end | 672 | end |
| 670 | table.sort(SUBS, function(a, b) return (string.lower(a.path) < string.lower(b.path)) end) | 673 | table.sort(SUBS, function(a, b) return (a.path:lower() < b.path:lower()) end) |
| 671 | for n, sub in pairs(SUBS) do | 674 | for n, sub in pairs(SUBS) do |
| 672 | local name = sub.path | 675 | local name = sub.path |
| 673 | sub.whichPage = whichPage(name) | 676 | sub.whichPage = whichPage(name) |
| @@ -746,51 +749,52 @@ local Writer = Lunamark.writer.html5.new(LunamarkOpts) | |||
| 746 | local lunaLinky = function(url) -- Fix up the links. | 749 | local lunaLinky = function(url) -- Fix up the links. |
| 747 | if ('https://wiki.devuan.org/' ~= url) and ('https://fos.wiki.devuan.org/' ~= url) then | 750 | if ('https://wiki.devuan.org/' ~= url) and ('https://fos.wiki.devuan.org/' ~= url) then |
| 748 | -- TODO - This might be covering up a bug elsewhere. | 751 | -- TODO - This might be covering up a bug elsewhere. |
| 749 | if '/Main/' == string.sub(url, 1, 6) then | 752 | if '/Main/' == url:sub(1, 6) then |
| 750 | local link = linkFrom(Context.path, 'Foswiki/Main') | 753 | local link = linkFrom(Context.path, 'Foswiki/Main') |
| 751 | if '' == link then | 754 | if '' == link then |
| 752 | url = string.sub(url, 7) .. '.HTML' | 755 | url = url:sub(7) .. '.HTML' |
| 753 | else | 756 | else |
| 754 | url = link .. '/' .. string.sub(url, 7) .. '.HTML' | 757 | url = link .. '/' .. url:sub(7) .. '.HTML' |
| 755 | end | 758 | end |
| 756 | end | 759 | end |
| 757 | if '/System/' == string.sub(url, 1, 8) then | 760 | if '/System/' == url:sub(1, 8) then |
| 758 | url = 'https://fos.wiki.devuan.org' .. url | 761 | url = 'https://fos.wiki.devuan.org' .. url |
| 759 | end | 762 | end |
| 760 | for i, p in ipairs{'https://wiki.devuan.org/?n=', 'https://wiki.devuan.org?n=', 'PmWiki/uploads/', 'Foswiki/pub/', 'https://fos.wiki.devuan.org/'} do | 763 | for i, p in ipairs{'https://wiki.devuan.org/?n=', 'https://wiki.devuan.org?n=', 'PmWiki/uploads/', 'Foswiki/pub/', 'https://fos.wiki.devuan.org/'} do |
| 761 | if p == string.sub(url, 1, #p) then | 764 | if p == url:sub(1, #p) then |
| 762 | local ur = string.sub(url, #p + 1) | 765 | local ur = url:sub(#p + 1) |
| 763 | -- TODO - could probably replace some of this mess with RE.gsub() and friends. Meh, it works. | 766 | -- TODO - could probably replace some of this mess with RE.gsub() and friends. Meh, it works. |
| 764 | local f4, f5, tk1 = string.find(ur, '?', 1, true) | 767 | local f4, f5, tk1 = ur:find('?', 1, true) |
| 765 | if fail ~= f4 then | 768 | if fail ~= f4 then |
| 766 | local u = string.sub(ur, 1, f4 - 1) | 769 | local u = ur:sub(1, f4 - 1) |
| 767 | ur = u | 770 | ur = u |
| 768 | end | 771 | end |
| 769 | local md | 772 | local md |
| 770 | if ('fos' == string.sub(p, 9, 11)) or ('Fos' == string.sub(p, 1, 3)) then | 773 | |
| 774 | if ('fos' == p:sub(9, 11)) or ('Fos' == p:sub(1, 3)) then | ||
| 771 | md = readMdMd('Foswiki/' .. ur .. '.md', {}) | 775 | md = readMdMd('Foswiki/' .. ur .. '.md', {}) |
| 772 | else | 776 | else |
| 773 | md = readMdMd('PmWiki/' .. string.gsub(ur, '%.', '/', 1) .. '.md', {}) | 777 | md = readMdMd('PmWiki/' .. ur:gsub('%.', '/', 1) .. '.md', {}) |
| 774 | end | 778 | end |
| 775 | if (nil ~= md) and (nil ~= md.realURL) then url = md.realURL end | 779 | if (nil ~= md) and (nil ~= md.realURL) then url = md.realURL end |
| 776 | 780 | ||
| 777 | if ('https://fos.wiki.devuan.org/bin/' ~= string.sub(url, 1, 32)) and ('https://fos.wiki.devuan.org/System/' ~= string.sub(url, 1, 35)) then | 781 | if ('https://fos.wiki.devuan.org/bin/' ~= url:sub(1, 32)) and ('https://fos.wiki.devuan.org/System/' ~= url:sub(1, 35)) then |
| 778 | local xlnk = xLinks[string.gsub(ur, '%..*', '', 1)] | 782 | local xlnk = xLinks[ur:gsub('%..*', '', 1)] |
| 779 | if nil == Context.path then | 783 | if nil == Context.path then |
| 780 | url = string.gsub(ur, '%.', '/', 1) | 784 | url = ur:gsub('%.', '/', 1) |
| 781 | else | 785 | else |
| 782 | if nil == xlnk then xlnk = string.gsub(string.gsub(ur, '%..*', '', 1), '/.*', '', 1) end | 786 | if nil == xlnk then xlnk = string.gsub(ur:gsub('%..*', '', 1), '/.*', '', 1) end |
| 783 | if '' ~= Context.path then xlnk = linkFrom(Context.path, xlnk) end | 787 | if '' ~= Context.path then xlnk = linkFrom(Context.path, xlnk) end |
| 784 | if '/' == string.sub(xlnk, 1, 1) then xlnk = string.sub(xlnk, 2) end | ||
| 785 | if ('' ~= xlnk) and ('/' ~= string.sub(xlnk, -1)) then xlnk = xlnk .. '/' end | ||
| 786 | if 'DUNNO/' == xlnk then print('OOPS! page not found - @' .. Context.path .. ' / ' .. Context.bit .. '\t' .. url .. ' -> ' .. xlnk .. ' ' .. string.gsub(ur, '.*%.', '', 1) .. '.HTML') end | 788 | if 'DUNNO/' == xlnk then print('OOPS! page not found - @' .. Context.path .. ' / ' .. Context.bit .. '\t' .. url .. ' -> ' .. xlnk .. ' ' .. string.gsub(ur, '.*%.', '', 1) .. '.HTML') end |
| 789 | if '/' == xlnk:sub(1, 1) then xlnk = xlnk:sub(2) end | ||
| 790 | if ('' ~= xlnk) and ('/' ~= xlnk:sub(-1)) then xlnk = xlnk .. '/' end | ||
| 787 | end | 791 | end |
| 788 | -- if (nil ~= md) and (nil ~= md.realURL) then url = md.realURL | 792 | -- if (nil ~= md) and (nil ~= md.realURL) then url = md.realURL |
| 789 | -- else | 793 | -- else |
| 790 | url = xlnk .. string.gsub(ur, '.*%.', '', 1) | 794 | url = xlnk .. ur:gsub('.*%.', '', 1) |
| 791 | -- end | 795 | -- end |
| 792 | if 'PmWiki/uploads/' == p then | 796 | if 'PmWiki/uploads/' == p then |
| 793 | url = '../../' .. p .. string.gsub(ur, '%.', '.', 1) | 797 | url = '../../' .. p .. ur:gsub('%.', '.', 1) |
| 794 | elseif 'Foswiki/pub/' == p then | 798 | elseif 'Foswiki/pub/' == p then |
| 795 | url = '../../' .. p .. ur | 799 | url = '../../' .. p .. ur |
| 796 | else | 800 | else |
| @@ -806,7 +810,7 @@ end | |||
| 806 | function Writer.header(s, level) | 810 | function Writer.header(s, level) |
| 807 | local text = Lunamark.util.rope_to_string(s) | 811 | local text = Lunamark.util.rope_to_string(s) |
| 808 | -- FIXME - Work around a bug in Lunamark? | 812 | -- FIXME - Work around a bug in Lunamark? |
| 809 | text = RE.gsub(text, "{[\\]}", "") | 813 | text = RE.gsub(text, '{[\\]}', '') |
| 810 | return '<h' .. level .. ' id="' .. RE.gsub(text, '{[ ]}', '_') .. '">' .. text .. ' <a style="font-size: 0.42em;" href="#top">🔼</a></h' .. level .. '>' | 814 | return '<h' .. level .. ' id="' .. RE.gsub(text, '{[ ]}', '_') .. '">' .. text .. ' <a style="font-size: 0.42em;" href="#top">🔼</a></h' .. level .. '>' |
| 811 | end | 815 | end |
| 812 | local OgWriterLink = Writer.link -- So we can call the original from within mine, we are just changing the URL. | 816 | local OgWriterLink = Writer.link -- So we can call the original from within mine, we are just changing the URL. |
| @@ -849,7 +853,7 @@ for name, file in pairs(Files) do | |||
| 849 | for i, f in pairs(Subs[file.path].subs) do | 853 | for i, f in pairs(Subs[file.path].subs) do |
| 850 | table.insert(subs, f) | 854 | table.insert(subs, f) |
| 851 | end | 855 | end |
| 852 | table.sort(subs, function(a, b) return (string.lower(a) < string.lower(b)) end) | 856 | table.sort(subs, function(a, b) return (a:lower() < b:lower()) end) |
| 853 | for i, f in ipairs(subs) do | 857 | for i, f in ipairs(subs) do |
| 854 | local pth = file.path | 858 | local pth = file.path |
| 855 | if '' ~= file.path then pth = file.path .. '/' end | 859 | if '' ~= file.path then pth = file.path .. '/' end |
| @@ -861,7 +865,7 @@ for name, file in pairs(Files) do | |||
| 861 | -- Figure out this pages menu links. | 865 | -- Figure out this pages menu links. |
| 862 | metadata.menu = '' | 866 | metadata.menu = '' |
| 863 | if nil == metadata.title then metadata.title = bit end | 867 | if nil == metadata.title then metadata.title = bit end |
| 864 | if nil ~= Subs[file.path].files then table.sort(Subs[file.path].files, function(a, b) return (string.lower(a) < string.lower(b)) end) end | 868 | if nil ~= Subs[file.path].files then table.sort(Subs[file.path].files, function(a, b) return (a:lower() < b:lower()) end) end |
| 865 | for i, f in ipairs(Subs[file.path].files) do | 869 | for i, f in ipairs(Subs[file.path].files) do |
| 866 | local title, url = nil, nil | 870 | local title, url = nil, nil |
| 867 | if '' == file.path then | 871 | if '' == file.path then |
| @@ -872,15 +876,17 @@ for name, file in pairs(Files) do | |||
| 872 | url = Files[file.path .. '/' .. f].metadata.URL | 876 | url = Files[file.path .. '/' .. f].metadata.URL |
| 873 | end | 877 | end |
| 874 | if nil == title then title = f end | 878 | if nil == title then title = f end |
| 879 | |||
| 880 | |||
| 875 | if bit == f then | 881 | if bit == f then |
| 876 | metadata.menu = metadata.menu .. '<p>' .. title .. '</p>' | 882 | metadata.menu = metadata.menu .. '<p>' .. title .. '</p>' |
| 877 | for j, g in ipairs(file.headers) do | 883 | for j, g in ipairs(file.headers) do |
| 878 | local beg, en = RE.find(g, [['{']]) | 884 | local beg, en = RE.find(g, [['{']]) |
| 879 | if nil ~= beg then | 885 | if nil ~= beg then |
| 880 | g = string.sub(g, 1, beg - 2) | 886 | g = g:sub(1, beg - 2) |
| 881 | end | 887 | end |
| 882 | local h = string.sub(RE.gsub(g, '{[#]}', ''), 2) | 888 | local h = string.sub(RE.gsub(g, '{[#]}', ''), 2) |
| 883 | local l = string.len(g) - string.len(h) | 889 | local l = g:len() - h:len() |
| 884 | g = h | 890 | g = h |
| 885 | h = RE.gsub(h, '{[ ]}', ' ') | 891 | h = RE.gsub(h, '{[ ]}', ' ') |
| 886 | -- FIXME - Work around a bug in Lunamark? | 892 | -- FIXME - Work around a bug in Lunamark? |
| @@ -922,7 +928,7 @@ for name, file in pairs(Files) do | |||
| 922 | -- Add a link to the original page. | 928 | -- Add a link to the original page. |
| 923 | if nil ~= metadata.ogURL then | 929 | if nil ~= metadata.ogURL then |
| 924 | local title, link = whichWiki(metadata) | 930 | local title, link = whichWiki(metadata) |
| 925 | link = string.gsub(link, 'https://', 'HTTPS://') -- Prevent this one from being converted. | 931 | link = link:gsub('https://', 'HTTPS://') -- Prevent this one from being converted. |
| 926 | -- TODO - wrap "edit" in a link to actually edit it. PmWiki "?action=edit" Foswiki "https://fos.wiki.devuan.org/bit/edit/" .. page .. "?t=" .. 10 digit random number? | 932 | -- TODO - wrap "edit" in a link to actually edit it. PmWiki "?action=edit" Foswiki "https://fos.wiki.devuan.org/bit/edit/" .. page .. "?t=" .. 10 digit random number? |
| 927 | local edit = 'T' | 933 | local edit = 'T' |
| 928 | if 'PmWiki' == metadata.ogWiki then edit = 'Maybe you can <a href="' .. link .. '?action=edit">edit</a> t' end | 934 | if 'PmWiki' == metadata.ogWiki then edit = 'Maybe you can <a href="' .. link .. '?action=edit">edit</a> t' end |
| @@ -944,7 +950,7 @@ for name, file in pairs(Files) do | |||
| 944 | result = RE.compile ('{~ ({[$][A-Za-z_]+[$]} -> meta / .)* ~}', | 950 | result = RE.compile ('{~ ({[$][A-Za-z_]+[$]} -> meta / .)* ~}', |
| 945 | { | 951 | { |
| 946 | meta = function(a) | 952 | meta = function(a) |
| 947 | a = string.sub(a, 2, -2) | 953 | a = a:sub(2, -2) |
| 948 | local md = metadata[a] | 954 | local md = metadata[a] |
| 949 | if nil == md then | 955 | if nil == md then |
| 950 | md = GlobalMetaData[a] | 956 | md = GlobalMetaData[a] |
