diff options
| author | onefang | 2026-02-05 04:42:03 +1000 |
|---|---|---|
| committer | onefang | 2026-02-05 04:42:03 +1000 |
| commit | ff2f4340554b4160f6f8a679fce07e3a0ce46273 (patch) | |
| tree | 1e1f50c36ff3c533d37829d67f98a9f3dc8e4bce | |
| parent | Add polygLua, though not using it just yet. (diff) | |
| download | notYetAnotherWiki-ff2f4340554b4160f6f8a679fce07e3a0ce46273.zip notYetAnotherWiki-ff2f4340554b4160f6f8a679fce07e3a0ce46273.tar.gz notYetAnotherWiki-ff2f4340554b4160f6f8a679fce07e3a0ce46273.tar.bz2 notYetAnotherWiki-ff2f4340554b4160f6f8a679fce07e3a0ce46273.tar.xz | |
Start using polygLua.
| -rwxr-xr-x | notYetAnotherWiki.lua | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index 29fe316..114af16 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua | |||
| @@ -39,7 +39,7 @@ if nil ~= h then | |||
| 39 | Template = h:read('*a') -- NOTE - Lua 5.3 changes to not need the *, but ignores it if it's there. | 39 | Template = h:read('*a') -- NOTE - Lua 5.3 changes to not need the *, but ignores it if it's there. |
| 40 | h:close() | 40 | h:close() |
| 41 | else | 41 | else |
| 42 | print('oops! No such file ' .. 'default.template') | 42 | E('oops! No such file ' .. 'default.template') |
| 43 | end | 43 | end |
| 44 | 44 | ||
| 45 | 45 | ||
| @@ -108,7 +108,7 @@ local toFile = function(name, key, value) | |||
| 108 | if '.md' ~= name:sub(-3, -1) then | 108 | if '.md' ~= name:sub(-3, -1) then |
| 109 | h = io.open(name .. '.md', 'r') | 109 | h = io.open(name .. '.md', 'r') |
| 110 | if nil ~= h then | 110 | if nil ~= h then |
| 111 | -- print('Parsing ' .. name .. '.md') | 111 | -- D('Parsing ' .. name .. '.md') |
| 112 | Context = Files[name] | 112 | Context = Files[name] |
| 113 | body = h:read('*a') ; h:close() | 113 | body = h:read('*a') ; h:close() |
| 114 | -- Deal with my typical double spaced sentence endings, and other things. | 114 | -- Deal with my typical double spaced sentence endings, and other things. |
| @@ -164,13 +164,13 @@ end | |||
| 164 | local readMdMd = function(name, metadata) | 164 | local readMdMd = function(name, metadata) |
| 165 | local h1 = io.open(name .. '.md') | 165 | local h1 = io.open(name .. '.md') |
| 166 | if nil == h1 then | 166 | if nil == h1 then |
| 167 | -- print('Could not open ' .. name .. '.md') | 167 | -- E('Could not open ' .. name .. '.md') |
| 168 | return {} | 168 | return {} |
| 169 | else | 169 | else |
| 170 | for l in h1:lines() do | 170 | for l in h1:lines() do |
| 171 | for k, v in l:gmatch'(%w+)%s*=%s*(.+)' do | 171 | for k, v in l:gmatch'(%w+)%s*=%s*(.+)' do |
| 172 | if nil == v then | 172 | if nil == v then |
| 173 | print(name .. ' ' .. k) | 173 | P(name .. ' ' .. k) |
| 174 | else | 174 | else |
| 175 | metadata[k] = v | 175 | metadata[k] = v |
| 176 | end | 176 | end |
| @@ -184,7 +184,7 @@ end | |||
| 184 | 184 | ||
| 185 | local commonLinky = function(l, body, u, url, beg, en, beg0, en0, bump) | 185 | local commonLinky = function(l, body, u, url, beg, en, beg0, en0, bump) |
| 186 | if nil == url then | 186 | if nil == url then |
| 187 | -- print('OOPS! unknown linky - @' .. l .. '\t\t\t' .. string.sub(body, beg - 9, en) .. ' ' .. string.sub(body, en + 1, en0)) | 187 | -- W('OOPS! unknown linky - @' .. l .. '\t\t\t' .. body:sub(beg - 9, en) .. ' ' .. body:sub(en + 1, en0)) |
| 188 | else | 188 | else |
| 189 | local md = readMdMd(url, {}) | 189 | local md = readMdMd(url, {}) |
| 190 | -- if nil ~= md then | 190 | -- if nil ~= md then |
| @@ -216,7 +216,7 @@ h = io.open('everything.md', 'w') | |||
| 216 | if nil ~= h then | 216 | if nil ~= h then |
| 217 | h:close() | 217 | h:close() |
| 218 | else | 218 | else |
| 219 | print("Can't open everything.md for writing.") | 219 | E"Can't open everything.md for writing." |
| 220 | end | 220 | end |
| 221 | 221 | ||
| 222 | -- Scan the sub folders looking for our files. | 222 | -- Scan the sub folders looking for our files. |
| @@ -253,7 +253,7 @@ for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md | |||
| 253 | if nil ~= metadata then | 253 | if nil ~= metadata then |
| 254 | -- DUNNO if this writes to the original file, or overwrites the symlink. | 254 | -- DUNNO if this writes to the original file, or overwrites the symlink. |
| 255 | local a, e = io.open(l, 'w') | 255 | local a, e = io.open(l, 'w') |
| 256 | if nil == a then print('Could not open ' .. l .. ' - ' .. e) else | 256 | if nil == a then E('Could not open ' .. l .. ' - ' .. e) else |
| 257 | for k, v in pairs(metadata) do | 257 | for k, v in pairs(metadata) do |
| 258 | a:write(k .. '=' .. v .. '\n') | 258 | a:write(k .. '=' .. v .. '\n') |
| 259 | end | 259 | end |
| @@ -277,7 +277,7 @@ for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md | |||
| 277 | os.execute('rm ' .. unsort .. tp .. '.HTML') | 277 | os.execute('rm ' .. unsort .. tp .. '.HTML') |
| 278 | os.execute('rm ' .. unsort .. tp .. '.md') | 278 | os.execute('rm ' .. unsort .. tp .. '.md') |
| 279 | a, e = io.open(unsort .. tp .. '.HTML', 'w') | 279 | a, e = io.open(unsort .. tp .. '.HTML', 'w') |
| 280 | if nil == a then print('Could not open ' .. unsort .. tp .. '.HTML' .. ' - ' .. e) else | 280 | if nil == a then E('Could not open ' .. unsort .. tp .. '.HTML' .. ' - ' .. e) else |
| 281 | local dst = l:sub(1, -4) .. '.HTML' | 281 | local dst = l:sub(1, -4) .. '.HTML' |
| 282 | local cnt = 1 | 282 | local cnt = 1 |
| 283 | for j = 1, #metadata.ogFile do | 283 | for j = 1, #metadata.ogFile do |
| @@ -292,7 +292,7 @@ for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md | |||
| 292 | </html> | 292 | </html> |
| 293 | ]=]) | 293 | ]=]) |
| 294 | a:close() | 294 | a:close() |
| 295 | print('REDIRECT ' .. unsort .. tp .. '.HTML \t-> ' .. dst) | 295 | W('REDIRECT ' .. unsort .. tp .. '.HTML \t-> ' .. dst) |
| 296 | end | 296 | end |
| 297 | 297 | ||
| 298 | end | 298 | end |
| @@ -306,7 +306,7 @@ for l in io.popen('find -L ' .. Folder .. ' -name "*.HTM" -type f,l -printf "%P\ | |||
| 306 | local htime = io.popen('date -ur ' .. l .. ' +%s'):read('l') | 306 | local htime = io.popen('date -ur ' .. l .. ' +%s'):read('l') |
| 307 | local mtime = io.popen('date -ur ' .. l:sub(1, -4) .. 'md +%s 2>/dev/null'):read('l') | 307 | local mtime = io.popen('date -ur ' .. l:sub(1, -4) .. 'md +%s 2>/dev/null'):read('l') |
| 308 | if (nil == mtime) or (htime > mtime) then | 308 | if (nil == mtime) or (htime > mtime) then |
| 309 | print('pandoc converting ' .. l .. ' -> ' .. string.sub(l, 1, -4) .. 'md') | 309 | I('pandoc converting ' .. l .. ' -> ' .. l:sub(1, -4) .. 'md') |
| 310 | os.execute('cp ' .. l .. ' ' .. l .. '_ORIGINAL0') | 310 | os.execute('cp ' .. l .. ' ' .. l .. '_ORIGINAL0') |
| 311 | -- Open the HTM files and do the initial cleanups, then pandoc them. | 311 | -- Open the HTM files and do the initial cleanups, then pandoc them. |
| 312 | h = io.open(l, 'r') | 312 | h = io.open(l, 'r') |
| @@ -363,19 +363,19 @@ writeString(l .. '_ORIGINAL1', body) | |||
| 363 | if ('pub/' == url:sub(1, 4)) then | 363 | if ('pub/' == url:sub(1, 4)) then |
| 364 | -- FIXME? - evil hack? | 364 | -- FIXME? - evil hack? |
| 365 | url = 'Foswiki/' .. url | 365 | url = 'Foswiki/' .. url |
| 366 | --print('FOSWIKI HTM ' .. url) | 366 | --D('FOSWIKI HTM ' .. url) |
| 367 | else | 367 | else |
| 368 | url = nil | 368 | url = nil |
| 369 | end | 369 | end |
| 370 | end | 370 | end |
| 371 | --print('HTM0 ' .. string.sub(body, beg, en + 84) .. ' \t\t') | 371 | --D('HTM0 ' .. body:sub(beg, en + 84) .. ' \t\t') |
| 372 | beg, en, body, here = commonLinky(l, body, 'https://fos.wiki.devuan.org/', url, beg, en, beg0, en0, 1) | 372 | beg, en, body, here = commonLinky(l, body, 'https://fos.wiki.devuan.org/', url, beg, en, beg0, en0, 1) |
| 373 | --if nil ~= en then print('HTM1 ' .. string.sub(body, beg, en + 84) .. ' \t\t') end | 373 | --if nil ~= en then D('HTM1 ' .. body:sub(beg, en + 84) .. ' \t\t') end |
| 374 | --[=[ | 374 | --[=[ |
| 375 | if nil == url then | 375 | if nil == url then |
| 376 | print('OOPS! unknown linky - @' .. l .. '\t\t\t' .. string.sub(body, beg - 9, en) .. ' ' .. string.sub(body, en + 1, en0)) | 376 | W('OOPS! unknown linky - @' .. l .. '\t\t\t' .. body:sub(beg - 9, en) .. ' ' .. body:sub(en + 1, en0)) |
| 377 | else | 377 | else |
| 378 | -- print(' linky - @' .. l .. '\t\t\t' .. string.sub(body, beg - 9, en) .. ' ' .. string.sub(body, en + 1, en0) .. ' -> ' .. url) | 378 | -- I(' linky - @' .. l .. '\t\t\t' .. body:sub(beg - 9, en) .. ' ' .. body:sub(en + 1, en0) .. ' -> ' .. url) |
| 379 | local md = readMdMd(url, {}) | 379 | local md = readMdMd(url, {}) |
| 380 | -- if nil ~= md then | 380 | -- if nil ~= md then |
| 381 | if nil ~= md.realURL then url = md.realURL end | 381 | if nil ~= md.realURL then url = md.realURL end |
| @@ -440,9 +440,9 @@ writeString(l .. '_ORIGINAL1', body) | |||
| 440 | else | 440 | else |
| 441 | url = nil | 441 | url = nil |
| 442 | end | 442 | end |
| 443 | --print('HTM0 ' .. string.sub(body, beg, en + 84) .. ' \t\t') | 443 | --D('HTM0 ' .. body:sub(beg, en + 84) .. ' \t\t') |
| 444 | beg, en, body, here = commonLinky(l, body, "'https://wiki.devuan.org/", url, beg, en, beg0, en0, 0) | 444 | beg, en, body, here = commonLinky(l, body, "'https://wiki.devuan.org/", url, beg, en, beg0, en0, 0) |
| 445 | --if nil ~= en then print('HTM1 ' .. string.sub(body, beg, en + 84) .. ' \t\t') end | 445 | --if nil ~= en then D('HTM1 ' .. body:sub(beg, en + 84) .. ' \t\t') end |
| 446 | end | 446 | end |
| 447 | 447 | ||
| 448 | writeString(l .. '_NEW', body) | 448 | writeString(l .. '_NEW', body) |
| @@ -518,13 +518,13 @@ end | |||
| 518 | -- Find empty subs. | 518 | -- Find empty subs. |
| 519 | for name, sub in pairs(Subs) do | 519 | for name, sub in pairs(Subs) do |
| 520 | if 0 == #sub.files then | 520 | if 0 == #sub.files then |
| 521 | print("EMPTY " .. name) | 521 | W('EMPTY ' .. name) |
| 522 | h = io.open(name .. '/index.md', 'w') | 522 | h = io.open(name .. '/index.md', 'w') |
| 523 | if nil ~= h then | 523 | if nil ~= h then |
| 524 | h:write('This folder has no files.') | 524 | h:write('This folder has no files.') |
| 525 | h:close() | 525 | h:close() |
| 526 | else | 526 | else |
| 527 | print("Can't open " .. name .. '/index.md for writing.') | 527 | E("Can't open " .. name .. '/index.md for writing.') |
| 528 | end | 528 | end |
| 529 | end | 529 | end |
| 530 | end | 530 | end |
| @@ -588,14 +588,14 @@ local linkFrom = function(source, dest) | |||
| 588 | local lnk = '' | 588 | local lnk = '' |
| 589 | if source ~= dest then | 589 | if source ~= dest then |
| 590 | if nil == Subs[source] then | 590 | if nil == Subs[source] then |
| 591 | -- print('!!!! No idea where to find source ' .. source) | 591 | -- W('!!!! No idea where to find source ' .. source) |
| 592 | return 'DUNNO' | 592 | return 'DUNNO' |
| 593 | end | 593 | end |
| 594 | if nil == Subs[dest] then | 594 | if nil == Subs[dest] then |
| 595 | if dest == Subs[source].bit then | 595 | if dest == Subs[source].bit then |
| 596 | return '' | 596 | return '' |
| 597 | else | 597 | else |
| 598 | -- print('!!!! No idea where to find dest ' .. dest .. ' from ' .. Subs[source].path .. ' / ' .. Subs[source].bit) | 598 | -- W('!!!! No idea where to find dest ' .. dest .. ' from ' .. Subs[source].path .. ' / ' .. Subs[source].bit) |
| 599 | return 'DUNNO' | 599 | return 'DUNNO' |
| 600 | end | 600 | end |
| 601 | end | 601 | end |
| @@ -661,7 +661,7 @@ if nil ~= h then | |||
| 661 | h:write(Bdy) | 661 | h:write(Bdy) |
| 662 | h:close() | 662 | h:close() |
| 663 | else | 663 | else |
| 664 | print("Can't open everything.md for writing.") | 664 | E"Can't open everything.md for writing." |
| 665 | end | 665 | end |
| 666 | toFile('everything', 'body', Bdy) | 666 | toFile('everything', 'body', Bdy) |
| 667 | 667 | ||
| @@ -801,9 +801,9 @@ local lunaLinky = function(url, lab, tit) -- Fix up the links. | |||
| 801 | else | 801 | else |
| 802 | if nil == xlnk then xlnk = string.gsub(ur:gsub('%..*', '', 1), '/.*', '', 1) end | 802 | if nil == xlnk then xlnk = string.gsub(ur:gsub('%..*', '', 1), '/.*', '', 1) end |
| 803 | if '' ~= Context.path then xlnk = linkFrom(Context.path, xlnk) end | 803 | if '' ~= Context.path then xlnk = linkFrom(Context.path, xlnk) end |
| 804 | if 'DUNNO/' == xlnk then print('OOPS! page not found - @' .. Context.path .. ' / ' .. Context.bit .. '\t' .. url .. ' -> ' .. xlnk .. ' ' .. string.gsub(ur, '.*%.', '', 1) .. '.HTML') end | ||
| 805 | if '/' == xlnk:sub(1, 1) then xlnk = xlnk:sub(2) end | 804 | if '/' == xlnk:sub(1, 1) then xlnk = xlnk:sub(2) end |
| 806 | if ('' ~= xlnk) and ('/' ~= xlnk:sub(-1)) then xlnk = xlnk .. '/' end | 805 | if ('' ~= xlnk) and ('/' ~= xlnk:sub(-1)) then xlnk = xlnk .. '/' end |
| 806 | if 'DUNNO/' == xlnk then E('OOPS! page not found - @' .. Context.path .. ' / ' .. Context.bit .. '\t' .. url .. ' -> ' .. xlnk .. ' ' .. ur:gsub('.*%.', '', 1) .. '.HTML') end | ||
| 807 | end | 807 | end |
| 808 | -- if (nil ~= md) and (nil ~= md.realURL) then url = md.realURL | 808 | -- if (nil ~= md) and (nil ~= md.realURL) then url = md.realURL |
| 809 | -- else | 809 | -- else |
| @@ -997,8 +997,8 @@ for name, file in pairs(Files) do | |||
| 997 | 997 | ||
| 998 | -- Write the file. | 998 | -- Write the file. |
| 999 | if '' ~= result then | 999 | if '' ~= result then |
| 1000 | -- print('From ' .. name .. '.md -> ' .. base) | ||
| 1001 | writeString(name .. '.HTML', result) | 1000 | writeString(name .. '.HTML', result) |
| 1001 | -- D('From ' .. name .. '.md -> ' .. base) | ||
| 1002 | end | 1002 | end |
| 1003 | end | 1003 | end |
| 1004 | end | 1004 | end |
