Mercurial Hosting > luan
annotate website/src/lib/Shared.luan @ 1931:28cd9b3abdb3
add lang
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Fri, 02 May 2025 10:24:38 -0600 |
| parents | 31f006c64782 |
| children | 047e4dde22b4 |
| 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() | |
| 19 Shared.started = started | |
| 20 | |
| 1651 | 21 function Shared.head() |
| 22 %> | |
| 23 <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| 24 <style> | |
| 1929 | 25 @import "/site.css?s=<%=started%>"; |
| 1651 | 26 </style> |
| 1929 | 27 <script src="/site.js?s=<%=started%>"></script> |
| 1651 | 28 <% |
| 29 end | |
| 30 | |
| 1652 | 31 local function header(crumbs) |
| 1929 | 32 local lang = get_lang() |
| 33 local home | |
| 34 if lang == "en" then | |
| 35 home = "/" | |
| 36 else | |
| 37 home = "/"..lang.."/" | |
| 38 end | |
| 1651 | 39 %> |
| 40 <div header> | |
| 1747 | 41 <span breadcrumbs> |
| 1929 | 42 <a href="<%=home%>">Luan</a> |
| 1651 | 43 <% for _, crumb in ipairs(crumbs or {}) do %> |
| 1747 | 44 / <%=crumb%> |
| 1651 | 45 <% end %> |
| 1929 | 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> | |
| 1747 | 53 </span> |
| 1827 | 54 <span><a href="https://www.reactionary.software/">reactionary software</a> by <a href="https://linkmy.style/fschmidt">fschmidt</a></span> |
| 1651 | 55 </div> |
| 56 <% | |
| 57 end | |
| 1652 | 58 Shared.header = header |
| 59 | |
| 60 function Shared.docs_header() | |
| 1929 | 61 header{[[<a href="docs.html">Documentation</a>]]} |
| 1652 | 62 end |
| 1651 | 63 |
| 1653 | 64 local function show_toc(content) |
| 65 %> | |
| 66 <ul> | |
| 67 <% | |
| 68 for id, info in pairs(content) do | |
| 69 %> | |
|
1812
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1784
diff
changeset
|
70 <li c_<%=id%> ><a id="c_<%=id%>" href="#<%=id%>"><%=info.title%></a> |
| 1653 | 71 <% |
| 72 local subs = info.subs | |
| 73 if subs ~= nil then | |
| 74 show_toc(subs) | |
| 75 end | |
| 76 %> | |
| 77 </li> | |
| 78 <% | |
| 79 end | |
| 80 %> | |
| 81 </ul> | |
| 82 <% | |
| 83 end | |
| 84 Shared.show_toc = show_toc | |
| 85 | |
| 86 local function nothing() end | |
| 87 | |
| 1929 | 88 local show_content, show_content_info |
| 89 | |
| 90 function show_content_info(id,info,h) | |
| 1653 | 91 %> |
| 92 <div heading> | |
| 93 <h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>> | |
| 94 <a href="#c_<%=id%>">contents</a> | |
| 95 </div> | |
| 96 <% | |
| 97 (info.content or nothing)() | |
| 98 local subs = info.subs | |
| 99 if subs ~= nil then | |
| 100 show_content(subs,h+1) | |
| 101 end | |
| 1929 | 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) | |
| 1653 | 108 end |
| 109 end | |
| 110 Shared.show_content = show_content | |
| 111 | |
| 1651 | 112 return Shared |
