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. --- TODO.md | 5 ----- notYetAnotherWiki.lua | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/TODO.md b/TODO.md index be57fa2..d6f6039 100644 --- a/TODO.md +++ b/TODO.md @@ -7,12 +7,7 @@ Make it perphekd! Fix up linky conversion. DONE, mostly. -- This is the "page moved" problem, but now it's "page copied" and "page linked", a generic solution might work. -- Rethink this, I might be going the wrong way. - Need to deal with real file name versus title. Also symlink name not matching what it points to. -- . Hmmm, might it be good policy to have a single canonical context for each page? The "real URL" .md.md thing? -- . Loop through the manually placed symlinks, adjusting "real URL" as we go. -- + What to do about mulitple symlinks pointing to the same page? Compare timestamps, most recent wins. Add atom feed for single page. Alas cgit only seems to have ATOM feed on the whole repo, not individual files. 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