view website/src/lib/Shared.luan @ 1934:5b5d88cf13b5 default tip

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 02 May 2025 20:22:13 -0600
parents 7d5dabe8eab8
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 Translator = require "luan:gpt/Translator.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 = {}

function Translator.prompt(html,language)
%>
Please translate the HTML below delimited by triple quotes from English to <%=language%>.

Note that the content is related to computer programming, so keep that in mind while translating.  The English word "library" refers to a programming library, not a place to borrow books, so translate to the word in the target language that means programming library.  So for Spanish, use "librería".

Do not translate file names.

Do not translate the contents of <code> tags.

"""
<%=html%>
"""
<%
end

Http.not_found_handler = Site_translator.not_found_handler or error()

local started = Time.now()

local function reactionary_url()
	local url = "https://www.reactionary.software"
	local lang = get_lang()
	if lang ~= "en" then
		url = url.."/"..lang
	end
	return url
end
Shared.reactionary_url = reactionary_url

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="<%=reactionary_url()%>/">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