diff website/src/lib/Shared.luan @ 1653:418b610e887b

docs work
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 31 Mar 2022 22:12:40 -0600
parents d5779a264a4a
children 2fbca5c84422
line wrap: on
line diff
--- a/website/src/lib/Shared.luan	Thu Mar 31 19:04:59 2022 -0600
+++ b/website/src/lib/Shared.luan	Thu Mar 31 22:12:40 2022 -0600
@@ -1,6 +1,7 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
 local ipairs = Luan.ipairs or error()
+local pairs = Luan.pairs or error()
 
 
 local Shared = {}
@@ -30,4 +31,45 @@
 	header{[[<a href="/docs.html">Documentation</a>]]}
 end
 
+local function show_toc(content)
+%>
+			<ul>
+<%
+	for id, info in pairs(content) do
+%>
+			<li><a id="c_<%=id%>" href="#<%=id%>"><%=info.title%></a>
+<%
+		local subs = info.subs
+		if subs ~= nil then
+			show_toc(subs)
+		end
+%>
+			</li>
+<%
+	end
+%>
+			</ul>
+<%
+end
+Shared.show_toc = show_toc
+
+local function nothing() end
+
+local function show_content(content,h)
+	for id, info in pairs(content) do
+%>
+			<div heading>
+				<h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>>
+				<a href="#c_<%=id%>">contents</a>
+			</div>
+<%
+		(info.content or nothing)()
+		local subs = info.subs
+		if subs ~= nil then
+			show_content(subs,h+1)
+		end
+	end
+end
+Shared.show_content = show_content
+
 return Shared