add blog editor

This commit is contained in:
2026-08-31 16:39:56 +00:00
parent d793400336
commit 4822125787
13 changed files with 447 additions and 60 deletions

View File

@@ -0,0 +1,35 @@
import { db } from '$lib/server/db';
import { blogArticles } from '$lib/server/db/schema';
import { isAdmin } from '$lib/server/auth';
import { eq } from 'drizzle-orm';
import type { PageServerLoad } from './$types.js';
import { error, redirect } from '@sveltejs/kit';
export const load: PageServerLoad = async (event) => {
const [article] = await db
.select()
.from(blogArticles)
.where(eq(blogArticles.slug, event.params.slug));
if (!article) {
return error(404, { message: 'Article not found' });
}
const admin = isAdmin(event);
if (article.status !== 'published') {
if (!admin) {
return error(404, { message: 'Article not found' });
}
// Drafts are only ever viewed/edited through the editor.
return redirect(303, `/blog/${article.slug}/edit`);
}
return {
blogArticle: article,
isAdmin: admin
};
};
export const actions = {};