This commit is contained in:
1 parent
831efac051
commit
f40b49c654
7 files changed
+13
-37
No files matched your search
@@ -23,10 +23,10 @@ export const load: PageServerLoad = async ({ platform }) => {
|
||||
try {
|
||||
const { results } = await db
|
||||
.prepare(
|
||||
`SELECT s.id, s.name, s.slug, s.description, COUNT(p.id) AS post_count
|
||||
`SELECT s.id, s.name, s.slug, COUNT(p.id) AS post_count
|
||||
FROM series s
|
||||
LEFT JOIN posts p ON p.series_id = s.id
|
||||
GROUP BY s.id, s.name, s.slug, s.description
|
||||
GROUP BY s.id, s.name, s.slug
|
||||
ORDER BY s.name COLLATE NOCASE ASC`
|
||||
)
|
||||
.all();
|
||||
@@ -36,7 +36,6 @@ export const load: PageServerLoad = async ({ platform }) => {
|
||||
id: number;
|
||||
name: string;
|
||||
slug: string;
|
||||
description: string | null;
|
||||
post_count: number;
|
||||
}>
|
||||
};
|
||||
@@ -54,16 +53,13 @@ export const actions: Actions = {
|
||||
const formData = await request.formData();
|
||||
const name = formData.get('name')?.toString().trim() || '';
|
||||
const slug = makeSlug(formData.get('slug')?.toString() || name);
|
||||
const description = formData.get('description')?.toString().trim() || null;
|
||||
|
||||
if (!name || !slug) return fail(400, { error: '系列名称和 URL 别名不能为空' });
|
||||
|
||||
try {
|
||||
const created = await db
|
||||
.prepare(
|
||||
'INSERT INTO series (name, slug, description) VALUES (?, ?, ?) RETURNING id, name, slug, description'
|
||||
)
|
||||
.bind(name, slug, description)
|
||||
.prepare('INSERT INTO series (name, slug) VALUES (?, ?) RETURNING id, name, slug')
|
||||
.bind(name, slug)
|
||||
.first();
|
||||
return { success: true, series: created };
|
||||
} catch (err: unknown) {
|
||||
@@ -83,7 +79,6 @@ export const actions: Actions = {
|
||||
const id = Number(formData.get('id'));
|
||||
const name = formData.get('name')?.toString().trim() || '';
|
||||
const slug = makeSlug(formData.get('slug')?.toString() || '');
|
||||
const description = formData.get('description')?.toString().trim() || null;
|
||||
|
||||
if (!Number.isInteger(id) || id <= 0 || !name || !slug) {
|
||||
return fail(400, { error: '系列信息不完整' });
|
||||
@@ -91,8 +86,8 @@ export const actions: Actions = {
|
||||
|
||||
try {
|
||||
await db
|
||||
.prepare('UPDATE series SET name = ?, slug = ?, description = ? WHERE id = ?')
|
||||
.bind(name, slug, description, id)
|
||||
.prepare('UPDATE series SET name = ?, slug = ? WHERE id = ?')
|
||||
.bind(name, slug, id)
|
||||
.run();
|
||||
return { success: true };
|
||||
} catch (err: unknown) {
|
||||
|
||||
@@ -68,14 +68,6 @@
|
||||
oninput={handleSlugInput}
|
||||
required
|
||||
/>
|
||||
|
||||
<label for="description">描述</label>
|
||||
<textarea
|
||||
id="description"
|
||||
name="description"
|
||||
rows="5"
|
||||
placeholder="介绍这个系列的主题和阅读顺序"></textarea>
|
||||
|
||||
<button type="submit" class="btn btn-primary">创建</button>
|
||||
</form>
|
||||
</section>
|
||||
@@ -102,12 +94,6 @@
|
||||
<input id="slug-{item.id}" name="slug" type="text" value={item.slug} required />
|
||||
</div>
|
||||
</div>
|
||||
<label for="description-{item.id}">描述</label>
|
||||
<textarea
|
||||
id="description-{item.id}"
|
||||
name="description"
|
||||
rows="3"
|
||||
value={item.description || ''}></textarea>
|
||||
<button type="submit" class="action-btn">保存修改</button>
|
||||
<a
|
||||
href={resolve('/series/[slug]', { slug: item.slug })}
|
||||
|
||||
@@ -14,7 +14,6 @@ interface PostRow {
|
||||
series_id: number | null;
|
||||
series_name: string | null;
|
||||
series_slug: string | null;
|
||||
series_description: string | null;
|
||||
series_weight: number | null;
|
||||
}
|
||||
|
||||
@@ -72,7 +71,7 @@ export const load: PageServerLoad = async ({ platform, params }) => {
|
||||
c.name as category_name, c.slug as category_slug,
|
||||
u.username as author,
|
||||
s.id as series_id, s.name as series_name, s.slug as series_slug,
|
||||
s.description as series_description, p.series_weight
|
||||
p.series_weight
|
||||
FROM posts p
|
||||
LEFT JOIN categories c ON p.category_id = c.id
|
||||
LEFT JOIN users u ON p.author_id = u.id
|
||||
@@ -100,7 +99,6 @@ export const load: PageServerLoad = async ({ platform, params }) => {
|
||||
id: number;
|
||||
name: string;
|
||||
slug: string;
|
||||
description: string | null;
|
||||
} | null = null;
|
||||
let seriesPosts: Array<{
|
||||
id: number;
|
||||
@@ -113,8 +111,7 @@ export const load: PageServerLoad = async ({ platform, params }) => {
|
||||
series = {
|
||||
id: post.series_id,
|
||||
name: post.series_name,
|
||||
slug: post.series_slug,
|
||||
description: post.series_description
|
||||
slug: post.series_slug
|
||||
};
|
||||
const seriesQuery = await db
|
||||
.prepare(
|
||||
|
||||
@@ -9,10 +9,10 @@ export const load: PageServerLoad = async ({ platform }) => {
|
||||
try {
|
||||
const { results } = await db
|
||||
.prepare(
|
||||
`SELECT s.id, s.name, s.slug, s.description, COUNT(p.id) AS post_count
|
||||
`SELECT s.id, s.name, s.slug, COUNT(p.id) AS post_count
|
||||
FROM series s
|
||||
LEFT JOIN posts p ON p.series_id = s.id
|
||||
GROUP BY s.id, s.name, s.slug, s.description
|
||||
GROUP BY s.id, s.name, s.slug
|
||||
ORDER BY s.name COLLATE NOCASE ASC`
|
||||
)
|
||||
.all();
|
||||
@@ -21,7 +21,6 @@ export const load: PageServerLoad = async ({ platform }) => {
|
||||
id: number;
|
||||
name: string;
|
||||
slug: string;
|
||||
description: string | null;
|
||||
post_count: number;
|
||||
}>
|
||||
};
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
{#each data.series as item (item.id)}
|
||||
<a href={resolve('/series/[slug]', { slug: item.slug })} class="series-card">
|
||||
<h2>{item.name}</h2>
|
||||
{#if item.description}<p>{item.description}</p>{/if}
|
||||
<span>{item.post_count} 篇文章</span>
|
||||
</a>
|
||||
{:else}
|
||||
|
||||
@@ -6,9 +6,9 @@ export const load: PageServerLoad = async ({ platform, params }) => {
|
||||
if (!db) throw error(500, '数据库未连接');
|
||||
try {
|
||||
const series = await db
|
||||
.prepare('SELECT id, name, slug, description FROM series WHERE slug = ?')
|
||||
.prepare('SELECT id, name, slug FROM series WHERE slug = ?')
|
||||
.bind(params.slug)
|
||||
.first<{ id: number; name: string; slug: string; description: string | null }>();
|
||||
.first<{ id: number; name: string; slug: string }>();
|
||||
if (!series) throw error(404, '系列不存在');
|
||||
const { results } = await db
|
||||
.prepare(
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<article class="article-detail yue">
|
||||
<div class="banner-title">
|
||||
<h1 class="post-title">{data.series.name}</h1>
|
||||
{#if data.series.description}<p class="post-meta">{data.series.description}</p>{/if}
|
||||
<span class="post-meta">{data.posts.length} 篇文章</span>
|
||||
</div>
|
||||
|
||||
<ol class="series-posts">
|
||||
|
||||
Reference in new issue
Block a user