Mercurial Hosting > luan
annotate website/src/lib/Shared.luan @ 1938:bd00b36380d9 default tip
ai options
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 16 May 2025 17:20:29 -0600 |
parents | 5b5d88cf13b5 |
children |
rev | line source |
---|---|
1938 | 1 local ai = "gpt" |
2 | |
1651 | 3 local Luan = require "luan:Luan.luan" |
4 local error = Luan.error | |
5 local ipairs = Luan.ipairs or error() | |
1653 | 6 local pairs = Luan.pairs or error() |
1929 | 7 local Time = require "luan:Time.luan" |
8 local Http = require "luan:http/Http.luan" | |
1938 | 9 local Ai = require "luan:ai/Ai.luan" |
10 Ai.set_ai(ai) | |
11 local require_ai = Ai.require_ai or error() | |
12 local Translator = require_ai "Translator.luan" | |
13 local Site_translator = require "luan:ai/Site_translator.luan" | |
1929 | 14 local get_lang = Site_translator.get_lang or error() |
15 local languages = Site_translator.languages or error() | |
16 local Logging = require "luan:logging/Logging.luan" | |
17 local logger = Logging.logger "Shared" | |
1651 | 18 |
19 | |
20 local Shared = {} | |
21 | |
1938 | 22 if ai == "gpt" then |
23 function Translator.prompt(html,language) | |
1933 | 24 %> |
25 Please translate the HTML below delimited by triple quotes from English to <%=language%>. | |
26 | |
27 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". | |
28 | |
1934 | 29 Do not translate file names. |
1933 | 30 |
1934 | 31 Do not translate the contents of <code> tags. |
1933 | 32 |
33 """ | |
34 <%=html%> | |
35 """ | |
36 <% | |
1938 | 37 end |
38 else error(ai) end | |
1933 | 39 |
1929 | 40 Http.not_found_handler = Site_translator.not_found_handler or error() |
41 | |
42 local started = Time.now() | |
1932 | 43 |
44 local function reactionary_url() | |
45 local url = "https://www.reactionary.software" | |
46 local lang = get_lang() | |
47 if lang ~= "en" then | |
48 url = url.."/"..lang | |
49 end | |
50 return url | |
51 end | |
52 Shared.reactionary_url = reactionary_url | |
1929 | 53 |
1651 | 54 function Shared.head() |
55 %> | |
56 <meta name="viewport" content="width=device-width, initial-scale=1"> | |
57 <style> | |
1929 | 58 @import "/site.css?s=<%=started%>"; |
1651 | 59 </style> |
1929 | 60 <script src="/site.js?s=<%=started%>"></script> |
1651 | 61 <% |
62 end | |
63 | |
1652 | 64 local function header(crumbs) |
1929 | 65 local lang = get_lang() |
66 local home | |
67 if lang == "en" then | |
68 home = "/" | |
69 else | |
70 home = "/"..lang.."/" | |
71 end | |
1651 | 72 %> |
73 <div header> | |
1747 | 74 <span breadcrumbs> |
1929 | 75 <a href="<%=home%>">Luan</a> |
1651 | 76 <% for _, crumb in ipairs(crumbs or {}) do %> |
1747 | 77 / <%=crumb%> |
1651 | 78 <% end %> |
1929 | 79 - <select onchange="setLanguage(value)"> |
80 <% for code, name in pairs(languages) do | |
81 local selected = code==lang and "selected" or "" | |
82 %> | |
83 <option value="<%=code%>" <%=selected%> ><%=name%></option> | |
84 <% end %> | |
85 </select> | |
1747 | 86 </span> |
1932 | 87 <span><a href="<%=reactionary_url()%>/">reactionary software</a> by <a href="https://linkmy.style/fschmidt">fschmidt</a></span> |
1651 | 88 </div> |
89 <% | |
90 end | |
1652 | 91 Shared.header = header |
92 | |
93 function Shared.docs_header() | |
1929 | 94 header{[[<a href="docs.html">Documentation</a>]]} |
1652 | 95 end |
1651 | 96 |
1653 | 97 local function show_toc(content) |
98 %> | |
99 <ul> | |
100 <% | |
101 for id, info in pairs(content) do | |
102 %> | |
1812
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1784
diff
changeset
|
103 <li c_<%=id%> ><a id="c_<%=id%>" href="#<%=id%>"><%=info.title%></a> |
1653 | 104 <% |
105 local subs = info.subs | |
106 if subs ~= nil then | |
107 show_toc(subs) | |
108 end | |
109 %> | |
110 </li> | |
111 <% | |
112 end | |
113 %> | |
114 </ul> | |
115 <% | |
116 end | |
117 Shared.show_toc = show_toc | |
118 | |
119 local function nothing() end | |
120 | |
1929 | 121 local show_content, show_content_info |
122 | |
123 function show_content_info(id,info,h) | |
1653 | 124 %> |
125 <div heading> | |
126 <h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>> | |
127 <a href="#c_<%=id%>">contents</a> | |
128 </div> | |
129 <% | |
130 (info.content or nothing)() | |
131 local subs = info.subs | |
132 if subs ~= nil then | |
133 show_content(subs,h+1) | |
134 end | |
1929 | 135 end |
136 Shared.show_content_info = show_content_info | |
137 | |
138 function show_content(content,h) | |
139 for id, info in pairs(content) do | |
140 show_content_info(id,info,h) | |
1653 | 141 end |
142 end | |
143 Shared.show_content = show_content | |
144 | |
1651 | 145 return Shared |