From 2762f24493e5cb6e7b78ff55d9252ed24398c505 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Sat, 28 Dec 2024 16:02:18 +1000 Subject: TODO-- Directory level metadata files. --- INSTALL.md | 2 - MeTaDaTa.md | 4 ++ README | 6 ++- TODO.md | 4 -- notYetAnotherWiki.lua | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 MeTaDaTa.md diff --git a/INSTALL.md b/INSTALL.md index a4704e9..596f8bf 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,9 +1,7 @@ --- pagetitle: "INSTALL" author: onefang -feedatom: https://sledjhamr.org/cgit/notYetAnotherWiki/atom history: https://sledjhamr.org/cgit/notYetAnotherWiki/log/INSTALL.md -sourcecode: https://sledjhamr.org/cgit/notYetAnotherWiki/ --- notYetAnotherWiki uses [lcmark](https://github.com/jgm/lcmark) to parse [CommonMark](https://commonmark.org/) into HTML. You can probably install it using luarocks. lua-yaml is the YAML parsing library I test with. diff --git a/MeTaDaTa.md b/MeTaDaTa.md new file mode 100644 index 0000000..ab7b673 --- /dev/null +++ b/MeTaDaTa.md @@ -0,0 +1,4 @@ +--- +feedatom: https://sledjhamr.org/cgit/notYetAnotherWiki/atom +sourcecode: https://sledjhamr.org/cgit/notYetAnotherWiki/ +--- diff --git a/README b/README index 82f1538..29e3b63 100644 --- a/README +++ b/README @@ -1,9 +1,7 @@ --- pagetitle: "notYetAnotherWiki" author: onefang -feedatom: https://sledjhamr.org/cgit/notYetAnotherWiki/atom history: https://sledjhamr.org/cgit/notYetAnotherWiki/log/index.md -sourcecode: https://sledjhamr.org/cgit/notYetAnotherWiki/ --- notYetAnotherWiki is not another wiki, at least not yet. It'll be much @@ -70,6 +68,10 @@ Currently it'll scan the current directory and subdirectories looking for variations. Then it produces .HTML files converted from these .md files, and links them all together into a web site. +Any .md file that is just the beginning metadata block doesn't get +rendered into HTML, but is global metadata for this directory and subs, +though the subs can override this with their own metadata.md files. + git is used to store the .md files, and provides edit history. Added on the footer is links to cgit, which is used to store the files in git on your server. This provides acces to the source code, history, and ATOM diff --git a/TODO.md b/TODO.md index 5f03522..f809490 100644 --- a/TODO.md +++ b/TODO.md @@ -1,14 +1,10 @@ --- pagetitle: "TODO" author: onefang -feedatom: https://sledjhamr.org/cgit/notYetAnotherWiki/atom history: https://sledjhamr.org/cgit/notYetAnotherWiki/log/TODO.md -sourcecode: https://sledjhamr.org/cgit/notYetAnotherWiki/ --- ## Do these -Any .md file that is just the beginning metadata block doesn't get rendered into HTML, but is global metadata for this directory and subs, though the subs can override this. - Footer is still wrong. Clean up the favicon and logo stuff. 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 local body, metadata, err = lcmark.convert(cm, "html", {smart = true, yaml_metadata = true, columns = 0}) if nil == body then print('oops! ' .. err) else + + + if '' == body then + -- A simple v.metadata = metadata wont work, you end up with a reference so that changes to metadata get applied to v.metadata. + v.metadata = {} + for l, y in pairs(metadata) do + v.metadata[l] = y + end + local argh = {} + for l, y in ipairs(v.files) do + if w.name ~= y.name then table.insert(argh, y) end + end + v.files = argh + print('') + else + + local bod, err = lcmark.compile_template(body) + if nil == bod then print('oops! ' .. err) else + local templateFile = metadata.template + if nil == file then + templateFile = nil + else + if nil == templateFile then templateFile = 'default' end + templateFile = templateFile .. '.template' + for m, x in pairs(globalData) do if nil == metadata[m] then metadata[m] = x else print('metadata already has ' .. m) end end + if nil ~= v.metadata then + for m, x in pairs(v.metadata) do if nil == metadata[m] then metadata[m] = x else print('metadata already has ' .. m) end end + end + end + + if nil ~= v.files then + for m, x in ipairs(v.files) do + metadata.menu = metadata.menu .. x.URL .. '\n' + end + end + if nil ~= v.subs then + for m, x in pairs(v.subs) do + metadata.header = metadata.header .. x.URL + end + end + + local num = #(v.bits) + local trail = 'home   ' + local p = v.parent + for i = 1, num do + trail = trail .. '' .. v.bits[i] .. '   ' + end + trail = trail .. w.name + metadata.trail = trail + + metadata.body = lcmark.apply_template(bod, metadata) + + local tm = '' + if nil ~= templateFile then + local h = io.open(templateFile, 'r') + if nil ~= h then + tm = tm .. h:read('*a') + h:close() + else + print('oops! No such file ' .. templateFile) + end + + local template, err = lcmark.compile_template(tm) + if nil == template then print('oops! ' .. err) else + result = lcmark.apply_template(template, metadata) + end + else + result = body + end + + if ('' ~= result) and (nil ~= file) then + local base = path .. w.name .. '.HTML' + print(base) + local a, e = io.open(base, 'w') + if nil == a then print('Could not open ' .. base .. ' - ' .. e) else + a:write(result) + a:close() + end + else + print('') + end + end + + end + end + + h:close() + else + print('oops! No such file ' .. file) + end + + end + end + +end + + local h = io.open(file, 'r') + if nil ~= h then + local cm = h:read('*a') + local result = '' + local body, metadata, err = lcmark.convert(cm, "html", {smart = true, yaml_metadata = true, columns = 0}) + + if nil == body then print('oops! ' .. err) else local bod, err = lcmark.compile_template(body) if nil == bod then print('oops! ' .. err) else local templateFile = metadata.template -- cgit v1.1