From 6295a00373185409523dca47467bd4e33c4ec155 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Wed, 26 Mar 2025 16:50:33 +1000 Subject: realURL stuff. Document it, and fix up the multiples. --- notYetAnotherWiki.lua | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'notYetAnotherWiki.lua') diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index f4eebe4..c6628fb 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua @@ -220,17 +220,38 @@ local Directory = arg[1] toSub('') if nil == Directory then Directory = '.' end --- Sort out realURL for symlinked .md.md files. +--[[ Sort out realURL for symlinked .md.md files. + 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. + realURL starts out being the path to the downloaded file and friends. + If we make a symlink during SuckIt, then that gets updated to point to the place the symlink is in. + below we compare timestamps and select the latest version if there's more than one symlink. + For the "page symlinked" problem, this should work if realURL is kept updated. + For the "page copied" problem, this should work if realURL is kept updated, same as symlinked really, coz that's just another copy. + 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. + 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. +]] for l in io.popen('find -L ' .. Directory .. ' -name unsorted -prune -o -name "*.md.md" -xtype l -printf "%P\n"'):lines() do local metadata = readMdMd(string.sub(l, 1, -4), {}) --- FIXME - if this already exists, compare the timestamps, most recent wins. - metadata.realURL = string.sub(l, 1, -7) - local a, e = io.open(l, 'w') - if nil == a then print('Could not open ' .. l .. ' - ' .. e) else - for k, v in pairs(metadata) do - a:write(k .. '=' .. v .. '\n') + if nil == metadata.realURL then + metadata.realURL = string.sub(l, 1, -7) + else + if metadata.realURL ~= string.sub(l, 1, -7) then + -- If this already exists, compare the timestamps, most recent wins. + local time0 = io.popen('ls -l --time-style=+%s "' .. metadata.realURL .. '.md.md" | cut -d \' \' -f 6'):read('l') + local time1 = io.popen('ls -l --time-style=+%s "' .. l .. '" | cut -d \' \' -f 6'):read('l') + if time0 > time1 then metadata = nil end + else metadata = nil end + end + + if nil ~= metadata then +-- DUNNO if this writes to the original file, or overwrites the symlink. + local a, e = io.open(l, 'w') + if nil == a then print('Could not open ' .. l .. ' - ' .. e) else + for k, v in pairs(metadata) do + a:write(k .. '=' .. v .. '\n') + end + a:close() end - a:close() end end @@ -253,8 +274,7 @@ end -- Look for copied pages from the other wikis. for l in io.popen('find -L ' .. Directory .. ' -name "*.HTM" -type f,l -printf "%P\n"'):lines() do --- TODO - Only do this if .HTM is newer than .md, or .md doesn't exist. - +-- Only do this if .HTM is newer than .md, or .md doesn't exist. local htime = io.popen("date -ur " .. l .. " +%s"):read('l') local mtime = io.popen("date -ur " .. string.sub(l, 1, -4) .. "md +%s 2>/dev/null"):read('l') if (nil == mtime) or (htime > mtime) then -- cgit v1.1