comparison src/thread.html.luan @ 11:3ed1e3f3a53a

use bbcode_to_html
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 30 Jun 2022 20:05:11 -0600
parents 9674275019bb
children ad1604c72156
comparison
equal deleted inserted replaced
10:de0cbf515ef5 11:3ed1e3f3a53a
1 local Luan = require "luan:Luan.luan" 1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error 2 local error = Luan.error
3 local ipairs = Luan.ipairs or error() 3 local ipairs = Luan.ipairs or error()
4 local Html = require "luan:Html.luan"
5 local html_encode = Html.encode or error()
6 local Parsers = require "luan:Parsers.luan"
7 local bbcode_to_html = Parsers.bbcode_to_html or error()
4 local Io = require "luan:Io.luan" 8 local Io = require "luan:Io.luan"
9 local output_of = Io.output_of or error()
5 local Http = require "luan:http/Http.luan" 10 local Http = require "luan:http/Http.luan"
6 local Shared = require "site:/lib/Shared.luan" 11 local Shared = require "site:/lib/Shared.luan"
7 local head = Shared.head or error() 12 local head = Shared.head or error()
8 local header = Shared.header or error() 13 local header = Shared.header or error()
9 local footer = Shared.footer or error() 14 local footer = Shared.footer or error()
10 local Forum = require "site:/lib/Forum.luan" 15 local Forum = require "site:/lib/Forum.luan"
11 local forum_title = Forum.title or error() 16 local forum_title = Forum.title or error()
12 local Db = require "site:/lib/Db.luan" 17 local Db = require "site:/lib/Db.luan"
13 local Post = require "site:/lib/Post.luan" 18 local Post = require "site:/lib/Post.luan"
19 local User = require "site:/lib/User.luan"
14 20
21
22 local function quoter(content,user_name)
23 return output_of( function()
24 %><blockquote><%
25 if user_name ~= nil then
26 local user = User.get_by_name(user_name)
27 if user == nil then
28 %><%= html_encode(user_name) %> wrote:<%
29 else
30 %><a href="/user_somthing"><%= html_encode(user_name) %></a> wrote:<%
31 end
32 end
33 %><%= content %><%
34 %></blockquote><%
35 end_function )
36 end
15 37
16 return function() 38 return function()
17 local root_id = Http.request.parameters.root or error() 39 local root_id = Http.request.parameters.root or error()
18 local docs, total_hits = Db.search("post_root_id:"..root_id,1,1000,{sort="id"}) 40 local docs, total_hits = Db.search("post_root_id:"..root_id,1,1000,{sort="id"})
19 local posts = Post.from_docs(docs) 41 local posts = Post.from_docs(docs)
35 <% header() %> 57 <% header() %>
36 <div content> 58 <div content>
37 <h1><%=subject_html%></h1> 59 <h1><%=subject_html%></h1>
38 <% for _, post in ipairs(posts) do %> 60 <% for _, post in ipairs(posts) do %>
39 <hr> 61 <hr>
40 <p post><%=post.content%></p> 62 <div post><%=bbcode_to_html(post.content,quoter)%></div>
41 <p> 63 <p>
42 <a href="/reply.html?parent=<%=post.id%>">reply</a> 64 <a href="/reply.html?parent=<%=post.id%>">reply</a>
43 - <a href="/edit.html?post=<%=post.id%>">edit</a> 65 - <a href="/edit.html?post=<%=post.id%>">edit</a>
44 </p> 66 </p>
45 <% end %> 67 <% end %>