diff options
author | dvs1 | 2024-12-22 01:58:55 +1000 |
---|---|---|
committer | dvs1 | 2024-12-22 01:58:55 +1000 |
commit | f83b131a214030e2381f2728e18d300028463447 (patch) | |
tree | 1029aa897f567f77fc6fc08b80c339fd71fa4417 | |
parent | Move the version number into the code. (diff) | |
download | notYetAnotherWiki-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.HTML | 4 | ||||
-rw-r--r-- | index.HTML | 4 | ||||
-rwxr-xr-x | notYetAnotherWiki.lua | 62 | ||||
-rw-r--r-- | testing/index.HTML | 5 |
4 files changed, 39 insertions, 36 deletions
@@ -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"> |
@@ -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 | ||
5 | local globalData = {version = '-0.1', header = '', footer = '', menu = '', ['_'] = ' ', ['dlr'] = '$'} | 5 | local globalData = {version = '-0.1', header = '', footer = '', menu = '', ['_'] = ' ', ['dlr'] = '$'} |
6 | local site = {} | 6 | local site = {} |
7 | local dirs = {} | 7 | |
8 | local createHTML = function(cm, file) | 8 | local createHTML = function(cm, file) |
9 | -- cm = string.gsub(cm, '. ', '. ') | 9 | -- cm = string.gsub(cm, '. ', '. ') |
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> 👣') | 51 | table.insert(trl, '">' .. m .. '</a> 👣') |
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> ' | 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> ' | ||
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 |
110 | end | 116 | end |
111 | 117 | ||
112 | 118 | local directory = arg[1] | |
113 | 119 | if nil == directory then directory = '.' end | |
114 | for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do | 120 | for 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} |
157 | end | 163 | end |
158 | 164 | ||
159 | for k, v in pairs(dirs) do | 165 | for 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” | ||
56 | author: onefang</h2> | ||
57 | <p>I’ve been around since the early sixties, but no one ever noticed. You | ||
58 | really should have tried to pay attention though, I’m awesome. I try to | 55 | really should have tried to pay attention though, I’m awesome. I try to |
59 | help the world, but that’s not what everyone wants me to do. Well, the | 56 | help the world, but that’s not what everyone wants me to do. Well, the |
60 | people in charge of this poor defenseless world of ours.</p> | 57 | people in charge of this poor defenseless world of ours.</p> |