aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authordvs12024-12-22 01:58:55 +1000
committerdvs12024-12-22 01:58:55 +1000
commitf83b131a214030e2381f2728e18d300028463447 (patch)
tree1029aa897f567f77fc6fc08b80c339fd71fa4417
parentMove the version number into the code. (diff)
downloadnotYetAnotherWiki-f83b131a214030e2381f2728e18d300028463447.zip
notYetAnotherWiki-f83b131a214030e2381f2728e18d300028463447.tar.gz
notYetAnotherWiki-f83b131a214030e2381f2728e18d300028463447.tar.bz2
notYetAnotherWiki-f83b131a214030e2381f2728e18d300028463447.tar.xz
Bit of code cleanup.
Allow parsing some other directory. Sort the menus. General cleanup.
-rw-r--r--TODO.HTML4
-rw-r--r--index.HTML4
-rwxr-xr-xnotYetAnotherWiki.lua62
-rw-r--r--testing/index.HTML5
4 files changed, 39 insertions, 36 deletions
diff --git a/TODO.HTML b/TODO.HTML
index 70eaac0..8222581 100644
--- a/TODO.HTML
+++ b/TODO.HTML
@@ -38,8 +38,8 @@
38 </tr> 38 </tr>
39 <td rowspan=0 style="background-color: rebeccapurple; text-align:left; white-space:nowrap; vertical-align:top"> 39 <td rowspan=0 style="background-color: rebeccapurple; text-align:left; white-space:nowrap; vertical-align:top">
40 menu for the current directory 40 menu for the current directory
41 <p><a href="index.HTML">index</a></p> 41 <p><a href="TODO.HTML">TODO</a></p>
42<p><a href="TODO.HTML">TODO</a></p> 42<p><a href="index.HTML">index</a></p>
43 43
44 </td> 44 </td>
45 <td style="background-color: rebeccapurple"> 45 <td style="background-color: rebeccapurple">
diff --git a/index.HTML b/index.HTML
index db58d96..53d773b 100644
--- a/index.HTML
+++ b/index.HTML
@@ -38,8 +38,8 @@
38 </tr> 38 </tr>
39 <td rowspan=0 style="background-color: rebeccapurple; text-align:left; white-space:nowrap; vertical-align:top"> 39 <td rowspan=0 style="background-color: rebeccapurple; text-align:left; white-space:nowrap; vertical-align:top">
40 menu for the current directory 40 menu for the current directory
41 <p><a href="index.HTML">index</a></p> 41 <p><a href="TODO.HTML">TODO</a></p>
42<p><a href="TODO.HTML">TODO</a></p> 42<p><a href="index.HTML">index</a></p>
43 43
44 </td> 44 </td>
45 <td style="background-color: rebeccapurple"> 45 <td style="background-color: rebeccapurple">
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua
index 0a616c7..977a117 100755
--- a/notYetAnotherWiki.lua
+++ b/notYetAnotherWiki.lua
@@ -4,10 +4,10 @@ local lcmark = require("lcmark")
4 4
5local globalData = {version = '-0.1', header = '', footer = '', menu = '', ['_'] = '&nbsp;', ['dlr'] = '&dollar;'} 5local globalData = {version = '-0.1', header = '', footer = '', menu = '', ['_'] = '&nbsp;', ['dlr'] = '&dollar;'}
6local site = {} 6local site = {}
7local dirs = {} 7
8local createHTML = function(cm, file) 8local createHTML = function(cm, file)
9-- cm = string.gsub(cm, '. ', '.&nbsp; ') 9-- cm = string.gsub(cm, '. ', '.&nbsp; ')
10 if nil ~= file then print('\nAbout to parse file ' .. file) end 10 if (nil ~= file) and ('' ~= file) then io.write('Parsing ' .. file .. ' -> ') end
11 local result = '' 11 local result = ''
12 local body, metadata, err = lcmark.convert(cm, "html", {smart = true, yaml_metadata = true, columns = 0}) 12 local body, metadata, err = lcmark.convert(cm, "html", {smart = true, yaml_metadata = true, columns = 0})
13 13
@@ -38,7 +38,7 @@ local createHTML = function(cm, file)
38 metadata.menu = '' 38 metadata.menu = ''
39 local trl = {} 39 local trl = {}
40 metadata.trail = '' 40 metadata.trail = ''
41 local dir = dirs[''] 41 local dir = site['']
42 local dr, pdr, tr = '', '', '' 42 local dr, pdr, tr = '', '', ''
43 while nil ~= dir.subs do 43 while nil ~= dir.subs do
44 local old = dir 44 local old = dir
@@ -47,7 +47,7 @@ local createHTML = function(cm, file)
47 pdr = pdr .. '/' .. m 47 pdr = pdr .. '/' .. m
48 tr = tr .. '../' 48 tr = tr .. '../'
49 dr = m 49 dr = m
50 dir = dirs[dr] 50 dir = site[dr]
51 table.insert(trl, '">' .. m .. '</a> &#x1f463;') 51 table.insert(trl, '">' .. m .. '</a> &#x1f463;')
52 break 52 break
53 end 53 end
@@ -62,15 +62,19 @@ local createHTML = function(cm, file)
62 metadata.trail = table.concat(trl) 62 metadata.trail = table.concat(trl)
63 63
64 if nil ~= dir.files then 64 if nil ~= dir.files then
65 for m, x in pairs(dir.files) do 65 local l = {}
66 local u = string.sub(x, 1 + #pdr) 66 for m, x in pairs(dir.files) do table.insert(l, {m = m; x = x}) end
67 metadata.menu = metadata.menu .. '<p><a href="' .. u .. '.HTML">' .. m .. '</a></p>\n' 67 table.sort(l, function(a, b) return (a.m <= b.m) end)
68 for m, x in ipairs(l) do
69 metadata.menu = metadata.menu .. '<p><a href="' .. string.sub(x.x, 1 + #pdr) .. '.HTML">' .. x.m .. '</a></p>\n'
68 end 70 end
69 end 71 end
70 if nil ~= dir.subs then 72 if nil ~= dir.subs then
71 for m, x in pairs(dir.subs) do 73 local l = {}
72 local u = string.sub(x, 1 + #pdr) 74 for m, x in pairs(dir.subs) do table.insert(l, {m = m; x = x}) end
73 metadata.header = metadata.header .. '<a href="' .. u .. '">' .. m .. '</a> &nbsp; ' 75 table.sort(l, function(a, b) return (a.m <= b.m) end)
76 for m, x in pairs(l) do
77 metadata.header = metadata.header .. '<a href="' .. string.sub(x.x, 1 + #pdr) .. '">' .. x.m .. '</a> &nbsp; '
74 end 78 end
75 end 79 end
76 end 80 end
@@ -99,19 +103,21 @@ local createHTML = function(cm, file)
99 103
100 if ('' ~= result) and (nil ~= file) then 104 if ('' ~= result) and (nil ~= file) then
101 local base = string.gsub(file, '%.md$', '') 105 local base = string.gsub(file, '%.md$', '')
102 print('Creating file ' .. base .. '.HTML') 106 print(base .. '.HTML')
103 local a, e = io.open(base .. '.HTML', 'w') 107 local a, e = io.open(base .. '.HTML', 'w')
104 if nil == a then print('Could not open ' .. base .. '.HTML - ' .. e) else 108 if nil == a then print('Could not open ' .. base .. '.HTML - ' .. e) else
105 a:write(result) 109 a:write(result)
106 a:close() 110 a:close()
107 end 111 end
112 else
113 print('')
108 end 114 end
109 return result 115 return result
110end 116end
111 117
112 118local directory = arg[1]
113 119if nil == directory then directory = '.' end
114for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do 120for l in io.popen('find ' .. directory .. ' -name "*.md" -type f -printf "%P\n"'):lines() do
115 local dir = '' 121 local dir = ''
116 local files, subs = {}, {} 122 local files, subs = {}, {}
117 local c, parent = 1, '' 123 local c, parent = 1, ''
@@ -119,44 +125,44 @@ for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do
119 for p in string.gmatch(l, '(%w+)/') do 125 for p in string.gmatch(l, '(%w+)/') do
120 if '' == dir then 126 if '' == dir then
121 dir = p 127 dir = p
122 if nil ~= dirs[dir] then 128 if nil ~= site[dir] then
123 subs = dirs[dir].subs 129 subs = site[dir].subs
124 files = dirs[dir].files 130 files = site[dir].files
125 end 131 end
126 end 132 end
127 133
128 local path = string.sub(l, 1, -1 - #(string.gsub(l, '.*/', ''))) 134 local path = string.sub(l, 1, -1 - #(string.gsub(l, '.*/', '')))
129 if nil ~= dirs[parent] then 135 if nil ~= site[parent] then
130 if nil == dirs[parent].subs then dirs[parent].subs = {} end 136 if nil == site[parent].subs then site[parent].subs = {} end
131 dirs[parent].subs[p] = path 137 site[parent].subs[p] = path
132 elseif 1 == c then subs[p] = path 138 elseif 1 == c then subs[p] = path
133 else 139 else
134 if ('' ~= parent) and (dir == parent) then subs[p] = path end 140 if ('' ~= parent) and (dir == parent) then subs[p] = path end
135 dirs[parent] = {subs = {[p] = path}} 141 site[parent] = {subs = {[p] = path}}
136 end 142 end
137 c = c + #p + 1 143 c = c + #p + 1
138 parent = p 144 parent = p
139 end 145 end
140 146
141 if (1 == c) and (nil ~= dirs[dir]) then 147 if (1 == c) and (nil ~= site[dir]) then
142 subs = dirs[dir].subs 148 subs = site[dir].subs
143 files = dirs[dir].files 149 files = site[dir].files
144 end 150 end
145 151
146 local base = string.gsub(string.sub(l, c, -1), '%.md$', '') 152 local base = string.gsub(string.sub(l, c, -1), '%.md$', '')
147 if nil ~= dirs[parent] then dirs[parent].files[base] = string.sub(l, 1, -4) 153 if nil ~= site[parent] then site[parent].files[base] = string.sub(l, 1, -4)
148 elseif 1 == c then files[base] = string.sub(l, 1, -4) 154 elseif 1 == c then files[base] = string.sub(l, 1, -4)
149 else 155 else
150 if ('' ~= parent) and (dir == parent) then files[base] = string.sub(l, 1, -4) end 156 if ('' ~= parent) and (dir == parent) then files[base] = string.sub(l, 1, -4) end
151 dirs[parent] = {files = {[base] = string.sub(l, 1, -4)}} 157 site[parent] = {files = {[base] = string.sub(l, 1, -4)}}
152 end 158 end
153 159
154-- FIXME - still some minor bug somewhere, this fixes that, but causes other problems. Meh, I can live with excess empty subs tables. 160-- FIXME - still some minor bug somewhere, this fixes that, but causes other problems. Meh, I can live with excess empty subs tables.
155-- if (nil ~= subs) and (0 == #subs) then subs = nil end 161-- if (nil ~= subs) and (0 == #subs) then subs = nil end
156 dirs[dir] = {files = files, subs = subs} 162 site[dir] = {files = files, subs = subs}
157end 163end
158 164
159for k, v in pairs(dirs) do 165for k, v in pairs(site) do
160 if nil ~= v.files then 166 if nil ~= v.files then
161 for m, x in pairs(v.files) do 167 for m, x in pairs(v.files) do
162 local file = x .. '.md' 168 local file = x .. '.md'
diff --git a/testing/index.HTML b/testing/index.HTML
index d10f1af..07ec28f 100644
--- a/testing/index.HTML
+++ b/testing/index.HTML
@@ -51,10 +51,7 @@
51 <div name="contentFrame"> 51 <div name="contentFrame">
52 <h1>G’day world!</h1> 52 <h1>G’day world!</h1>
53 Author: onefang 53 Author: onefang
54 <hr /> 54 <p>I’ve been around since the early sixties, but no one ever noticed.  You
55<h2>pagetitle: “TODO”
56author: onefang</h2>
57<p>I’ve been around since the early sixties, but no one ever noticed.  You
58really should have tried to pay attention though, I’m awesome.  I try to 55really should have tried to pay attention though, I’m awesome.  I try to
59help the world, but that’s not what everyone wants me to do.&nbsp; Well, the 56help the world, but that’s not what everyone wants me to do.&nbsp; Well, the
60people in charge of this poor defenseless world of ours.</p> 57people in charge of this poor defenseless world of ours.</p>