Mercurial Hosting > luan
annotate website/src/lib/Shared.luan @ 1932:047e4dde22b4
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 02 May 2025 17:32:01 -0600 |
parents | 31f006c64782 |
children | 7d5dabe8eab8 |
rev | line source |
---|---|
1651 | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | |
3 local ipairs = Luan.ipairs or error() | |
1653 | 4 local pairs = Luan.pairs or error() |
1929 | 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" | |
1651 | 12 |
13 | |
14 local Shared = {} | |
15 | |
1929 | 16 Http.not_found_handler = Site_translator.not_found_handler or error() |
17 | |
18 local started = Time.now() | |
1932 | 19 |
20 local function reactionary_url() | |
21 local url = "https://www.reactionary.software" | |
22 local lang = get_lang() | |
23 if lang ~= "en" then | |
24 url = url.."/"..lang | |
25 end | |
26 return url | |
27 end | |
28 Shared.reactionary_url = reactionary_url | |
1929 | 29 |
1651 | 30 function Shared.head() |
31 %> | |
32 <meta name="viewport" content="width=device-width, initial-scale=1"> | |
33 <style> | |
1929 | 34 @import "/site.css?s=<%=started%>"; |
1651 | 35 </style> |
1929 | 36 <script src="/site.js?s=<%=started%>"></script> |
1651 | 37 <% |
38 end | |
39 | |
1652 | 40 local function header(crumbs) |
1929 | 41 local lang = get_lang() |
42 local home | |
43 if lang == "en" then | |
44 home = "/" | |
45 else | |
46 home = "/"..lang.."/" | |
47 end | |
1651 | 48 %> |
49 <div header> | |
1747 | 50 <span breadcrumbs> |
1929 | 51 <a href="<%=home%>">Luan</a> |
1651 | 52 <% for _, crumb in ipairs(crumbs or {}) do %> |
1747 | 53 / <%=crumb%> |
1651 | 54 <% end %> |
1929 | 55 - <select onchange="setLanguage(value)"> |
56 <% for code, name in pairs(languages) do | |
57 local selected = code==lang and "selected" or "" | |
58 %> | |
59 <option value="<%=code%>" <%=selected%> ><%=name%></option> | |
60 <% end %> | |
61 </select> | |
1747 | 62 </span> |
1932 | 63 <span><a href="<%=reactionary_url()%>/">reactionary software</a> by <a href="https://linkmy.style/fschmidt">fschmidt</a></span> |
1651 | 64 </div> |
65 <% | |
66 end | |
1652 | 67 Shared.header = header |
68 | |
69 function Shared.docs_header() | |
1929 | 70 header{[[<a href="docs.html">Documentation</a>]]} |
1652 | 71 end |
1651 | 72 |
1653 | 73 local function show_toc(content) |
74 %> | |
75 <ul> | |
76 <% | |
77 for id, info in pairs(content) do | |
78 %> | |
1812
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1784
diff
changeset
|
79 <li c_<%=id%> ><a id="c_<%=id%>" href="#<%=id%>"><%=info.title%></a> |
1653 | 80 <% |
81 local subs = info.subs | |
82 if subs ~= nil then | |
83 show_toc(subs) | |
84 end | |
85 %> | |
86 </li> | |
87 <% | |
88 end | |
89 %> | |
90 </ul> | |
91 <% | |
92 end | |
93 Shared.show_toc = show_toc | |
94 | |
95 local function nothing() end | |
96 | |
1929 | 97 local show_content, show_content_info |
98 | |
99 function show_content_info(id,info,h) | |
1653 | 100 %> |
101 <div heading> | |
102 <h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>> | |
103 <a href="#c_<%=id%>">contents</a> | |
104 </div> | |
105 <% | |
106 (info.content or nothing)() | |
107 local subs = info.subs | |
108 if subs ~= nil then | |
109 show_content(subs,h+1) | |
110 end | |
1929 | 111 end |
112 Shared.show_content_info = show_content_info | |
113 | |
114 function show_content(content,h) | |
115 for id, info in pairs(content) do | |
116 show_content_info(id,info,h) | |
1653 | 117 end |
118 end | |
119 Shared.show_content = show_content | |
120 | |
1651 | 121 return Shared |