This commit is contained in:
2025-10-18 18:40:17 +02:00
parent b4923376bf
commit 9a25c81a41
34 changed files with 15917 additions and 49787 deletions
+5 -4
View File
@@ -1,4 +1,4 @@
include "pages/page.wl"
include "page.wl"
let posts = $query("SELECT P.id, P.title, P.is_link, P.content, (SELECT COUNT(*) FROM Comments as C WHERE c.parent_post=P.id) as num_comments, CURRENT_TIMESTAMP as date FROM Posts as P")
@@ -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>
}
+3 -3
View File
@@ -1,5 +1,5 @@
include "pages/page.wl"
include "pages/login_and_signup_style.wl"
include "page.wl"
include "login_and_signup_style.wl"
let main =
<main>
@@ -7,7 +7,7 @@ let main =
<div id="response"></div>
<form hx-post="/api/login" hx-target="#response">
<form action="/api/login" method="POST">
<input type="text" name="username" placeholder="username" />
<input type="password" name="password" placeholder="password" />
<input type="submit" value="Log-In" />
+1 -1
View File
@@ -1,4 +1,4 @@
include "pages/page.wl"
include "page.wl"
let style =
<style>
+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>
}
+46 -43
View File
@@ -1,7 +1,8 @@
include "pages/page.wl"
include "page.wl"
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 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 = {}
@@ -179,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>
@@ -193,54 +194,56 @@ let main =
</summary>
<div class="add-comment">
<form action="/api/comment" method="POST">
<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(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="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(child)
</div>
</div>
\if len(root_comments) == 0:
<div id="no-comments">
No comments
</div>
else for comment in root_comments:
render_comment(comment)
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 "pages/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)
+3 -3
View File
@@ -1,5 +1,5 @@
include "pages/page.wl"
include "pages/login_and_signup_style.wl"
include "page.wl"
include "login_and_signup_style.wl"
let main =
<main>
@@ -7,7 +7,7 @@ let main =
<div id="response"></div>
<form hx-post="/api/signup" hx-target="#response">
<form action="/api/signup" method="POST">
<input type="text" name="username" placeholder="username" />
<input type="email" name="email" placeholder="email" />
<input type="password" name="password1" placeholder="password" />
+2 -2
View File
@@ -1,4 +1,4 @@
include "pages/page.wl"
include "page.wl"
let style =
<style>
@@ -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">