General fixes for cWEB and updated WL

This commit is contained in:
2025-10-16 15:48:49 +02:00
parent 0da40c6659
commit 04fcad87f0
12 changed files with 500 additions and 243 deletions
+4 -3
View File
@@ -42,8 +42,9 @@ let style =
let main =
<main>
\if len(posts) == 0:
\if len(posts) == 0: {
<div id="no-posts">There are no posts yet!</div>
}
\for post in posts: {
@@ -55,10 +56,10 @@ let main =
<div class="item">
<div>
<a href=\'"'\link\'"'>\escape(post.title)</a>
<a href="\{link}">\{escape post.title}</a>
</div>
<div>
<span>\escape(post.date)</span> | <span>\escape(post.num_comments) comments</span>
<span>\{escape post.date}</span> | <span>\{escape post.num_comments} comments</span>
</div>
</div>
}
+70 -69
View File
@@ -1,75 +1,76 @@
procedure page(title, login_user_id, style, main)
procedure page(title, login_user_id, style, main) {
<html>
<head>
<meta charset="UTF-8" />
<title>CN - \escape(title)</title>
<style>
body {
line-height: 200%;
font-family: monospace;
max-width: 800px;
margin: 20px auto;
}
nav {
overflow: auto;
background: #5780C9;
color: #6E93D4;
padding: 5px 10px;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
}
nav div {
float: left
}
nav div:last-child {
float: right
}
nav a {
font-size: 14px;
color: #1D2B42;
}
nav a.current {
font-weight: bold;
}
main {
padding: 5px 10px;
background: #F7E6C0;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
}
footer {
padding: 5px 10px;
}
</style>
\(style)
<script src="https://cdnjs.cloudflare.com/ajax/libs/htmx/1.9.2/htmx.min.js"></script>
</head>
<body>
<nav>
<div>
<a href="/index">index</a>
\if login_user_id != none: {
"|\n"
<a href="/write">write</a>
<head>
<meta charset="UTF-8" />
<title>CN - \{escape title}</title>
<style>
body {
line-height: 200%;
font-family: monospace;
max-width: 800px;
margin: 20px auto;
}
</div>
\if login_user_id == none:
nav {
overflow: auto;
background: #5780C9;
color: #6E93D4;
padding: 5px 10px;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
}
nav div {
float: left
}
nav div:last-child {
float: right
}
nav a {
font-size: 14px;
color: #1D2B42;
}
nav a.current {
font-weight: bold;
}
main {
padding: 5px 10px;
background: #F7E6C0;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
}
footer {
padding: 5px 10px;
}
</style>
\{style}
<script src="https://cdnjs.cloudflare.com/ajax/libs/htmx/1.9.2/htmx.min.js"></script>
</head>
<body>
<nav>
<div>
<a href="/login">log-in</a>
|
<a href="/signup">sign-up</a>
<a href="/index">index</a>
\if login_user_id != none: {
"|\n"
<a href="/write">write</a>
}
</div>
else
<div>
<a href="">settings</a>
|
<a href="/api/logout">log-out</a>
</div>
</nav>
\main
<footer>
Made with love by cozis
</footer>
</body>
\if login_user_id == none:
<div>
<a href="/login">log-in</a>
|
<a href="/signup">sign-up</a>
</div>
else
<div>
<a href="">settings</a>
|
<a href="/api/logout">log-out</a>
</div>
</nav>
\{main}
<footer>
Made with love by cozis
</footer>
</body>
</html>
}
+41 -41
View File
@@ -180,13 +180,13 @@ let main =
<main>
<div class="thread-header">
<div class="thread-title">
<span>\escape(post.title)</span>
<span>\{escape post.title}</span>
</div>
<div class="thread-meta">
submitted 3 hours ago by <a href="">\escape(post.username)</a> | <a href="">\len(comments)</a>
submitted 3 hours ago by <a href="">\{escape post.username}</a> | <a href="">\{len comments}</a>
</div>
<div class="thread-text">
<pre>\escape(post.content)</pre>
<pre>\{escape post.content}</pre>
</div>
<details>
<summary>
@@ -194,50 +194,14 @@ let main =
</summary>
<div class="add-comment">
<form action="/api/comment" method="POST">
<input type="hidden" name="csrf" value=\'"'\$csrf\'"' />
<input type="hidden" name="parent_post" value=\'"'\post_id\'"' />
<input type="hidden" name="csrf" value="\{$csrf}" />
<input type="hidden" name="parent_post" value="\{post_id}" />
<textarea name="content" placeholder="Add a comment..."></textarea>
<input type="submit" vaue="Publish" />
</form>
</div>
</details>
</div>
\procedure render_comment(post_id, comment)
<div class="comment">
<div class="vote-buttons">
<a href=""></a>
<a href=""></a>
</div>
<div class="comment-content">
<div class="comment-meta">
<a href="">\escape(comment.username)</a> 2 hours ago
</div>
<div class="comment-text">
<pre>\escape(comment.content)</pre>
</div>
\if $login_user_id != none:
<details>
<summary>
reply
</summary>
<div class="add-comment">
<form action="/api/comment" method="POST">
<input type="hidden" name="csrf" value=\'"'\$csrf\'"' />
<input type="hidden" name="parent_post" value=\'"'\post_id\'"' />
<input type="hidden" name="parent_comment" value=\'"'\comment.id\'"' />
<textarea name="content" placeholder="Add a comment..."></textarea>
<input type="submit" vaue="Publish" />
</form>
</div>
</details>
</div>
<div class="comment-child">
\for child in comment.child:
render_comment(post_id, child)
</div>
</div>
\if len(root_comments) == 0:
<div id="no-comments">
No comments
@@ -246,4 +210,40 @@ let main =
render_comment(post_id, comment)
</main>
procedure render_comment(post_id, comment) {
<div class="comment">
<div class="vote-buttons">
<a href=""></a>
<a href=""></a>
</div>
<div class="comment-content">
<div class="comment-meta">
<a href="">\{escape comment.username}</a> 2 hours ago
</div>
<div class="comment-text">
<pre>\{escape comment.content}</pre>
</div>
\if $login_user_id != none:
<details>
<summary>
reply
</summary>
<div class="add-comment">
<form action="/api/comment" method="POST">
<input type="hidden" name="csrf" value="\{$csrf}" />
<input type="hidden" name="parent_post" value="\{post_id}" />
<input type="hidden" name="parent_comment" value="\{comment.id}" />
<textarea name="content" placeholder="Add a comment..."></textarea>
<input type="submit" vaue="Publish" />
</form>
</div>
</details>
</div>
<div class="comment-child">
\for child in comment.child:
render_comment(post_id, child)
</div>
</div>
}
page(post.title, $login_user_id, style, main)
-73
View File
@@ -1,73 +0,0 @@
include "page.wl"
let posts = $query("SELECT title, content FROM Posts WHERE id=?", $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 roots = []
for comment in comments: {
if comment.parent_comment == none:
roots << comment
else
lookup[comment.parent_comment].child << comment
}
comments = roots
let post = posts[0]
let style =
<style>
.child {
border-left: 3px solid #ccc;
padding-left: 10px;
}
form textarea {
width: 100%;
}
</style>
procedure render_comment(parent)
<div>
<a href="">\parent.username</a>
<p>
\parent.content
</p>
<div class="child">
\if $login_user_id != none:
<form action="/api/comment" method="POST">
<input type="hidden" name="parent_post" value=\'"'\$post_id\'"' />
<input type="hidden" name="parent_comment" value=\'"'\parent.id\'"' />
<textarea name="content"></textarea>
<input type="submit" vaue="Publish" />
</form>
\for child in parent.child:
render_comment(child)
</div>
</div>
let main =
<main>
<h3>\post.title</h3>
<p>\post.content</p>
<div>
<form action="/api/comment" method="POST">
<input type="hidden" name="parent_post" value=\'"'\$post_id\'"' />
<textarea name="content"></textarea>
<input type="submit" vaue="Publish" />
</form>
</div>
\if len comments == 0:
<span>No comments yet!</span>
else for comment in comments:
render_comment(comment)
</main>
page(post.title, $login_user_id, style, main)
+1 -1
View File
@@ -60,7 +60,7 @@ let main =
<main>
<form action="/api/post" method="POST">
<input type="hidden" name="csrf" value=\'"'\$csrf\'"' />
<input type="hidden" name="csrf" value="\{$csrf}" />
<input type="text" id="title" name="title" placeholder="Title" required />
<div class="checkbox-row">