aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/notYetAnotherWiki.lua
diff options
context:
space:
mode:
authordvs12025-03-26 16:50:33 +1000
committerdvs12025-03-26 16:50:33 +1000
commit6295a00373185409523dca47467bd4e33c4ec155 (patch)
treecc3166195f2f1f81aac1f6e7bdec8f0660ca6b69 /notYetAnotherWiki.lua
parentMinor TODO += 2 (diff)
downloadnotYetAnotherWiki-6295a00373185409523dca47467bd4e33c4ec155.zip
notYetAnotherWiki-6295a00373185409523dca47467bd4e33c4ec155.tar.gz
notYetAnotherWiki-6295a00373185409523dca47467bd4e33c4ec155.tar.bz2
notYetAnotherWiki-6295a00373185409523dca47467bd4e33c4ec155.tar.xz
realURL stuff.
Document it, and fix up the multiples.
Diffstat (limited to 'notYetAnotherWiki.lua')
-rwxr-xr-xnotYetAnotherWiki.lua40
1 files changed, 30 insertions, 10 deletions
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]
220toSub('') 220toSub('')
221if nil == Directory then Directory = '.' end 221if nil == Directory then Directory = '.' end
222 222
223-- Sort out realURL for symlinked .md.md files. 223--[[ 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 starts out being the path to the downloaded file and friends.
226 If we make a symlink during SuckIt, then that gets updated to point to the place the symlink is in.
227 below we compare timestamps and select the latest version if there's more than one symlink.
228 For the "page symlinked" problem, this should work if realURL is kept updated.
229 For the "page copied" problem, this should work if realURL is kept updated, same as symlinked really, coz that's just another copy.
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 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]]
224for l in io.popen('find -L ' .. Directory .. ' -name unsorted -prune -o -name "*.md.md" -xtype l -printf "%P\n"'):lines() do 233for l in io.popen('find -L ' .. Directory .. ' -name unsorted -prune -o -name "*.md.md" -xtype l -printf "%P\n"'):lines() do
225 local metadata = readMdMd(string.sub(l, 1, -4), {}) 234 local metadata = readMdMd(string.sub(l, 1, -4), {})
226-- FIXME - if this already exists, compare the timestamps, most recent wins. 235 if nil == metadata.realURL then
227 metadata.realURL = string.sub(l, 1, -7) 236 metadata.realURL = string.sub(l, 1, -7)
228 local a, e = io.open(l, 'w') 237 else
229 if nil == a then print('Could not open ' .. l .. ' - ' .. e) else 238 if metadata.realURL ~= string.sub(l, 1, -7) then
230 for k, v in pairs(metadata) do 239 -- If this already exists, compare the timestamps, most recent wins.
231 a:write(k .. '=' .. v .. '\n') 240 local time0 = io.popen('ls -l --time-style=+%s "' .. metadata.realURL .. '.md.md" | cut -d \' \' -f 6'):read('l')
241 local time1 = io.popen('ls -l --time-style=+%s "' .. l .. '" | cut -d \' \' -f 6'):read('l')
242 if time0 > time1 then metadata = nil end
243 else metadata = nil end
244 end
245
246 if nil ~= metadata then
247-- DUNNO if this writes to the original file, or overwrites the symlink.
248 local a, e = io.open(l, 'w')
249 if nil == a then print('Could not open ' .. l .. ' - ' .. e) else
250 for k, v in pairs(metadata) do
251 a:write(k .. '=' .. v .. '\n')
252 end
253 a:close()
232 end 254 end
233 a:close()
234 end 255 end
235end 256end
236 257
@@ -253,8 +274,7 @@ end
253 274
254-- Look for copied pages from the other wikis. 275-- Look for copied pages from the other wikis.
255for l in io.popen('find -L ' .. Directory .. ' -name "*.HTM" -type f,l -printf "%P\n"'):lines() do 276for l in io.popen('find -L ' .. Directory .. ' -name "*.HTM" -type f,l -printf "%P\n"'):lines() do
256-- TODO - Only do this if .HTM is newer than .md, or .md doesn't exist. 277-- Only do this if .HTM is newer than .md, or .md doesn't exist.
257
258 local htime = io.popen("date -ur " .. l .. " +%s"):read('l') 278 local htime = io.popen("date -ur " .. l .. " +%s"):read('l')
259 local mtime = io.popen("date -ur " .. string.sub(l, 1, -4) .. "md +%s 2>/dev/null"):read('l') 279 local mtime = io.popen("date -ur " .. string.sub(l, 1, -4) .. "md +%s 2>/dev/null"):read('l')
260 if (nil == mtime) or (htime > mtime) then 280 if (nil == mtime) or (htime > mtime) then