diff options
author | dvs1 | 2025-03-14 21:34:10 +1000 |
---|---|---|
committer | dvs1 | 2025-03-14 21:34:10 +1000 |
commit | 6be63601ba1c2cd76aa1eca2ee349492f3360aa4 (patch) | |
tree | ced739b8e0dad5e1daf0b9555835bc2b75660b34 | |
parent | Basic TOC. (diff) | |
download | notYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.zip notYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.tar.gz notYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.tar.bz2 notYetAnotherWiki-6be63601ba1c2cd76aa1eca2ee349492f3360aa4.tar.xz |
Make the TOC actually work.
-rw-r--r-- | TODO.md | 2 | ||||
-rwxr-xr-x | notYetAnotherWiki.lua | 16 |
2 files changed, 12 insertions, 6 deletions
@@ -6,8 +6,8 @@ Make it perphekd! | |||
6 | 6 | ||
7 | TOC | 7 | TOC |
8 | 8 | ||
9 | - Add anchors, so clicking on them goes to the heading. | ||
10 | - Lengthy headings need to be tamed. | 9 | - Lengthy headings need to be tamed. |
10 | - Need a "go to top" linky after each heading now. | ||
11 | 11 | ||
12 | 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. | 12 | 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. |
13 | 13 | ||
diff --git a/notYetAnotherWiki.lua b/notYetAnotherWiki.lua index f124eeb..3590af7 100755 --- a/notYetAnotherWiki.lua +++ b/notYetAnotherWiki.lua | |||
@@ -710,6 +710,10 @@ local lunaLinky = function(url) -- Fix up the links. | |||
710 | return url | 710 | return url |
711 | end | 711 | end |
712 | 712 | ||
713 | function Writer.header(s, level) | ||
714 | local text = table.concat(s) | ||
715 | return '<h' .. level .. ' id="' .. RE.gsub(text, '{[ ]}', '_') .. '">' .. text .. '</h' .. level .. '>' | ||
716 | end | ||
713 | local OgWriterLink = Writer.link -- So we can call the original from within mine, we are just changing the URL. | 717 | local OgWriterLink = Writer.link -- So we can call the original from within mine, we are just changing the URL. |
714 | function Writer.link(lab, url, tit) | 718 | function Writer.link(lab, url, tit) |
715 | return OgWriterLink(lab, lunaLinky(url), tit) | 719 | return OgWriterLink(lab, lunaLinky(url), tit) |
@@ -776,14 +780,16 @@ for name, file in pairs(Files) do | |||
776 | if bit == f then | 780 | if bit == f then |
777 | metadata.menu = metadata.menu .. '<p>' .. title .. '</p>' | 781 | metadata.menu = metadata.menu .. '<p>' .. title .. '</p>' |
778 | for j, g in ipairs(file.headers) do | 782 | for j, g in ipairs(file.headers) do |
779 | g = RE.gsub(g, '{[#]}', ' ') | 783 | local h = string.sub(RE.gsub(g, '{[#]}', ''), 2) |
780 | g = RE.gsub(g, '{[ ]}', ' ') | 784 | local l = string.len(g) - string.len(h) |
781 | local beg, en = RE.find(g, [['{']]) | 785 | g = h |
786 | h = RE.gsub(h, '{[ ]}', ' ') | ||
787 | local beg, en = RE.find(h, [['{']]) | ||
782 | if nil ~= beg then | 788 | if nil ~= beg then |
783 | g = string.sub(g, 1, beg - 7) | 789 | g = string.sub(h, 1, beg - 7) |
784 | end | 790 | end |
785 | -- FIXME - if it's a linky, strip off the URL part. The Wiki audit has such things. | 791 | -- FIXME - if it's a linky, strip off the URL part. The Wiki audit has such things. |
786 | metadata.menu = metadata.menu .. '<p style="font-size: 0.80em;">' .. g .. '</p>' | 792 | metadata.menu = metadata.menu .. '<p>' .. string.rep(' ', l) .. '<a style="font-size: 0.80em;" href="#' .. RE.gsub(g, '{[ ]}', '_') .. '">' .. h .. '</a></p>' |
787 | end | 793 | end |
788 | else | 794 | else |
789 | if nil ~= url then metadata.menu = metadata.menu .. '<p><a href="' .. url .. '">' .. title .. ' ☝</a></p>' | 795 | if nil ~= url then metadata.menu = metadata.menu .. '<p><a href="' .. url .. '">' .. title .. ' ☝</a></p>' |