diff options
-rwxr-xr-x | notYetAnotherWiki.lua | 21 |
1 files changed, 21 insertions, 0 deletions
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 | |||
230 | 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 copied" problem, this should work if realURL is kept updated, same as symlinked really, coz that's just another copy. |
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 | 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. |
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 | 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. |
233 | A left over .md.md file should have a redirect .HTML page created for it. | ||
233 | ]] | 234 | ]] |
234 | for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md.md" -xtype l -printf "%P\n"'):lines() do | 235 | for l in io.popen('find -L ' .. Folder .. ' -name unsorted -prune -o -name "*.md.md" -xtype l -printf "%P\n"'):lines() do |
235 | local metadata = readMdMd(string.sub(l, 1, -4), {}) | 236 | 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 | |||
237 | metadata.realURL = string.sub(l, 1, -7) | 238 | metadata.realURL = string.sub(l, 1, -7) |
238 | else | 239 | else |
239 | if metadata.realURL ~= string.sub(l, 1, -7) then | 240 | if metadata.realURL ~= string.sub(l, 1, -7) then |
241 | metadata.realURL = string.sub(l, 1, -7) | ||
240 | -- If this already exists, compare the timestamps, most recent wins. | 242 | -- If this already exists, compare the timestamps, most recent wins. |
241 | local time0 = io.popen('ls -l --time-style=+%s "' .. metadata.realURL .. '.md.md" | cut -d \' \' -f 6'):read('l') | 243 | local time0 = io.popen('ls -l --time-style=+%s "' .. metadata.realURL .. '.md.md" | cut -d \' \' -f 6'):read('l') |
242 | local time1 = io.popen('ls -l --time-style=+%s "' .. l .. '" | cut -d \' \' -f 6'):read('l') | 244 | 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 | |||
270 | -- Keep the .md.md symlink, delete the rest. | 272 | -- Keep the .md.md symlink, delete the rest. |
271 | os.execute('rm ' .. unsort .. tp .. '.HTML') | 273 | os.execute('rm ' .. unsort .. tp .. '.HTML') |
272 | os.execute('rm ' .. unsort .. tp .. '.md') | 274 | os.execute('rm ' .. unsort .. tp .. '.md') |
275 | a, e = io.open(unsort .. tp .. '.HTML', 'w') | ||
276 | if nil == a then print('Could not open ' .. unsort .. tp .. '.HTML' .. ' - ' .. e) else | ||
277 | local dst = string.sub(l, 1, -4) .. '.HTML' | ||
278 | local cnt = 1 | ||
279 | for j = 1, #metadata.ogFile do | ||
280 | if '/' == string.sub(metadata.ogFile, j, j) then cnt = cnt + 1 end | ||
281 | end | ||
282 | dst = string.rep('../', cnt) .. dst | ||
283 | a:write( | ||
284 | [=[<!DOCTYPE html> | ||
285 | <html> | ||
286 | <head><meta http-equiv="refresh" content="0; url=]=] .. dst .. [=[\" /></head> | ||
287 | <body><p>Click this if you don't get redirected to the real page - <a href="]=] .. dst .. [=[\">Redirect</a></p></body> | ||
288 | </html> | ||
289 | ]=]) | ||
290 | a:close() | ||
291 | print('REDIRECT ' .. unsort .. tp .. '.HTML \t-> ' .. dst) | ||
292 | end | ||
293 | |||
273 | end | 294 | end |
274 | end | 295 | end |
275 | end | 296 | end |