view website/src/lib/Shared.luan @ 1827:50e570b598b2

security
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 15 Sep 2024 10:36:46 -0600
parents f44dcb3fedf7
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local ipairs = Luan.ipairs or error()
local pairs = Luan.pairs or error()


local Shared = {}

function Shared.head()
%>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<style>
			@import "/site.css";
		</style>
<%
end

local function header(crumbs)
%>
		<div header>
			<span breadcrumbs>
				<a href="/">Luan</a>
<%	for _, crumb in ipairs(crumbs or {}) do %>
				/ <%=crumb%>
<%	end %>
			</span>
			<span><a href="https://www.reactionary.software/">reactionary software</a> by <a href="https://linkmy.style/fschmidt">fschmidt</a></span>
		</div>
<%
end
Shared.header = header

function Shared.docs_header()
	header{[[<a href="/docs.html">Documentation</a>]]}
end

local function show_toc(content)
%>
			<ul>
<%
	for id, info in pairs(content) do
%>
			<li c_<%=id%> ><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