diff options
author | dvs1 | 2024-12-16 13:25:52 +1000 |
---|---|---|
committer | dvs1 | 2024-12-16 13:25:52 +1000 |
commit | 9dd962166a1849a31b25767a81cf269f4b99d4a5 (patch) | |
tree | f75f63a74441a44280921bb02059d518cb0c180a /notYetAnotherWiki.lua | |
parent | Again, nope. lol (diff) | |
download | notYetAnotherWiki-9dd962166a1849a31b25767a81cf269f4b99d4a5.zip notYetAnotherWiki-9dd962166a1849a31b25767a81cf269f4b99d4a5.tar.gz notYetAnotherWiki-9dd962166a1849a31b25767a81cf269f4b99d4a5.tar.bz2 notYetAnotherWiki-9dd962166a1849a31b25767a81cf269f4b99d4a5.tar.xz |
Commit the test version of the code.
Diffstat (limited to 'notYetAnotherWiki.lua')
-rwxr-xr-x | notYetAnotherWiki.lua | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua new file mode 100755 index 0000000..1f077b5 --- /dev/null +++ b/notYetAnotherWiki.lua | |||
@@ -0,0 +1,112 @@ | |||
1 | #!/usr/bin/env luajit | ||
2 | |||
3 | --[[ TODOs | ||
4 | Contstruct metadata.webtrail in createHTML from links to index.HTML in the various bits of the path of the input file. | ||
5 | |||
6 | Construct a default set of menus if menu.md / header.md doesn't exist in each directory. | ||
7 | Same for footer.md I guess. | ||
8 | |||
9 | For such fragments, rename their results to footer.FRAGMENT. metadata.isFragment | ||
10 | |||
11 | BUG - sub directories get their links screwed with extra path. | ||
12 | |||
13 | Check the timestamps on the files, only update if source is newer than destination. Meh, it's already 600 times faster than the pandoc version. | ||
14 | |||
15 | Add atom feed and history for single page. Alas cgit only seems to have ATOM feed and commit log on the whole repo, not individual files. | ||
16 | ]] | ||
17 | |||
18 | local lcmark = require("lcmark") | ||
19 | |||
20 | local createHTML = function(cm, file, menu) | ||
21 | -- cm = string.gsub(cm, '._ ', '. ') | ||
22 | if nil ~= file then print('About to parse file ' .. file) end | ||
23 | local result = '' | ||
24 | local body, metadata, err = lcmark.convert(cm, "html", {smart = true, yaml_metadata = true, columns = 0}) | ||
25 | |||
26 | if nil == body then print('oops! ' .. err) else | ||
27 | local bod, err = lcmark.compile_template(body) | ||
28 | if nil == bod then print('oops! ' .. err) else | ||
29 | local templateFile = metadata.template | ||
30 | metadata['_'] = ' ' | ||
31 | if nil == templateFile then templateFile = 'default' end | ||
32 | templateFile = templateFile .. '.template' | ||
33 | if nil == menu then | ||
34 | templateFile = nil | ||
35 | else | ||
36 | metadata.menu = menu | ||
37 | end | ||
38 | metadata.body = lcmark.apply_template(bod, metadata) | ||
39 | |||
40 | local tm = '' | ||
41 | if nil ~= templateFile then | ||
42 | local h = io.open(templateFile, 'r') | ||
43 | if nil ~= h then | ||
44 | tm = tm .. h:read('*a') | ||
45 | h:close() | ||
46 | else | ||
47 | print('oops! No such file ' .. templateFile) | ||
48 | end | ||
49 | |||
50 | local template, err = lcmark.compile_template(tm) | ||
51 | if nil == template then print('oops! ' .. err) else | ||
52 | result = lcmark.apply_template(template, metadata) | ||
53 | end | ||
54 | else | ||
55 | result = body | ||
56 | end | ||
57 | end | ||
58 | end | ||
59 | |||
60 | if ('' ~= result) and (nil ~= file) then | ||
61 | local base = string.gsub(file, '%.md$', '') | ||
62 | print('Creating file ' .. base .. '.HTML') | ||
63 | local a, e = io.open(base .. '.HTML', 'w') | ||
64 | if nil == a then print('Could not open ' .. base .. '.HTML - ' .. e) else | ||
65 | a:write(result) | ||
66 | a:close() | ||
67 | end | ||
68 | end | ||
69 | return result | ||
70 | end | ||
71 | |||
72 | |||
73 | local cm = '' | ||
74 | local filename = '' | ||
75 | local menu = '' | ||
76 | |||
77 | |||
78 | local h = io.open('menu.md', 'r') | ||
79 | if nil ~= h then | ||
80 | print('Found menu.md') | ||
81 | menu = createHTML(h:read('*a')) | ||
82 | h:close() | ||
83 | menu = string.gsub(menu, 'ul>', 'menu>') | ||
84 | end | ||
85 | |||
86 | |||
87 | if 0 ~= #arg then | ||
88 | for i,a in ipairs(arg) do | ||
89 | if filename == '' then filename = a end | ||
90 | local h = io.open(a, 'r') | ||
91 | if nil ~= h then | ||
92 | cm = cm .. h:read('*a') | ||
93 | h:close() | ||
94 | else | ||
95 | print('oops! No such file ' .. a) | ||
96 | end | ||
97 | end | ||
98 | if filename == '' then filename = 'test.md' end | ||
99 | createHTML(cm, filename, menu) | ||
100 | else | ||
101 | local sticks = io.popen('find . -name "*.md" -type f -printf "%P\n"') | ||
102 | for l in sticks:lines() do | ||
103 | cm = '' | ||
104 | local h = io.open(l, 'r') | ||
105 | if nil ~= h then | ||
106 | createHTML(h:read('*a'), l, menu) | ||
107 | h:close() | ||
108 | else | ||
109 | print('oops! No such file ' .. l) | ||
110 | end | ||
111 | end | ||
112 | end | ||