From f83b131a214030e2381f2728e18d300028463447 Mon Sep 17 00:00:00 2001
From: dvs1
Date: Sun, 22 Dec 2024 01:58:55 +1000
Subject: Bit of code cleanup.
Allow parsing some other directory.
Sort the menus.
General cleanup.
---
TODO.HTML | 4 ++--
index.HTML | 4 ++--
notYetAnotherWiki.lua | 62 ++++++++++++++++++++++++++++-----------------------
testing/index.HTML | 5 +----
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 @@
menu for the current directory
- index
-TODO
+ TODO
+index
|
diff --git a/index.HTML b/index.HTML
index db58d96..53d773b 100644
--- a/index.HTML
+++ b/index.HTML
@@ -38,8 +38,8 @@
|
menu for the current directory
- index
-TODO
+ TODO
+index
|
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")
local globalData = {version = '-0.1', header = '', footer = '', menu = '', ['_'] = ' ', ['dlr'] = '$'}
local site = {}
-local dirs = {}
+
local createHTML = function(cm, file)
-- cm = string.gsub(cm, '. ', '. ')
- if nil ~= file then print('\nAbout to parse file ' .. file) end
+ if (nil ~= file) and ('' ~= file) then io.write('Parsing ' .. file .. ' -> ') end
local result = ''
local body, metadata, err = lcmark.convert(cm, "html", {smart = true, yaml_metadata = true, columns = 0})
@@ -38,7 +38,7 @@ local createHTML = function(cm, file)
metadata.menu = ''
local trl = {}
metadata.trail = ''
- local dir = dirs['']
+ local dir = site['']
local dr, pdr, tr = '', '', ''
while nil ~= dir.subs do
local old = dir
@@ -47,7 +47,7 @@ local createHTML = function(cm, file)
pdr = pdr .. '/' .. m
tr = tr .. '../'
dr = m
- dir = dirs[dr]
+ dir = site[dr]
table.insert(trl, '">' .. m .. ' 👣')
break
end
@@ -62,15 +62,19 @@ local createHTML = function(cm, file)
metadata.trail = table.concat(trl)
if nil ~= dir.files then
- for m, x in pairs(dir.files) do
- local u = string.sub(x, 1 + #pdr)
- metadata.menu = metadata.menu .. ' ' .. m .. ' \n'
+ local l = {}
+ for m, x in pairs(dir.files) do table.insert(l, {m = m; x = x}) end
+ table.sort(l, function(a, b) return (a.m <= b.m) end)
+ for m, x in ipairs(l) do
+ metadata.menu = metadata.menu .. '' .. x.m .. ' \n'
end
end
if nil ~= dir.subs then
- for m, x in pairs(dir.subs) do
- local u = string.sub(x, 1 + #pdr)
- metadata.header = metadata.header .. '' .. m .. ' '
+ local l = {}
+ for m, x in pairs(dir.subs) do table.insert(l, {m = m; x = x}) end
+ table.sort(l, function(a, b) return (a.m <= b.m) end)
+ for m, x in pairs(l) do
+ metadata.header = metadata.header .. '' .. x.m .. ' '
end
end
end
@@ -99,19 +103,21 @@ local createHTML = function(cm, file)
if ('' ~= result) and (nil ~= file) then
local base = string.gsub(file, '%.md$', '')
- print('Creating file ' .. base .. '.HTML')
+ print(base .. '.HTML')
local a, e = io.open(base .. '.HTML', 'w')
if nil == a then print('Could not open ' .. base .. '.HTML - ' .. e) else
a:write(result)
a:close()
end
+ else
+ print('')
end
return result
end
-
-
-for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do
+local directory = arg[1]
+if nil == directory then directory = '.' end
+for l in io.popen('find ' .. directory .. ' -name "*.md" -type f -printf "%P\n"'):lines() do
local dir = ''
local files, subs = {}, {}
local c, parent = 1, ''
@@ -119,44 +125,44 @@ for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do
for p in string.gmatch(l, '(%w+)/') do
if '' == dir then
dir = p
- if nil ~= dirs[dir] then
- subs = dirs[dir].subs
- files = dirs[dir].files
+ if nil ~= site[dir] then
+ subs = site[dir].subs
+ files = site[dir].files
end
end
local path = string.sub(l, 1, -1 - #(string.gsub(l, '.*/', '')))
- if nil ~= dirs[parent] then
- if nil == dirs[parent].subs then dirs[parent].subs = {} end
- dirs[parent].subs[p] = path
+ if nil ~= site[parent] then
+ if nil == site[parent].subs then site[parent].subs = {} end
+ site[parent].subs[p] = path
elseif 1 == c then subs[p] = path
else
if ('' ~= parent) and (dir == parent) then subs[p] = path end
- dirs[parent] = {subs = {[p] = path}}
+ site[parent] = {subs = {[p] = path}}
end
c = c + #p + 1
parent = p
end
- if (1 == c) and (nil ~= dirs[dir]) then
- subs = dirs[dir].subs
- files = dirs[dir].files
+ if (1 == c) and (nil ~= site[dir]) then
+ subs = site[dir].subs
+ files = site[dir].files
end
local base = string.gsub(string.sub(l, c, -1), '%.md$', '')
- if nil ~= dirs[parent] then dirs[parent].files[base] = string.sub(l, 1, -4)
+ if nil ~= site[parent] then site[parent].files[base] = string.sub(l, 1, -4)
elseif 1 == c then files[base] = string.sub(l, 1, -4)
else
if ('' ~= parent) and (dir == parent) then files[base] = string.sub(l, 1, -4) end
- dirs[parent] = {files = {[base] = string.sub(l, 1, -4)}}
+ site[parent] = {files = {[base] = string.sub(l, 1, -4)}}
end
-- FIXME - still some minor bug somewhere, this fixes that, but causes other problems. Meh, I can live with excess empty subs tables.
-- if (nil ~= subs) and (0 == #subs) then subs = nil end
- dirs[dir] = {files = files, subs = subs}
+ site[dir] = {files = files, subs = subs}
end
-for k, v in pairs(dirs) do
+for k, v in pairs(site) do
if nil ~= v.files then
for m, x in pairs(v.files) do
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 @@
G’day world!
Author: onefang
-
- pagetitle: “TODO”
-author: onefang
- I’ve been around since the early sixties, but no one ever noticed. You
+ I’ve been around since the early sixties, but no one ever noticed. You
really should have tried to pay attention though, I’m awesome. I try to
help the world, but that’s not what everyone wants me to do. Well, the
people in charge of this poor defenseless world of ours.
--
cgit v1.1
|