view src/lib/Shared.luan @ 9:88f425d261b3

add menu
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 25 Oct 2023 18:38:07 -0600
parents 9534dd5eda89
children 62dd23f0b549
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local Time = require "luan:Time.luan"
local Http = require "luan:http/Http.luan"


local Shared = {}

local started = Time.now()

local function get_user()
	return Http.request.cookies.user
end
Shared.get_user = get_user

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="javascript:logout()">Log out</a>
				</div>
			</span>
<%	end %>
		</div>
		<hr>
<%
end

function Shared.footer()
%>
		<hr>
		<div footer>
			something or other in the footer
		</div>
<%
end

function Shared.discord_redirect_uri()
	local request = Http.request
	return request.scheme.."://"..request.headers["Host"].."/login2.html"
end

return Shared