Mercurial Hosting > luan
comparison 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 | 047e4dde22b4 |
comparison
equal
deleted
inserted
replaced
1928:e16f38f4fdfc | 1929:31f006c64782 |
---|---|
1 local Luan = require "luan:Luan.luan" | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | 2 local error = Luan.error |
3 local ipairs = Luan.ipairs or error() | 3 local ipairs = Luan.ipairs or error() |
4 local pairs = Luan.pairs or error() | 4 local pairs = Luan.pairs or error() |
5 local Time = require "luan:Time.luan" | |
6 local Http = require "luan:http/Http.luan" | |
7 local Site_translator = require "luan:gpt/Site_translator.luan" | |
8 local get_lang = Site_translator.get_lang or error() | |
9 local languages = Site_translator.languages or error() | |
10 local Logging = require "luan:logging/Logging.luan" | |
11 local logger = Logging.logger "Shared" | |
5 | 12 |
6 | 13 |
7 local Shared = {} | 14 local Shared = {} |
15 | |
16 Http.not_found_handler = Site_translator.not_found_handler or error() | |
17 | |
18 local started = Time.now() | |
19 Shared.started = started | |
8 | 20 |
9 function Shared.head() | 21 function Shared.head() |
10 %> | 22 %> |
11 <meta name="viewport" content="width=device-width, initial-scale=1"> | 23 <meta name="viewport" content="width=device-width, initial-scale=1"> |
12 <style> | 24 <style> |
13 @import "/site.css"; | 25 @import "/site.css?s=<%=started%>"; |
14 </style> | 26 </style> |
27 <script src="/site.js?s=<%=started%>"></script> | |
15 <% | 28 <% |
16 end | 29 end |
17 | 30 |
18 local function header(crumbs) | 31 local function header(crumbs) |
32 local lang = get_lang() | |
33 local home | |
34 if lang == "en" then | |
35 home = "/" | |
36 else | |
37 home = "/"..lang.."/" | |
38 end | |
19 %> | 39 %> |
20 <div header> | 40 <div header> |
21 <span breadcrumbs> | 41 <span breadcrumbs> |
22 <a href="/">Luan</a> | 42 <a href="<%=home%>">Luan</a> |
23 <% for _, crumb in ipairs(crumbs or {}) do %> | 43 <% for _, crumb in ipairs(crumbs or {}) do %> |
24 / <%=crumb%> | 44 / <%=crumb%> |
25 <% end %> | 45 <% end %> |
46 - <select onchange="setLanguage(value)"> | |
47 <% for code, name in pairs(languages) do | |
48 local selected = code==lang and "selected" or "" | |
49 %> | |
50 <option value="<%=code%>" <%=selected%> ><%=name%></option> | |
51 <% end %> | |
52 </select> | |
26 </span> | 53 </span> |
27 <span><a href="https://www.reactionary.software/">reactionary software</a> by <a href="https://linkmy.style/fschmidt">fschmidt</a></span> | 54 <span><a href="https://www.reactionary.software/">reactionary software</a> by <a href="https://linkmy.style/fschmidt">fschmidt</a></span> |
28 </div> | 55 </div> |
29 <% | 56 <% |
30 end | 57 end |
31 Shared.header = header | 58 Shared.header = header |
32 | 59 |
33 function Shared.docs_header() | 60 function Shared.docs_header() |
34 header{[[<a href="/docs.html">Documentation</a>]]} | 61 header{[[<a href="docs.html">Documentation</a>]]} |
35 end | 62 end |
36 | 63 |
37 local function show_toc(content) | 64 local function show_toc(content) |
38 %> | 65 %> |
39 <ul> | 66 <ul> |
56 end | 83 end |
57 Shared.show_toc = show_toc | 84 Shared.show_toc = show_toc |
58 | 85 |
59 local function nothing() end | 86 local function nothing() end |
60 | 87 |
61 local function show_content(content,h) | 88 local show_content, show_content_info |
62 for id, info in pairs(content) do | 89 |
90 function show_content_info(id,info,h) | |
63 %> | 91 %> |
64 <div heading> | 92 <div heading> |
65 <h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>> | 93 <h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>> |
66 <a href="#c_<%=id%>">contents</a> | 94 <a href="#c_<%=id%>">contents</a> |
67 </div> | 95 </div> |
69 (info.content or nothing)() | 97 (info.content or nothing)() |
70 local subs = info.subs | 98 local subs = info.subs |
71 if subs ~= nil then | 99 if subs ~= nil then |
72 show_content(subs,h+1) | 100 show_content(subs,h+1) |
73 end | 101 end |
102 end | |
103 Shared.show_content_info = show_content_info | |
104 | |
105 function show_content(content,h) | |
106 for id, info in pairs(content) do | |
107 show_content_info(id,info,h) | |
74 end | 108 end |
75 end | 109 end |
76 Shared.show_content = show_content | 110 Shared.show_content = show_content |
77 | 111 |
78 return Shared | 112 return Shared |