Mercurial Hosting > linkmystyle
diff src/pic.html.luan @ 0:8f4df159f06b
start public repo
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 11 Jul 2025 20:57:49 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pic.html.luan Fri Jul 11 20:57:49 2025 -0600 @@ -0,0 +1,73 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local ipairs = Luan.ipairs or error() +local Html = require "luan:Html.luan" +local html_encode = Html.encode or error() +local Parsers = require "luan:Parsers.luan" +local json_string = Parsers.json_string or error() +local Io = require "luan:Io.luan" +local Http = require "luan:http/Http.luan" +local Shared = require "site:/lib/Shared.luan" +local pub_head = Shared.pub_head or error() +local show_saved = Shared.show_saved or error() +local Pic = require "site:/lib/Pic.luan" +local get_pic_by_id = Pic.get_by_id or error() +local User = require "site:/lib/User.luan" +local get_user_by_id = User.get_by_id or error() +local Link = require "site:/lib/Link.luan" +local get_owner_links = Link.get_owner_links or error() + + +return function() + local pic = Http.request.parameters.pic or error() + pic = get_pic_by_id(pic) + if pic == nil then + Http.response.send_error(404) + return + end + local pic_title = pic.title + local pic_id = pic.id + local links = get_owner_links(pic_id) + local user = get_user_by_id(pic.user_id) or error() + local title = user.html_title() + local is_saved = Http.request.parameters.saved ~= nil + local saved = is_saved and "?saved" or "" + local back_path = "/"..user.name..saved + Io.stdout = Http.response.text_writer() +%> +<!doctype html> +<html pic> + <head> + <script> + window.Page = <%=json_string(pic_title)%>; + </script> +<% pub_head(user) %> + <title>Link My Style | <%=title%> | <%= html_encode(pic_title) %></title> + </head> + <body colored> +<% if is_saved then + show_saved("/pic.html?pic="..pic_id) + end %> + <div pub_background_img></div> + <div pub_content> + <div back> + <a href="<%=back_path%>#p-<%=pic_id%>"><img src="/images/keyboard_backspace.svg"></a> + </div> + <div body> + <div left> + <img pic <%=pic.title_attr()%> src="<%=pic.get_url()%>"> + <div hashtags><%=pic.hashtags_html(back_path)%></div> + </div> + <div outer_links> + <div links> +<% for _, link in ipairs(links) do %> + <a link=x href="<%=link.url%>"><%=html_encode(link.title)%></a> +<% end %> + </div> + </div> + </div> + </div> + </body> +</html> +<% +end