include "page.wl" let post_id = $args(0) let posts = $query("SELECT U.username, P.title, P.content FROM Posts as P, Users as U WHERE P.id=? AND U.id=P.author", post_id) let comments = $query("SELECT C.id, U.username, C.content, C.parent_post, C.parent_comment FROM Comments as C, Users as U WHERE C.parent_post=? AND U.id=C.author", post_id) let lookup = {} for comment in comments: { comment.child = [] lookup[comment.id] = comment } let root_comments = [] for comment in comments: { if comment.parent_comment == none: root_comments << comment else lookup[comment.parent_comment].child << comment } let post = posts[0] let style = let main =
\{escape post.title}
submitted 3 hours ago by \{escape post.username} | \{len comments}
\{escape post.content}
reply
\if len(root_comments) == 0:
No comments
else for comment in root_comments: render_comment(post_id, comment)
procedure render_comment(post_id, comment) {
\{escape comment.content}
\if $login_user_id != none:
reply
\for child in comment.child: render_comment(post_id, child)
} page(post.title, $login_user_id, style, main)