update homepage draft and other pages

This commit is contained in:
2026-08-29 11:38:16 +00:00
parent 6452331ee7
commit 97ff9852cd
38 changed files with 2185 additions and 111 deletions

View File

@@ -0,0 +1,26 @@
import { db } from "$lib/db"
import { blogArticles } from "$lib/db/schema";
import { redirect } from "@sveltejs/kit";
import type { PageServerLoad } from "./$types.js";
export const load: PageServerLoad = async () => {
const articles = await db.select().from(blogArticles)
return {
blogArticles: articles
}
}
export const actions = {
default: async ({ request }): Promise<Response> => {
const formData = await request.formData();
const blogArticle = await db.insert(blogArticles).values({
title: formData.get('title')?.toString(),
slug: formData.get('slug')?.toString(),
content: formData.get('content')?.toString()
}).returning();
return redirect(303, `/blog/${blogArticle[0].slug}`);
}
}

View File

@@ -0,0 +1,28 @@
<script lang="ts">
import { enhance } from '$app/forms';
let { data } = $props();
let createNewArticlePopup = $state(false);
</script>
<div class="text-center py-8 gap-2 flex align-center justify-center">
<h1 class="text-2xl">Blog (Stan's yapping corner)</h1>
<button onclick={() => createNewArticlePopup = true} class="bg-gray-800 rounded px-4 py-2 text-white font-bold">Write new article</button>
</div>
{#each data.blogArticles as article}
<div class="flex">
<a href="/blog/${article.slug}">{article.title}</a>
<p>{article.createdAt?.toDateString()}</p>
</div>
{/each}
{#if createNewArticlePopup}
<form method="POST" use:enhance>
<div>
<h2>Create New Article</h2>
</div>
</form>
{/if}

View File

@@ -0,0 +1,22 @@
import { db } from "$lib/db"
import { blogArticles } from "$lib/db/schema";
import { eq } from "drizzle-orm";
import type { PageServerLoad } from "./$types.js";
import { fail } from "@sveltejs/kit";
export const load: PageServerLoad = async ({params }) => {
const article = await db.select().from(blogArticles).where(eq(blogArticles.slug, params.slug))
if (article.length === 0) {
return fail(404, { message: "Article not found" });
}
return {
blogArticle: article[0]
}
}
export const actions = {
}

View File

@@ -0,0 +1,2 @@
l