From bcf74340a276aee6aaf0d0b2d6b07b29e50f0b25 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Wed, 26 Feb 2025 20:08:29 +1000 Subject: YAR - mostly theming and link conversion. Includes the new "hide all but content" icon. --- notYetAnotherWiki.lua | 172 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 143 insertions(+), 29 deletions(-) (limited to 'notYetAnotherWiki.lua') diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index 4207905..29ed9fb 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua @@ -25,7 +25,7 @@ local GlobalMetaData = { --
has alink, link, vlink; CSS has active, link, visited, and hover. devuanDevuanalink = '#03a4ff', devuanDevuanlink = '#0076b6', devuanDevuanvlink = '#6aa4db', devuanDevuanhlink = '#03a4ff', devuanSDevuanalink = '#98c3db', devuanSDevuanlink = '#ffffff', devuanSDevuanvlink = '#ffffff', devuanSDevuanhlink = '#98c3db', - karenPurple = '#8800ff', onefangPurple = '#cc00ff', + karenPurple = '#8800ff', onefangPurple = '#cc00ff', onefangGreen = '#42ff00', PinkFloyd = '#AA00AA', DeepPurple = '#220022', -- From an ancient site of mine, which went from PinkFloyd to DeepPurple as a background gradient. favicon = 'nYAW_icon.png', logo = 'nYAW.png', footer = 'Powered by notYetAnotherWiki version 0.0. ', @@ -155,6 +155,49 @@ end +local readMdMd = function(name, metadata) + local h1 = io.open(name .. '.md') + if nil == h1 then +-- print('Could not open ' .. name .. '.md') + return {} + else + for l in h1:lines() do + for k, v in string.gmatch(l, "(%w+)%s*=%s*(.+)") do + if nil == v then + print(name .. ' ' .. k) + else + metadata[k] = v + end + end + end + end + return metadata +end + + + +local commonLinky = function(l, body, u, url, beg, en, beg0, en0, bump) + if nil == url then +-- print('OOPS! unknown linky - @' .. l .. '\t\t\t' .. string.sub(body, beg - 9, en) .. ' ' .. string.sub(body, en + 1, en0)) + else + local md = readMdMd(url, {}) +-- if nil ~= md then + if nil ~= md.realURL then url = md.realURL end +-- end + body = string.sub(body, 1, beg - bump) .. url .. string.sub(body, en0 + 1) + here = here + string.len(url) + end + if 1 == bump then + here = here + 1 + beg, en = RE.find(body, [['https://fos.wiki.devuan.org/']], here) + else + beg, en = RE.find(body, [["'https://wiki.devuan.org/"]], here) + end + return beg, en, body, here +end + + + --------------------------------------------------------------------------------- -- Actually start doing things. @@ -166,12 +209,25 @@ else print("Can't open everything.md for writing.") end - -- Scan the subdirectories looking for our files. local Directory = arg[1] toSub('') if nil == Directory then Directory = '.' end +-- Sort out realURL for symlinked .md.md files. +for l in io.popen('find -L ' .. Directory .. ' -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') + end + a:close() + end +end + for l in io.popen('find -L ' .. Directory .. ' -name "*.HTM" -type f,l -printf "%P\n"'):lines() do -- print('pandoc converting ' .. l .. ' -> ' .. string.sub(l, 1, -4) .. 'md') -- Open the HTM files and do the initial cleanups, then pandoc them. @@ -203,11 +259,37 @@ for l in io.popen('find -L ' .. Directory .. ' -name "*.HTM" -type f,l -printf " {'rel="nofollow"'} -> blank / {"rel='nofollow'"} -> blank / {"target='_blank'"} -> blank / {"" ([%nl])* } -> blank / - {'style="' ([^"])+ '"'} -> '' / {"style='" ([^'])+ "'"} -> '' / +-- {'style="' ([^"])+ '"'} -> blank / {"style='" ([^'])+ "'"} -> blank / . )* ~}]], { blank = function(a) return '' end } ):match(body) body = result -- body = RE.gsub(body, [=[{""}]=], '') -- FIXME + local here = 1 + beg, en = RE.find(body, [['https://fos.wiki.devuan.org/']], here) + while nil ~= beg do + here = beg + 1 + local beg0, en0 + local url = nil + if '"' == string.sub(body, beg - 1, beg - 1) then + beg0, en0 = RE.find(body, [['"']], en) + url = string.sub(body, en + 1, en0 - 1) + end + if "'" == string.sub(body, beg - 1, beg - 1) then + beg0, en0 = RE.find(body, [["'"]], en) + url = string.sub(body, en + 1, en0) + end + + if nil ~= url then + if ('pub/' == string.sub(url, 1, 4)) then +-- FIXME? - evil hack? + url = 'Foswiki/' .. url + else + url = nil + end + end + beg, en, body, here = commonLinky(l, body, 'https://fos.wiki.devuan.org/', url, beg, en, beg0, en0, 1) + end + writeString(l .. '_NEW', body) elseif 'PmWiki' == string.sub(l, 1, 6) then local beg, en = RE.find(body, [['']]) if nil ~= beg then body = string.sub(body, en + 2) end @@ -230,11 +312,30 @@ for l in io.popen('find -L ' .. Directory .. ' -name "*.HTM" -type f,l -printf " {"class='wikilink'"} -> blank / {'rel="nofollow"'} -> blank / {"rel='nofollow'"} -> blank / {"target='_blank'"} -> blank / - {'style="' ([^"])+ '"'} -> '' / {"style='" ([^'])+ "'"} -> '' / +-- {'style="' ([^"])+ '"'} -> blank / {"style='" ([^'])+ "'"} -> blank / {" " ' .. xlnk .. ' ' .. string.gsub(ur, '.*%.', '', 1) .. '.HTML') end
- url = xlnk .. string.gsub(ur, '.*%.', '', 1) .. '.HTML'
+ if 'DUNNO/' == xlnk then print('OOPS! page not found - @' .. Context.path .. ' / ' .. Context.bit .. '\t' .. url .. ' -> ' .. xlnk .. ' ' .. string.gsub(ur, '.*%.', '', 1) .. '.HTML') end
+ end
+-- if (nil ~= md) and (nil ~= md.realURL) then url = md.realURL
+-- else
+ url = xlnk .. string.gsub(ur, '.*%.', '', 1)
+-- end
+ if 'PmWiki/uploads/' == p then
+ url = '../' .. p .. string.gsub(ur, '%.', '.', 1)
+ elseif 'Foswiki/pub/' == p then
+ url = '../' .. p .. ur
+ else
+ url = url .. '.HTML'
end
end
end
end
- return OgWriterLink(lab, url, tit)
+ return url
+end
+
+local OgWriterLink = Writer.link -- So we can call the original from within mine, we are just changing the URL.
+function Writer.link(lab, url, tit)
+ return OgWriterLink(lab, lunaLinky(url), tit)
end
+local OgWriterImage = Writer.image
+function Writer.image(lab, url, tit)
+ return OgWriterImage(lab, lunaLinky(url), tit)
+end
+
local Parse = Lunamark.reader.markdown.new(Writer, LunamarkOpts)
--
cgit v1.1