view website/src/lib/Shared.luan @ 1929:31f006c64782

translation
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 01 May 2025 18:31:05 -0600
parents 50e570b598b2
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 Time = require "luan:Time.luan"
local Http = require "luan:http/Http.luan"
local Site_translator = require "luan:gpt/Site_translator.luan"
local get_lang = Site_translator.get_lang or error()
local languages = Site_translator.languages or error()
local Logging = require "luan:logging/Logging.luan"
local logger = Logging.logger "Shared"


local Shared = {}

Http.not_found_handler = Site_translator.not_found_handler or error()

local started = Time.now()
Shared.started = started

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

local function header(crumbs)
	local lang = get_lang()
	local home
	if lang == "en" then
		home = "/"
	else
		home = "/"..lang.."/"
	end
%>
		<div header>
			<span breadcrumbs>
				<a href="<%=home%>">Luan</a>
<%	for _, crumb in ipairs(crumbs or {}) do %>
				/ <%=crumb%>
<%	end %>
				- <select onchange="setLanguage(value)">
<%	for code, name in pairs(languages) do
		local selected = code==lang and "selected" or ""
%>
					<option value="<%=code%>" <%=selected%> ><%=name%></option>
<%	end %>
				</select>
			</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 show_content, show_content_info

function show_content_info(id,info,h)
%>
			<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
Shared.show_content_info = show_content_info

function show_content(content,h)
	for id, info in pairs(content) do
		show_content_info(id,info,h)
	end
end
Shared.show_content = show_content

return Shared