From 11e46d4366d933618ad1f83fd555712ba9e8e375 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Fri, 28 Mar 2025 14:29:48 +1000 Subject: Create redirect pages for moved ones. --- notYetAnotherWiki.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'notYetAnotherWiki.lua') diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index 5033d78..eea42a7 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua @@ -230,6 +230,7 @@ if nil == Folder then Folder = '.' end 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. + A left over .md.md file should have a redirect .HTML page created for it. ]] for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md.md" -xtype l -printf "%P\n"'):lines() do local metadata = readMdMd(string.sub(l, 1, -4), {}) @@ -237,6 +238,7 @@ for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md metadata.realURL = string.sub(l, 1, -7) else if metadata.realURL ~= string.sub(l, 1, -7) then + metadata.realURL = string.sub(l, 1, -7) -- 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') @@ -270,6 +272,25 @@ for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md -- Keep the .md.md symlink, delete the rest. os.execute('rm ' .. unsort .. tp .. '.HTML') os.execute('rm ' .. unsort .. tp .. '.md') + a, e = io.open(unsort .. tp .. '.HTML', 'w') + if nil == a then print('Could not open ' .. unsort .. tp .. '.HTML' .. ' - ' .. e) else + local dst = string.sub(l, 1, -4) .. '.HTML' + local cnt = 1 + for j = 1, #metadata.ogFile do + if '/' == string.sub(metadata.ogFile, j, j) then cnt = cnt + 1 end + end + dst = string.rep('../', cnt) .. dst + a:write( +[=[ + +
+Click this if you don't get redirected to the real page - Redirect
+ +]=]) + a:close() + print('REDIRECT ' .. unsort .. tp .. '.HTML \t-> ' .. dst) + end + end end end -- cgit v1.1