diff options
author | dvs1 | 2024-12-17 03:32:20 +1000 |
---|---|---|
committer | dvs1 | 2024-12-17 03:32:20 +1000 |
commit | a5e7cd15a460e5d65ddc349be36983c3ca88c45a (patch) | |
tree | 0736ba63d58bcedd896bd0cde6614ab4d9e93adb | |
parent | More explaination about the project. (diff) | |
download | notYetAnotherWiki-a5e7cd15a460e5d65ddc349be36983c3ca88c45a.zip notYetAnotherWiki-a5e7cd15a460e5d65ddc349be36983c3ca88c45a.tar.gz notYetAnotherWiki-a5e7cd15a460e5d65ddc349be36983c3ca88c45a.tar.bz2 notYetAnotherWiki-a5e7cd15a460e5d65ddc349be36983c3ca88c45a.tar.xz |
Major code reorg, to get the menus working better.
-rw-r--r-- | TODO.HTML | 4 | ||||
-rw-r--r-- | about/index.HTML | 4 | ||||
-rw-r--r-- | index.HTML | 4 | ||||
-rwxr-xr-x | notYetAnotherWiki.lua | 81 | ||||
-rw-r--r-- | testing/index.HTML | 4 |
5 files changed, 53 insertions, 44 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"> |
diff --git a/about/index.HTML b/about/index.HTML index bb6a53c..e0cbee3 100644 --- a/about/index.HTML +++ b/about/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"> |
@@ -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 cfe7459..1746b0a 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua | |||
@@ -2,8 +2,12 @@ | |||
2 | 2 | ||
3 | local lcmark = require("lcmark") | 3 | local lcmark = require("lcmark") |
4 | 4 | ||
5 | local createHTML = function(cm, file, header, menu) | 5 | local globalData = {header = '', footer = '', menu = '', ['_'] = ' '} |
6 | -- cm = string.gsub(cm, '._ ', '. ') | 6 | local site = {} |
7 | |||
8 | |||
9 | local createHTML = function(cm, file) | ||
10 | -- cm = string.gsub(cm, '. ', '. ') | ||
7 | if nil ~= file then print('About to parse file ' .. file) end | 11 | if nil ~= file then print('About to parse file ' .. file) end |
8 | local result = '' | 12 | local result = '' |
9 | local body, metadata, err = lcmark.convert(cm, "html", {smart = true, yaml_metadata = true, columns = 0}) | 13 | local body, metadata, err = lcmark.convert(cm, "html", {smart = true, yaml_metadata = true, columns = 0}) |
@@ -12,14 +16,14 @@ local createHTML = function(cm, file, header, menu) | |||
12 | local bod, err = lcmark.compile_template(body) | 16 | local bod, err = lcmark.compile_template(body) |
13 | if nil == bod then print('oops! ' .. err) else | 17 | if nil == bod then print('oops! ' .. err) else |
14 | local templateFile = metadata.template | 18 | local templateFile = metadata.template |
15 | metadata['_'] = ' ' | 19 | if nil == file then |
16 | if nil == templateFile then templateFile = 'default' end | ||
17 | templateFile = templateFile .. '.template' | ||
18 | if nil == menu then | ||
19 | templateFile = nil | 20 | templateFile = nil |
20 | else | 21 | else |
21 | metadata.menu = menu | 22 | if nil == templateFile then templateFile = 'default' end |
22 | metadata.header = header | 23 | templateFile = templateFile .. '.template' |
24 | for k, v in pairs(globalData) do | ||
25 | if nill == metadata[k] then metadata[k] = v else print('metadata already has ' .. k) end | ||
26 | end | ||
23 | end | 27 | end |
24 | metadata.body = lcmark.apply_template(bod, metadata) | 28 | metadata.body = lcmark.apply_template(bod, metadata) |
25 | 29 | ||
@@ -56,9 +60,6 @@ local createHTML = function(cm, file, header, menu) | |||
56 | end | 60 | end |
57 | 61 | ||
58 | 62 | ||
59 | local cm, filename, header, menu = '', '', '', '' | ||
60 | local site = {} | ||
61 | |||
62 | for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do | 63 | for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do |
63 | local s = {} | 64 | local s = {} |
64 | local f = '' | 65 | local f = '' |
@@ -67,53 +68,61 @@ for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do | |||
67 | table.insert(s, p) | 68 | table.insert(s, p) |
68 | c = c + #p + 1 | 69 | c = c + #p + 1 |
69 | end | 70 | end |
70 | local full = string.sub(l, c, -1) | 71 | local base = string.gsub(string.sub(l, c, -1), '%.md$', '') |
71 | local base = string.gsub(full, '%.md$', '') | ||
72 | table.insert(s, base) | 72 | table.insert(s, base) |
73 | 73 | ||
74 | if 'menu' == s[#s] then | 74 | -- TODO - should do the same for header.md and footer.md |
75 | if 'menu' == base then | ||
75 | local h = io.open(l, 'r') | 76 | local h = io.open(l, 'r') |
76 | if nil ~= h then | 77 | if nil ~= h then |
78 | globalData.menuFound = true | ||
77 | print('Found ' .. l) | 79 | print('Found ' .. l) |
78 | menu = createHTML(h:read('*a')) | 80 | globalData.menu = string.gsub(createHTML(h:read('*a')), 'ul>', 'menu>') |
79 | h:close() | 81 | h:close() |
80 | menu = string.gsub(menu, 'ul>', 'menu>') | ||
81 | end | 82 | end |
82 | else | 83 | else |
83 | if 1 ~= #s then | 84 | if 1 ~= #s then site[l] = s else site[l] = base end |
84 | site[l] = s | 85 | end |
85 | else | 86 | end |
86 | site[l] = base | 87 | |
88 | for k, v in pairs(site) do | ||
89 | if 'string' == type(v) then | ||
90 | if not globalData.menuFound then | ||
91 | local m = '[' .. v .. '](' .. v .. '.HTML)\n' | ||
92 | globalData.menu = globalData.menu .. string.gsub(createHTML(m), 'ul>', 'menu>') | ||
87 | end | 93 | end |
94 | elseif not globalData.headerFound then | ||
95 | local path = '' | ||
96 | for i, w in ipairs(v) do | ||
97 | path = path .. w .. '/' | ||
98 | end | ||
99 | globalData.header = globalData.header .. '<a href="' .. string.sub(path, 1, -2) .. '.HTML">' .. v[1] .. '</a> ' | ||
88 | end | 100 | end |
89 | end | 101 | end |
90 | 102 | ||
91 | -- TODO - Only do these first things if menu.md doesn't exist, the second for headers.md | 103 | |
92 | --if '' == menu then | 104 | local cm, filename = '', '' |
105 | |||
106 | if 0 == #arg then | ||
93 | for k, v in pairs(site) do | 107 | for k, v in pairs(site) do |
108 | local path = '' | ||
94 | if 'string' == type(v) then | 109 | if 'string' == type(v) then |
95 | local m = '[' .. v .. '](' .. v .. '.HTML)\n' | 110 | path = v |
96 | menu = menu .. string.gsub(createHTML(m), 'ul>', 'menu>') | 111 | elseif not globalData.headerFound then |
97 | else | ||
98 | local path = '' | ||
99 | for i, w in ipairs(v) do | 112 | for i, w in ipairs(v) do |
100 | path = path .. w .. '/' | 113 | path = path .. w .. '/' |
101 | end | 114 | end |
102 | header = header .. '<a href="' .. string.sub(path, 1, -2) .. '.HTML">' .. v[1] .. '</a> ' | 115 | path = string.sub(path, 1, -2) |
103 | end | 116 | end |
104 | end | 117 | path = path .. '.md' |
105 | --end | ||
106 | |||
107 | 118 | ||
108 | if 0 == #arg then | ||
109 | for l in io.popen('find . -name "*.md" -type f -printf "%P\n"'):lines() do | ||
110 | cm = '' | 119 | cm = '' |
111 | local h = io.open(l, 'r') | 120 | local h = io.open(path, 'r') |
112 | if nil ~= h then | 121 | if nil ~= h then |
113 | createHTML(h:read('*a'), l, header, menu) | 122 | createHTML(h:read('*a'), path) |
114 | h:close() | 123 | h:close() |
115 | else | 124 | else |
116 | print('oops! No such file ' .. l) | 125 | print('oops! No such file ' .. path) |
117 | end | 126 | end |
118 | end | 127 | end |
119 | else | 128 | else |
@@ -128,5 +137,5 @@ else | |||
128 | end | 137 | end |
129 | end | 138 | end |
130 | if filename == '' then filename = 'test.md' end | 139 | if filename == '' then filename = 'test.md' end |
131 | createHTML(cm, filename, header, menu) | 140 | createHTML(cm, filename) |
132 | end | 141 | end |
diff --git a/testing/index.HTML b/testing/index.HTML index 05a496e..1dde2bd 100644 --- a/testing/index.HTML +++ b/testing/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"> |