aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authordvs12025-01-19 21:41:47 +1000
committerdvs12025-01-19 21:41:47 +1000
commit58d81d1a6d4dd09a8f19d4c42ab45caae7db030d (patch)
treed93f1d944a74cbdea6cbc3b7ac8feefddda5a3a8
parentClean up the title stuff. (diff)
downloadnotYetAnotherWiki-58d81d1a6d4dd09a8f19d4c42ab45caae7db030d.zip
notYetAnotherWiki-58d81d1a6d4dd09a8f19d4c42ab45caae7db030d.tar.gz
notYetAnotherWiki-58d81d1a6d4dd09a8f19d4c42ab45caae7db030d.tar.bz2
notYetAnotherWiki-58d81d1a6d4dd09a8f19d4c42ab45caae7db030d.tar.xz
Use the wiki print button, filter the wiki HTML early, and use cmark-gfm.
-rwxr-xr-xSuckItFos43
-rwxr-xr-xSuckItPm58
-rw-r--r--TODO.md1
-rwxr-xr-xnotYetAnotherWiki.lua54
4 files changed, 92 insertions, 64 deletions
diff --git a/SuckItFos b/SuckItFos
index 54fc376..b59f6b0 100755
--- a/SuckItFos
+++ b/SuckItFos
@@ -21,16 +21,34 @@ do
21 mkdir -p Foswiki/${base}/`dirname ${file}` 21 mkdir -p Foswiki/${base}/`dirname ${file}`
22 mkdir -p combined/$base 22 mkdir -p combined/$base
23 mkdir -p combined/${base}/`dirname ${file}` 23 mkdir -p combined/${base}/`dirname ${file}`
24 echo "Converting ${URL}/${base}/${file} -> Foswiki/${base}/${file}.md" 24 echo "Converting ${URL}/${base}/${file}?cover=print -> Foswiki/${base}/${file}.md"
25# pandoc -f html -t markdown --self-contained ${URL}/${base}/${file} >Foswiki/${base}/${file}.md 25# pandoc -f html -t markdown --self-contained ${URL}/${base}/${file} >Foswiki/${base}/${file}.md
26 # TODO - try curl, to see what is actually downloaded, and maybe not download unchanged pages. curl to .HTM 26 # TODO - try curl, to see what is actually downloaded, and maybe not download unchanged pages. curl to .HTM
27 # Doesn't help with redownloads, coz natch a dynamic site isn't cached. But I can at least comment out the curl command during testing to save time. 27 # Doesn't help with redownloads, coz natch a dynamic site isn't cached. But I can at least comment out the curl command during testing to save time.
28 curl --silent --no-progress-meter ${URL}/${base}/${file} -o Foswiki/${base}/${file}.HTM 28 curl --silent --no-progress-meter ${URL}/${base}/${file}?cover=print -o Foswiki/${base}/${file}.HTM
29
30 cp Foswiki/${base}/${file}.HTM Foswiki/${base}/${file}.HTM_ORIGINAL
31 csplit -ks Foswiki/${base}/${file}.HTM '%<div id="patternMainContents">%' '/<div class="foswikiAttachments foswikiFormStep" style="overflow:auto">/'
32 if [ -f xx00 ]; then
33 rm Foswiki/${base}/${file}.HTM
34 mv xx00 Foswiki/${base}/${file}.HTM
35 fi
36 sed -i -E Foswiki/${base}/${file}.HTM \
37 -e "s/rel='nofollow'//g" \
38 -e 's/rel="nofollow"//g' \
39 -e "s/target='_blank'//g" \
40 -e "s/class='foswiki[[:alpha:]]*'//g" \
41 -e 's/class="foswikiTopic"/class="FoswikiTopic"/g' \
42 -e 's/class="foswiki[[:alpha:]]*"//g' \
43 -e "s/style='.*;'//g"
44# -e "s/style='background-color: #.*;'//g" \
45# -e "s/style='font-size: .*;'//g"
46
29 pandoc -f html -t commonmark_x --self-contained Foswiki//${base}/${file}.HTM >Foswiki/${base}/${file}.md 47 pandoc -f html -t commonmark_x --self-contained Foswiki//${base}/${file}.HTM >Foswiki/${base}/${file}.md
30 ln -frs Foswiki/${base}/${file}.md combined/${base}/${file}.md
31 cp Foswiki/${base}/${file}.md Foswiki/${base}/${file}.md_ORIGINAL 48 cp Foswiki/${base}/${file}.md Foswiki/${base}/${file}.md_ORIGINAL
32 49
33 csplit -ks Foswiki/${base}/${file}.md '%::: {.foswikiTopic}%' '/::: {.foswikiContentFooter}/' 50# csplit -ks Foswiki/${base}/${file}.md '%::: {.foswikiTopic}%' '/::: {.foswikiContentFooter}/'
51 csplit -ks Foswiki/${base}/${file}.md '%::: {.FoswikiTopic}%' '/::: {.patternInfo}/'
34 if [ -f xx00 ]; then 52 if [ -f xx00 ]; then
35 rm Foswiki/${base}/${file}.md 53 rm Foswiki/${base}/${file}.md
36 mv xx00 Foswiki/${base}/${file}.md 54 mv xx00 Foswiki/${base}/${file}.md
@@ -40,21 +58,16 @@ do
40 sed -i -E Foswiki/${base}/${file}.md \ 58 sed -i -E Foswiki/${base}/${file}.md \
41 -e 's/\$/\$dlr\$/g' \ 59 -e 's/\$/\$dlr\$/g' \
42 -e 's/\{#.*\}//g' \ 60 -e 's/\{#.*\}//g' \
43 -e 's/\{\.foswiki.*\}//g' \
44 -e 's/\{\.foswiki.*//g' \
45 -e 's/\{\.foswikiNewLink rel=“nofollow”\}//g' \
46 -e 's/\{\.foswikiNewLink$//g' \
47 -e 's/^\.foswiki.*\}//g' \
48 -e 's/\{\.pattern.*\}//g' \ 61 -e 's/\{\.pattern.*\}//g' \
49 -e 's/\{\.pattern.*//g' \ 62 -e 's/\{\.pattern.*//g' \
50 -e 's/\{rel="nofollow"\}//g' \ 63 -e '/^<!-- -->/d' \
51 -e 's/^rel="nofollow"\}//g' \
52 -e 's/rel=“nofollow”\}$//g' \
53 -e '/^:::/d' 64 -e '/^:::/d'
54 echo -e "****\n[Original page](${URL}/${base}/${file}) where you can edit it." >> Foswiki/${base}/${file}.md 65 echo -e "****\n[Original page](${URL}/${base}/${file}) where maybe you can edit it." >> Foswiki/${base}/${file}.md
55 66
56# pandoc -t html -f commonmark_x --self-contained Foswiki/${base}/${file}.md > Foswiki//${base}/${file}.htm 67# pandoc -t html -f commonmark_x --self-contained Foswiki/${base}/${file}.md > Foswiki/${base}/${file}.htm
57 cmark-gfm -t html -e footnotes -e table -e strikethrough Foswiki/${base}/${file}.md > Foswiki//${base}/${file}.body 68# cmark-gfm -t html -e footnotes -e table -e strikethrough Foswiki/${base}/${file}.md > Foswiki/${base}/${file}.body
69# ln -frs Foswiki/${base}/${file}.body combined/${base}/${file}.body
70 ln -frs Foswiki/${base}/${file}.md combined/${base}/${file}.md
58done 71done
59 72
60notYetAnotherWiki.lua 73notYetAnotherWiki.lua
diff --git a/SuckItPm b/SuckItPm
index 64591c3..156ee9f 100755
--- a/SuckItPm
+++ b/SuckItPm
@@ -19,30 +19,44 @@ do
19 file=`echo "${line}" | cut -d '.' -f 2` 19 file=`echo "${line}" | cut -d '.' -f 2`
20 mkdir -p PmWiki/$base 20 mkdir -p PmWiki/$base
21 mkdir -p combined/$base 21 mkdir -p combined/$base
22 echo "Converting ${URL}/?n=${base}.${file} -> PmWiki/${base}/${file}.md" 22 echo "Converting ${URL}/?n=${base}.${file}?action=print -> PmWiki/${base}/${file}.md"
23# pandoc -f html -t markdown --self-contained ${URL}/?n=${base}.${file} >PmWiki/${base}/${file}.md 23# pandoc -f html -t markdown --self-contained ${URL}/?n=${base}.${file} >PmWiki/${base}/${file}.md
24 # TODO - try curl, to see what is actually downloaded, and maybe not download unchanged pages. curl to .HTM 24 # TODO - try curl, to see what is actually downloaded, and maybe not download unchanged pages. curl to .HTM
25 # Doesn't help with redownloads, coz natch a dynamic site isn't cached. But I can at least comment out the curl command during testing to save time. 25 # Doesn't help with redownloads, coz natch a dynamic site isn't cached. But I can at least comment out the curl command during testing to save time.
26# curl --no-progress-meter ${URL}/?n=${base}.${file} -o PmWiki/${base}/${file}.HTM 26# curl --no-progress-meter ${URL}/?n=${base}.${file} -o PmWiki/${base}/${file}.HTM
27 curl --no-progress-meter ${URL}/?n=${base}.${file}?action=markdown -o PmWiki/${base}/${file}.MD 27# curl --no-progress-meter ${URL}/?n=${base}.${file}?action=markdown -o PmWiki/${base}/${file}.MD
28# pandoc -f html -t commonmark_x --self-contained PmWiki//${base}/${file}.HTM >PmWiki/${base}/${file}.md 28 curl --no-progress-meter ${URL}/?n=${base}.${file}?action=print -o PmWiki/${base}/${file}.HTM
29 pandoc -f markdown -t commonmark_x --self-contained PmWiki//${base}/${file}.MD >PmWiki/${base}/${file}.md 29 cp PmWiki/${base}/${file}.HTM PmWiki/${base}/${file}.HTM_ORIGINAL
30 ln -frs PmWiki/${base}/${file}.md combined/${base}/${file}.md 30 csplit -ks PmWiki/${base}/${file}.HTM '%<!--PageText-->%' '/<!--HTMLFooter-->/'
31 cp PmWiki/${base}/${file}.md PmWiki/${base}/${file}.md_ORIGINAL
32
33 csplit -ks PmWiki/${base}/${file}.md '%trailstart%' '/trailend/'
34# csplit -ks PmWiki/${base}/${file}.md '%::: {#wikitext}%' '/::: {#wikifoot-links .footnav}/'
35 if [ -f xx00 ]; then 31 if [ -f xx00 ]; then
36 rm PmWiki/${base}/${file}.md 32 rm PmWiki/${base}/${file}.HTM
37 mv xx00 PmWiki/${base}/${file}.md 33 mv xx00 PmWiki/${base}/${file}.HTM
38 fi 34 fi
35 sed -i -E PmWiki/${base}/${file}.HTM \
36 -e "s/rel='nofollow'//g" \
37 -e "s/target='_blank'//g" \
38 -e "s/class='createlink'//g" \
39 -e "s/class='createlinktext'//g" \
40 -e "s/class='escaped'//g" \
41 -e "s/class='diffmarkup'//g" \
42 -e "s/class='selflink'//g" \
43 -e "s/class='urllink'//g" \
44 -e "s/class='vspace'//g" \
45 -e "s/class='wikilink'//g" \
46 -e "s/style='.*;'//g"
47# -e "s/class='.*'//g" \
48# -e "s/style='background-color: #.*;'//g" \
49# -e "s/style='font-size: .*;'//g"
50
51 pandoc -f html -t commonmark_x --self-contained PmWiki//${base}/${file}.HTM >PmWiki/${base}/${file}.md
52# pandoc -f markdown -t commonmark_x --self-contained PmWiki//${base}/${file}.MD >PmWiki/${base}/${file}.md
53 cp PmWiki/${base}/${file}.md PmWiki/${base}/${file}.md_ORIGINAL
39 54
40 # Attempt to clean things up, badly. 55 # Attempt to clean things up, badly.
41 sed -i -E PmWiki/${base}/${file}.md \ 56 sed -i -E PmWiki/${base}/${file}.md \
42 -e 's/\$/\$dlr\$/g' \ 57 -e 's/\$/\$dlr\$/g' \
43 -e 's/\{#.*\}//g' \ 58 -e 's/\{#.*\}//g' \
44 -e '/^:::/d' \ 59 -e '/^:::/d' \
45 -e '/\{\.wikilink\}/d' \
46 -e '/\[Site$/d' \ 60 -e '/\[Site$/d' \
47 -e '/^Page last modified on /d' \ 61 -e '/^Page last modified on /d' \
48 -e '/^\[\]/d' \ 62 -e '/^\[\]/d' \
@@ -52,22 +66,12 @@ do
52 -e "s/^\`\`\`//g" \ 66 -e "s/^\`\`\`//g" \
53 -e "s/\`\{=html\}//g" 67 -e "s/\`\{=html\}//g"
54 68
55# -e 's/\{rel=".*\}//g' \ 69 echo -e "****\n[Original page](${URL}/${base}/${file}) where maybe you can edit it." >> PmWiki/${base}/${file}.md
56# -e 's/\{rel="nofollow"$//g' \
57# -e 's/^rel="nofollow"\}//g' \
58# -e 's/^target="_blank"\}//g' \
59# -e 's/\{\.createlinktext.*\}//g' \
60# -e 's/\{\.createlinktext$//g' \
61# -e 's/\{\.createlink.*\}//g' \
62# -e 's/\{\.createlink$//g' \
63# -e 's/\{\.urllink.*\}//g' \
64# -e 's/\{\.urllink$//g'
65
66#echo "<hr/><p><a href=\"${URL}/?n=${base}.${file}\">Original page</a> where you can edit it.</p>" >> PmWiki/${base}/${file}.md
67 echo -e "****\n[Original page](${URL}/${base}/${file}) where you can edit it." >> PmWiki/${base}/${file}.md
68 70
69# pandoc -t html -f commonmark_x --self-contained PmWiki/${base}/${file}.md > PmWiki//${base}/${file}.htm 71# pandoc -t html -f commonmark_x --self-contained PmWiki/${base}/${file}.md > PmWiki/${base}/${file}.htm
70 cmark-gfm -t html -e footnotes -e table -e strikethrough PmWiki/${base}/${file}.md > PmWiki//${base}/${file}.body 72# cmark-gfm -t html -e footnotes -e table -e strikethrough PmWiki/${base}/${file}.md > PmWiki/${base}/${file}.body
73# ln -frs PmWiki/${base}/${file}.body combined/${base}/${file}.body
74 ln -frs PmWiki/${base}/${file}.md combined/${base}/${file}.md
71done 75done
72 76
73notYetAnotherWiki.lua 77notYetAnotherWiki.lua
diff --git a/TODO.md b/TODO.md
index 773c3c9..2062323 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,7 +1,6 @@
1# TODO 1# TODO
2## Do these 2## Do these
3 3
4See if any wiki specific MarkDown outputting modules can help. Already installed one for PmWiki, which works now. See if I can find something similar for Foswiki.
5 4
6Check the timestamps on the files, only update if source is newer than destination. Meh, it's already 600 times faster than the pandoc version. 5Check the timestamps on the files, only update if source is newer than destination. Meh, it's already 600 times faster than the pandoc version.
7- One quirk to watch for is if a URL path changes, the docs that have that URL need to be redone. 6- One quirk to watch for is if a URL path changes, the docs that have that URL need to be redone.
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua
index d592d06..c7b205d 100755
--- a/notYetAnotherWiki.lua
+++ b/notYetAnotherWiki.lua
@@ -24,11 +24,16 @@ local Sites, Files, Subs = {}, {}, {}
24-- Useful functions, part 0. 24-- Useful functions, part 0.
25 25
26-- A simple table.subtable = subtable wont work, you end up with a reference so that changes to the later get applaid to the former. 26-- A simple table.subtable = subtable wont work, you end up with a reference so that changes to the later get applaid to the former.
27local copyTable = function(t, strip) 27local derefiTable = function(t, strip)
28 local argh = {} 28 local argh = {}
29 for l, y in ipairs(t) do if (l ~= y.name) and strip then table.insert(argh, y) end end 29 for l, y in ipairs(t) do if (l ~= y.name) and strip then table.insert(argh, y) end end
30 return argh 30 return argh
31end 31end
32local derefTable = function(t, strip)
33 local argh = {}
34 for l, y in pairs(t) do argh[l] = y end
35 return argh
36end
32 37
33 38
34-- String together the bits array into a path string. 39-- String together the bits array into a path string.
@@ -79,7 +84,7 @@ for name, file in pairs(Files) do
79 path = path .. d 84 path = path .. d
80 if nil == Subs[path] then Subs[path] = {files = {}, subs = {}} end 85 if nil == Subs[path] then Subs[path] = {files = {}, subs = {}} end
81 if i < ln then Subs[path].subs[bits[i + 1]] = bits[i + 1] end 86 if i < ln then Subs[path].subs[bits[i + 1]] = bits[i + 1] end
82 Subs[path].bits = copyTable(bits, true) 87 Subs[path].bits = derefiTable(bits, true)
83 if i < ln then table.remove(Subs[path].bits, #bits) end 88 if i < ln then table.remove(Subs[path].bits, #bits) end
84 end 89 end
85 90
@@ -97,10 +102,14 @@ for name, file in pairs(Files) do
97 Files[name] = nil 102 Files[name] = nil
98 else 103 else
99 -- Ordinary md file, stash it's metadata and parsed body. 104 -- Ordinary md file, stash it's metadata and parsed body.
100 h = io.open(name .. '.body', 'r') 105 -- I need cmark-gfm, coz lcmark doesn't support tables and stuff, it only does basic cmark.
106 -- Have to strip out the metadata first, coz cmark-gfm doesn't grok that.
107 h = io.popen('cp "' .. name .. '.md" "' .. name .. '02" ; csplit -ksz -f "' .. name .. '" "' .. name .. '.md" "/^---$/+1" "{1}" 2>/dev/null ; rm "' .. name .. '00" ; rm "' .. name .. '01" 2>/dev/null')
108 if nil ~= h then h:close() end
109 h = io.popen('cmark-gfm -t html -e footnotes -e table -e strikethrough -e autolink -e tagfilter -e tasklist "' .. name .. '02" ; rm "' .. name .. '02"')
101 if nil ~= h then body = h:read('*a') ; h:close() end 110 if nil ~= h then body = h:read('*a') ; h:close() end
102 file.metadata = metadata 111 Files[name].metadata = metadata
103 file.body = body 112 Files[name].body = body
104 table.insert(Subs[path].files, bit) 113 table.insert(Subs[path].files, bit)
105 end 114 end
106end 115end
@@ -113,23 +122,26 @@ end
113-- NOTE - only looking for the .md files we scanned for before, any stray HTML, html, HTM, and htm files will get ignored. 122-- NOTE - only looking for the .md files we scanned for before, any stray HTML, html, HTM, and htm files will get ignored.
114local whichPage = function(f) 123local whichPage = function(f)
115 local fl = '' 124 local fl = ''
116 if (nil ~= Subs[f]) and (nil ~= Subs[f].files) then 125 if nil ~= Subs[f] then
117 if 1 == #(Subs[f].files) then fl = Subs[f].files[1] else 126 if nil ~= Subs[f].whichPage then return Subs[f].whichPage end
118 -- Standard files to search for. 127 if nil ~= Subs[f].files then
119 for i, v in ipairs{'about', 'readme', 'index', 'homepage', 'mainpage', 'webhome'} do 128 if 1 == #(Subs[f].files) then fl = Subs[f].files[1] else
120 for j, w in ipairs(Subs[f].files) do 129 -- Standard files to search for.
121 if v == string.lower(w) then 130 for i, v in ipairs{'about', 'readme', 'index', 'homepage', 'mainpage', 'webhome'} do
122 fl = w 131 for j, w in ipairs(Subs[f].files) do
123 break 132 if v == string.lower(w) then
133 fl = w
134 break
135 end
124 end 136 end
137 if '' ~= fl then break end
125 end 138 end
126 if '' ~= fl then break end 139 -- If nothing else, just grab the first one.
140 if ('' == fl) and (nil ~= Subs[f].files[1]) then fl = Subs[f].files[1] end
127 end 141 end
128 -- If nothing else, just grab the first one.
129 if ('' == fl) and (nil ~= Subs[f].files[1]) then fl = Subs[f].files[1] end
130 end 142 end
131 end 143 end
132 if '' ~= fl then fl = fl .. '.HTML' end 144 if '' ~= fl then fl = fl .. '.HTML' ; Subs[f].whichPage = fl end
133 return fl 145 return fl
134end 146end
135 147
@@ -167,7 +179,7 @@ end
167-- Loop through the files we found and actually create their HTML files. 179-- Loop through the files we found and actually create their HTML files.
168for name, file in pairs(Files) do 180for name, file in pairs(Files) do
169 local path, result = '', '' 181 local path, result = '', ''
170 local body, metadata = Files[name].body, Files[name].metadata 182 local body, metadata = Files[name].body, derefTable(Files[name].metadata, true)
171 local bits, bit = Files[name].bits, Files[name].bit 183 local bits, bit = Files[name].bits, Files[name].bit
172 local ln = #bits 184 local ln = #bits
173 185
@@ -237,7 +249,6 @@ for name, file in pairs(Files) do
237 249
238 -- Figure out this pages menu links. 250 -- Figure out this pages menu links.
239 metadata.menu = '' 251 metadata.menu = ''
240 if nil == metadata.title then metadata.title = metadata.pagetitle end
241 if nil == metadata.title then metadata.title = bit end 252 if nil == metadata.title then metadata.title = bit end
242 if nil ~= Subs[path].files then table.sort(Subs[path].files, function(a, b) return (string.lower(a) < string.lower(b)) end) end 253 if nil ~= Subs[path].files then table.sort(Subs[path].files, function(a, b) return (string.lower(a) < string.lower(b)) end) end
243 for i, f in ipairs(Subs[path].files) do 254 for i, f in ipairs(Subs[path].files) do
@@ -298,6 +309,7 @@ for name, file in pairs(Files) do
298 result = lcmark.apply_template(template, metadata) 309 result = lcmark.apply_template(template, metadata)
299 end 310 end
300 else 311 else
312 print('No template for ' .. name)
301 result = body 313 result = body
302 end 314 end
303 315
@@ -312,8 +324,8 @@ for name, file in pairs(Files) do
312 end 324 end
313 end 325 end
314 326
315 else 327-- else
316 print('') 328-- print('')
317 end 329 end
318end 330end
319 331