fix: build errors and merging projects and homepage
This commit is contained in:
@@ -1,26 +1,29 @@
|
||||
import { db } from "$lib/db"
|
||||
import { blogArticles } from "$lib/db/schema";
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
import type { PageServerLoad } from "./$types.js";
|
||||
import { db } from '$lib/server/db';
|
||||
import { blogArticles } from '$lib/server/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)
|
||||
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();
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import { resolve } from '$app/paths';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
@@ -8,13 +9,15 @@
|
||||
|
||||
<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>
|
||||
<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}
|
||||
{#each data.blogArticles as article (article.slug)}
|
||||
<div class="flex">
|
||||
<a href="/blog/${article.slug}">{article.title}</a>
|
||||
<a href={resolve('/blog/{slug}', { slug: article.slug })}>{article.title}</a>
|
||||
<p>{article.createdAt?.toDateString()}</p>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
import { db } from "$lib/db"
|
||||
import { blogArticles } from "$lib/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from '$lib/server/db';
|
||||
import { blogArticles } from '$lib/server/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
import type { PageServerLoad } from "./$types.js";
|
||||
import { fail } from "@sveltejs/kit";
|
||||
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))
|
||||
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 fail(404, { message: 'Article not found' });
|
||||
}
|
||||
|
||||
return {
|
||||
blogArticle: article[0]
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
|
||||
}
|
||||
export const actions = {};
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
|
||||
l
|
||||
bu
|
||||
|
||||
Reference in New Issue
Block a user