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