view website/src/lib/Shared.luan @ 1809:90187946d1a4

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 12 May 2024 17:15:33 -0600
parents fdc59d390615
children f44dcb3fedf7
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="http://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><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