aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/notYetAnotherWiki.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xnotYetAnotherWiki.lua25
1 files changed, 13 insertions, 12 deletions
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua
index f12547a..0883d87 100755
--- a/notYetAnotherWiki.lua
+++ b/notYetAnotherWiki.lua
@@ -215,10 +215,11 @@ else
215 print("Can't open everything.md for writing.") 215 print("Can't open everything.md for writing.")
216end 216end
217 217
218-- Scan the subdirectories looking for our files. 218-- Scan the sub folders looking for our files.
219local Directory = arg[1] 219local Folder = arg[1]
220toSub('') 220toSub('')
221if nil == Directory then Directory = '.' end 221if nil == Folder then Folder = '.' end
222--GlobalMetaData.root = Folder
222 223
223--[[ Sort out realURL for symlinked .md.md files. 224--[[ Sort out realURL for symlinked .md.md files.
224 realURL is the generic URL part for this page. By policy it points to whatever is the latest copy / symlink of the original download .md.md. 225 realURL is the generic URL part for this page. By policy it points to whatever is the latest copy / symlink of the original download .md.md.
@@ -230,7 +231,7 @@ if nil == Directory then Directory = '.' end
230 For the "page moved" problem, that'll be the most recent symlink, the old one still has it's symlink pointing to the download .md.md, which gets updated with the current realURL. 231 For the "page moved" problem, that'll be the most recent symlink, the old one still has it's symlink pointing to the download .md.md, which gets updated with the current realURL.
231 So when some external old URL points to someplace a page used to be, it's old symlink points to the up to date download .md.md, and we know where to go to find the page now. 232 So when some external old URL points to someplace a page used to be, it's old symlink points to the up to date download .md.md, and we know where to go to find the page now.
232]] 233]]
233for l in io.popen('find -L ' .. Directory .. ' -name unsorted -prune -o -name "*.md.md" -xtype l -printf "%P\n"'):lines() do 234for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md.md" -xtype l -printf "%P\n"'):lines() do
234 local metadata = readMdMd(string.sub(l, 1, -4), {}) 235 local metadata = readMdMd(string.sub(l, 1, -4), {})
235 if nil == metadata.realURL then 236 if nil == metadata.realURL then
236 metadata.realURL = string.sub(l, 1, -7) 237 metadata.realURL = string.sub(l, 1, -7)
@@ -256,7 +257,7 @@ for l in io.popen('find -L ' .. Directory .. ' -name unsorted -prune -o -name "*
256end 257end
257 258
258-- Clean up unsorted. 259-- Clean up unsorted.
259for l in io.popen('find -L ' .. Directory .. ' -name unsorted -prune -o -name "*.md" -a -not -name "*.md.md" -xtype l -printf "%P\n"'):lines() do 260for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md" -a -not -name "*.md.md" -xtype l -printf "%P\n"'):lines() do
260 local tp = '_fos' 261 local tp = '_fos'
261 local metadata = readMdMd(l, {}) 262 local metadata = readMdMd(l, {})
262 if nil ~= metadata then 263 if nil ~= metadata then
@@ -273,7 +274,7 @@ for l in io.popen('find -L ' .. Directory .. ' -name unsorted -prune -o -name "*
273end 274end
274 275
275-- Look for copied pages from the other wikis. 276-- Look for copied pages from the other wikis.
276for l in io.popen('find -L ' .. Directory .. ' -name "*.HTM" -type f,l -printf "%P\n"'):lines() do 277for l in io.popen('find -L ' .. Folder .. ' -name "*.HTM" -type f,l -printf "%P\n"'):lines() do
277-- Only do this if .HTM is newer than .md, or .md doesn't exist. 278-- Only do this if .HTM is newer than .md, or .md doesn't exist.
278 local htime = io.popen("date -ur " .. l .. " +%s"):read('l') 279 local htime = io.popen("date -ur " .. l .. " +%s"):read('l')
279 local mtime = io.popen("date -ur " .. string.sub(l, 1, -4) .. "md +%s 2>/dev/null"):read('l') 280 local mtime = io.popen("date -ur " .. string.sub(l, 1, -4) .. "md +%s 2>/dev/null"):read('l')
@@ -424,14 +425,14 @@ writeString(l .. '_ORIGINAL1', body)
424 end 425 end
425end 426end
426 427
427if '.' ~= Directory then 428if '.' ~= Folder then
428 for l in io.popen('find -L . -name "*.md" -type f,l -printf "%P\n"'):lines() do 429 for l in io.popen('find -L . -name "*.md" -type f,l -printf "%P\n"'):lines() do
429 toFile(string.gsub(l, '%.md$', '')) 430 toFile(string.gsub(l, '%.md$', ''))
430 end 431 end
431end 432end
432 433
433-- Can add in a distant directory to, for putting it's results in the current directory. 434-- Can add in a distant folder to, for putting it's results in the current folder.
434for l in io.popen('find -L ' .. Directory .. ' -name "*.md" -type f,l -printf "%P\n"'):lines() do 435for l in io.popen('find -L ' .. Folder .. ' -name "*.md" -type f,l -printf "%P\n"'):lines() do
435 local n = string.gsub(l, '%.md$', '') 436 local n = string.gsub(l, '%.md$', '')
436 if nil == Files[n] then toFile(n) end 437 if nil == Files[n] then toFile(n) end
437end 438end
@@ -492,7 +493,7 @@ for name, sub in pairs(Subs) do
492 print("EMPTY " .. name) 493 print("EMPTY " .. name)
493 h = io.open(name .. '/index.md', 'w') 494 h = io.open(name .. '/index.md', 'w')
494 if nil ~= h then 495 if nil ~= h then
495 h:write('This directory has no files.') 496 h:write('This folder has no files.')
496 h:close() 497 h:close()
497 else 498 else
498 print("Can't open " .. name .. '/index.md for writing.') 499 print("Can't open " .. name .. '/index.md for writing.')
@@ -504,7 +505,7 @@ end
504--------------------------------------------------------------------------------- 505---------------------------------------------------------------------------------
505-- These functions assume the above file and sub scan has completed. 506-- These functions assume the above file and sub scan has completed.
506 507
507-- Which page in this directory should we show? 508-- Which page in this folder should we show?
508-- NOTE - only looking for the .md files we scanned for before, any stray HTML, html, HTM, and htm files will get ignored. 509-- NOTE - only looking for the .md files we scanned for before, any stray HTML, html, HTM, and htm files will get ignored.
509local whichPage = function(f) 510local whichPage = function(f)
510 local fl = '' 511 local fl = ''
@@ -547,7 +548,7 @@ local whichWiki = function(metadata)
547end 548end
548 549
549 550
550-- Calculate a link from the source directory to the destination directory. 551-- Calculate a link from the source folder to the destination folder.
551local linkFrom = function(source, dest) 552local linkFrom = function(source, dest)
552 -- Evil hacks! 553 -- Evil hacks!
553 if 'Profiles' == dest then dest = 'PmWiki/Profiles' end 554 if 'Profiles' == dest then dest = 'PmWiki/Profiles' end