Mercurial Hosting > disearch
view src/lib/Shared.luan @ 23:e5c77f8d506d default tip
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 15 Sep 2024 10:45:43 -0600 |
parents | b386303be994 |
children |
line wrap: on
line source
local Luan = require "luan:Luan.luan" local error = Luan.error local ipairs = Luan.ipairs or error() local Time = require "luan:Time.luan" local Parsers = require "luan:Parsers.luan" local json_string = Parsers.json_string or error() local Http = require "luan:http/Http.luan" local Utils = require "site:/lib/Utils.luan" local get_user = Utils.get_user or error() local Shared = {} local started = Time.now() function Shared.head() %> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> @import "/site.css?s=<%=started%>"; </style> <script src="/site.js?s=<%=started%>"></script> <% end function Shared.header() %> <div header> <h1><a href="/">Disearch</a></h1> <% if get_user() == nil then %> <a href="login1.red">login</a> <% else %> <span right pulldown> <script>document.write(`<img src="https://cdn.discordapp.com/avatars/${localStorage.user_id}/${localStorage.user_avatar}.png" onclick="clickMenu(this)">`)</script> <div pulldown_menu> <span username><script>document.write(localStorage.user_name)</script></span> <a href="/bump.html">Bump Servers</a> <a href="/servers.html">Your Servers</a> <a href="javascript:logout()">Log out</a> </div> </span> <% end %> </div> <hr> <% end function Shared.footer() %> <hr> <div footer> <a href="/tools/links.html">links</a> </div> <% end local function base_url() local request = Http.request return request.scheme.."://"..request.headers["Host"] end Shared.base_url = base_url function Shared.discord_redirect_uri() return base_url().."/login2.html" end function Shared.js_error(field,message) %> showError( context.form, '<%=field%>', <%=json_string(message)%> ); <% end local times = { { time = 1000*60*60*24*365 unit = "year" } { time = 1000*60*60*24*7 unit = "week" } { time = 1000*60*60*24 unit = "day" } { time = 1000*60*60 unit = "hour" } { time = 1000*60 unit = "minute" } } function Shared.ago(time) for _, t in ipairs(times) do local n = time // t.time if n > 0 then %><%=n%> <%=t.unit%><% if n > 1 then %>s<% end %> ago<% return end end %>just now<% end return Shared