Reorganize code and clean up Makefile

This commit is contained in:
2025-08-09 08:47:47 +02:00
parent e200f52f40
commit 890a5c48e4
22 changed files with 331 additions and 179 deletions
+20 -9
View File
@@ -1,10 +1,9 @@
include "pages/page.wl"
let posts = [
{ title: "Show HN: Kitten TTS - 25MB CPU-Only, Open-Source TTS Model", date: "3 hours ago", num_comments: 127, link: "https://github.com/KittenML/KittenTTS" },
{ title: "Open models by OpenAI", date: "15 hours ago", num_comments: 651, link: "https://openai.com/open-models/" },
{ title: "Anthropic rejects the main developer of the library they use", date: "40 minutes ago", num_comments: 437, link: "https://grell.dev/blog/ai_rejection" }
]
let posts = $query("SELECT id, title, is_link, content, 0 as num_comments, CURRENT_TIMESTAMP as date FROM Posts")
if posts == none:
posts = []
let style =
<style>
@@ -35,15 +34,27 @@ let style =
let main =
<main>
\for post in posts:
\if len(posts) == 0:
<div>There are no posts yet!</div>
\for post in posts: {
let link
if post.is_link != 0:
link = post.content
else
link = ["/post?id=", post.id]
<div class="item">
<div>
<a href=post.link>\post.title</a>
<a href=link>\post.title</a>
</div>
<div>
<span>\post.date</span> | <span><a href="/thread">\post.num_comments comments</a></span>
<span>\post.date</span> | <span><a href=link>\post.num_comments comments</a></span>
</div>
</div>
}
</main>
page("Index", $login_user_id, style, main)
page("Index", $login_user_id, style, main)
+16
View File
@@ -0,0 +1,16 @@
include "pages/page.wl"
let posts = $query("SELECT title, content FROM Posts WHERE id=?", $post_id)
let post = posts[0]
let style =
<style>
</style>
let main =
<main>
<h3>\post.title</h3>
<p>\post.content</p>
</main>
page(post.title, $login_user_id, style, main)
+82 -5
View File
@@ -2,15 +2,92 @@ include "pages/page.wl"
let style =
<style>
form {
max-width: 400px;
margin: 30px auto;
}
form input,
form textarea {
border: 0;
outline: 0;
width: 100%;
border-radius: 3px;
padding: 8px;
margin-bottom: 15px;
background: #E8D4A9;
border: 1px solid #D4C298;
}
form input:focus,
form textarea:focus {
border-color: #5780C9;
background: #fff;
}
form textarea {
height: 120px;
resize: vertical;
}
form input[type=submit] {
cursor: pointer;
background: #5780C9;
color: #F7E6C0;
}
form input[type=submit]:hover {
background: #1D2B42;
}
.checkbox-row {
margin-bottom: 15px;
}
.checkbox-row input[type="checkbox"] {
width: auto;
margin-right: 8px;
}
.checkbox-row label {
color: #1D2B42;
font-size: 14px;
cursor: pointer;
}
</style>
let main =
<main>
<form action="api/post" method="POST">
<input type="text" name="title" />
<textarea name="content"></textarea>
<input type="submit" value="Publish" />
<form action="/api/post" method="POST">
<input type="text" id="title" name="title" placeholder="Title" required />
<div class="checkbox-row">
<input type="checkbox" id="is_link" name="is_link" onchange="togglePostType()" />
<label>This is a link post</label>
</div>
<input type="url" id="url" name="link" placeholder="URL" style="display: none;" />
<textarea id="content" name="content" placeholder="Write your post here..."></textarea>
<input type="submit" value="Submit Post" />
</form>
<script>
function togglePostType() {
const checkbox = document.getElementById('is_link');
const urlInput = document.getElementById('url');
const contentTextarea = document.getElementById('content');
if (checkbox.checked) {
urlInput.style.display = 'block';
contentTextarea.style.display = 'none';
} else {
urlInput.style.display = 'none';
contentTextarea.style.display = 'block';
}
}
</script>
</main>
page("Write Post", $login_user_id, style, main)
page("Write Post", $login_user_id, style, main)