view examples/blog/src/index.html.luan @ 1712:36c28be6d432

improve html and bbcode
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 14 Jul 2022 22:14:21 -0600
parents ad5647031343
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 Io = require "luan:Io.luan"
local Html = require "luan:Html.luan"
local html_encode = Html.encode or error()
local Http = require "luan:http/Http.luan"
local Post = require "site:/lib/Post.luan"


return function()
	local query = Http.request.parameters.query

	Io.stdout = Http.response.text_writer()
%>
<!doctype html>
<html>
	<head>
		<style>
			@import "/site.css";
		</style>
	</head>
	<body>
		<h1><a href="/">Demo Blog App</a></h1>

		<form>
			<input name=query type=text value="<%= query or "" %>">
			<input type=submit value=Search>
		</form>

		<div><a href="new.html">Make New Post</a></div>

		<%
		local posts = query and Post.search(query) or Post.get_all()
		for _, post in ipairs(posts) do
			%>
			<a name="p<%= post.id %>">
			<h2><%= post.subject %></h2>
			<p>
				<%= Time.format(post.date) %>
				- <a href="edit.html?post=<%= post.id %>">Edit</a>
				- <a href="delete?post=<%= post.id %>">Delete</a>
			</p>
			<pre><%= html_encode(post.content) %></pre>
			<hr>
			<%
		end
		%>

	</body>
</html>
<%
end