diff options
Diffstat (limited to 'notYetAnotherWiki.lua')
-rwxr-xr-x | notYetAnotherWiki.lua | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index be46646..65137b5 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua | |||
@@ -120,6 +120,109 @@ for k, v in pairs(sites) do | |||
120 | local body, metadata, err = lcmark.convert(cm, "html", {smart = true, yaml_metadata = true, columns = 0}) | 120 | local body, metadata, err = lcmark.convert(cm, "html", {smart = true, yaml_metadata = true, columns = 0}) |
121 | 121 | ||
122 | if nil == body then print('oops! ' .. err) else | 122 | if nil == body then print('oops! ' .. err) else |
123 | |||
124 | |||
125 | if '' == body then | ||
126 | -- A simple v.metadata = metadata wont work, you end up with a reference so that changes to metadata get applied to v.metadata. | ||
127 | v.metadata = {} | ||
128 | for l, y in pairs(metadata) do | ||
129 | v.metadata[l] = y | ||
130 | end | ||
131 | local argh = {} | ||
132 | for l, y in ipairs(v.files) do | ||
133 | if w.name ~= y.name then table.insert(argh, y) end | ||
134 | end | ||
135 | v.files = argh | ||
136 | print('') | ||
137 | else | ||
138 | |||
139 | local bod, err = lcmark.compile_template(body) | ||
140 | if nil == bod then print('oops! ' .. err) else | ||
141 | local templateFile = metadata.template | ||
142 | if nil == file then | ||
143 | templateFile = nil | ||
144 | else | ||
145 | if nil == templateFile then templateFile = 'default' end | ||
146 | templateFile = templateFile .. '.template' | ||
147 | for m, x in pairs(globalData) do if nil == metadata[m] then metadata[m] = x else print('metadata already has ' .. m) end end | ||
148 | if nil ~= v.metadata then | ||
149 | for m, x in pairs(v.metadata) do if nil == metadata[m] then metadata[m] = x else print('metadata already has ' .. m) end end | ||
150 | end | ||
151 | end | ||
152 | |||
153 | if nil ~= v.files then | ||
154 | for m, x in ipairs(v.files) do | ||
155 | metadata.menu = metadata.menu .. x.URL .. '\n' | ||
156 | end | ||
157 | end | ||
158 | if nil ~= v.subs then | ||
159 | for m, x in pairs(v.subs) do | ||
160 | metadata.header = metadata.header .. x.URL | ||
161 | end | ||
162 | end | ||
163 | |||
164 | local num = #(v.bits) | ||
165 | local trail = '<a href="' .. string.rep('../', num) .. '">home</a> ' | ||
166 | local p = v.parent | ||
167 | for i = 1, num do | ||
168 | trail = trail .. '<a href="' .. string.rep('../', num - i) .. '">' .. v.bits[i] .. '</a> ' | ||
169 | end | ||
170 | trail = trail .. w.name | ||
171 | metadata.trail = trail | ||
172 | |||
173 | metadata.body = lcmark.apply_template(bod, metadata) | ||
174 | |||
175 | local tm = '' | ||
176 | if nil ~= templateFile then | ||
177 | local h = io.open(templateFile, 'r') | ||
178 | if nil ~= h then | ||
179 | tm = tm .. h:read('*a') | ||
180 | h:close() | ||
181 | else | ||
182 | print('oops! No such file ' .. templateFile) | ||
183 | end | ||
184 | |||
185 | local template, err = lcmark.compile_template(tm) | ||
186 | if nil == template then print('oops! ' .. err) else | ||
187 | result = lcmark.apply_template(template, metadata) | ||
188 | end | ||
189 | else | ||
190 | result = body | ||
191 | end | ||
192 | |||
193 | if ('' ~= result) and (nil ~= file) then | ||
194 | local base = path .. w.name .. '.HTML' | ||
195 | print(base) | ||
196 | local a, e = io.open(base, 'w') | ||
197 | if nil == a then print('Could not open ' .. base .. ' - ' .. e) else | ||
198 | a:write(result) | ||
199 | a:close() | ||
200 | end | ||
201 | else | ||
202 | print('') | ||
203 | end | ||
204 | end | ||
205 | |||
206 | end | ||
207 | end | ||
208 | |||
209 | h:close() | ||
210 | else | ||
211 | print('oops! No such file ' .. file) | ||
212 | end | ||
213 | |||
214 | end | ||
215 | end | ||
216 | |||
217 | end | ||
218 | |||
219 | local h = io.open(file, 'r') | ||
220 | if nil ~= h then | ||
221 | local cm = h:read('*a') | ||
222 | local result = '' | ||
223 | local body, metadata, err = lcmark.convert(cm, "html", {smart = true, yaml_metadata = true, columns = 0}) | ||
224 | |||
225 | if nil == body then print('oops! ' .. err) else | ||
123 | local bod, err = lcmark.compile_template(body) | 226 | local bod, err = lcmark.compile_template(body) |
124 | if nil == bod then print('oops! ' .. err) else | 227 | if nil == bod then print('oops! ' .. err) else |
125 | local templateFile = metadata.template | 228 | local templateFile = metadata.template |