view website/src/lib/Shared.luan @ 1750:c7b3c327248a

webserver error handling
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 10 Jan 2023 22:42:47 -0700
parents 2fbca5c84422
children 7d2297155ee3
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>by <a href="https://www.linkmystyle.com/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><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