This commit is contained in:
1 parent
19061047b1
commit
5c993bb6cc
6 files changed
+18
-14
No files matched your search
@@ -3,9 +3,10 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, platform }) => {
|
export const load: PageServerLoad = async ({ params, platform, parent }) => {
|
||||||
const db = platform?.env?.DB;
|
const db = platform?.env?.DB;
|
||||||
const slug = params.slug;
|
const slug = params.slug;
|
||||||
|
const { aliases } = await parent();
|
||||||
|
|
||||||
if (!db) {
|
if (!db) {
|
||||||
throw error(500, '数据库未连接');
|
throw error(500, '数据库未连接');
|
||||||
@@ -28,7 +29,7 @@ export const load: PageServerLoad = async ({ params, platform }) => {
|
|||||||
}>();
|
}>();
|
||||||
|
|
||||||
if (!page) {
|
if (!page) {
|
||||||
throw error(404, '该页面不存在');
|
throw error(404, `该${aliases?.page || '页面'}不存在`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -37,6 +38,6 @@ export const load: PageServerLoad = async ({ params, platform }) => {
|
|||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
if ((err as any)?.status === 404) throw err;
|
if ((err as any)?.status === 404) throw err;
|
||||||
console.error('Error loading page:', err);
|
console.error('Error loading page:', err);
|
||||||
throw error(500, '加载页面失败');
|
throw error(500, '读取详情失败');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -26,6 +26,6 @@ export const load: PageServerLoad = async ({ platform }) => {
|
|||||||
};
|
};
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error('Error fetching public categories list:', err);
|
console.error('Error fetching public categories list:', err);
|
||||||
throw error(500, '读取分类列表失败');
|
throw error(500, '读取列表失败');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -25,8 +25,9 @@ function createExcerpt(source: string): string {
|
|||||||
return plainText ? `${plainText}...` : '';
|
return plainText ? `${plainText}...` : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ platform, params, url }) => {
|
export const load: PageServerLoad = async ({ platform, params, url, parent }) => {
|
||||||
const db = platform?.env.DB;
|
const db = platform?.env.DB;
|
||||||
|
const { aliases } = await parent();
|
||||||
if (!db) throw error(500, '数据库未连接');
|
if (!db) throw error(500, '数据库未连接');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -34,7 +35,7 @@ export const load: PageServerLoad = async ({ platform, params, url }) => {
|
|||||||
.prepare('SELECT id, name, slug FROM categories WHERE slug = ? COLLATE NOCASE')
|
.prepare('SELECT id, name, slug FROM categories WHERE slug = ? COLLATE NOCASE')
|
||||||
.bind(params.slug)
|
.bind(params.slug)
|
||||||
.first<{ id: number; name: string; slug: string }>();
|
.first<{ id: number; name: string; slug: string }>();
|
||||||
if (!category) throw error(404, '该分类不存在');
|
if (!category) throw error(404, `该${aliases?.category || '分类'}不存在`);
|
||||||
|
|
||||||
const countResult = await db
|
const countResult = await db
|
||||||
.prepare('SELECT COUNT(*) AS total FROM posts WHERE category_id = ?')
|
.prepare('SELECT COUNT(*) AS total FROM posts WHERE category_id = ?')
|
||||||
@@ -95,6 +96,6 @@ export const load: PageServerLoad = async ({ platform, params, url }) => {
|
|||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
if (isHttpError(cause, 404)) throw cause;
|
if (isHttpError(cause, 404)) throw cause;
|
||||||
console.error('Error loading category posts:', cause);
|
console.error('Error loading category posts:', cause);
|
||||||
throw error(500, '读取分类内容列表失败');
|
throw error(500, '读取列表失败');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -26,6 +26,6 @@ export const load: PageServerLoad = async ({ platform }) => {
|
|||||||
};
|
};
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error('Error fetching public series list:', err);
|
console.error('Error fetching public series list:', err);
|
||||||
throw error(500, '读取系列列表失败');
|
throw error(500, '读取列表失败');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
import { error, isHttpError } from '@sveltejs/kit';
|
import { error, isHttpError } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ platform, params }) => {
|
export const load: PageServerLoad = async ({ platform, params, parent }) => {
|
||||||
const db = platform?.env?.DB;
|
const db = platform?.env?.DB;
|
||||||
|
const { aliases } = await parent();
|
||||||
if (!db) throw error(500, '数据库未连接');
|
if (!db) throw error(500, '数据库未连接');
|
||||||
try {
|
try {
|
||||||
const series = await db
|
const series = await db
|
||||||
.prepare('SELECT id, name, slug FROM series WHERE slug = ?')
|
.prepare('SELECT id, name, slug FROM series WHERE slug = ?')
|
||||||
.bind(params.slug)
|
.bind(params.slug)
|
||||||
.first<{ id: number; name: string; slug: string }>();
|
.first<{ id: number; name: string; slug: string }>();
|
||||||
if (!series) throw error(404, '系列不存在');
|
if (!series) throw error(404, `${aliases?.series || '系列'}不存在`);
|
||||||
const { results } = await db
|
const { results } = await db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT id, slug, title, series_weight, published_at
|
`SELECT id, slug, title, series_weight, published_at
|
||||||
@@ -33,6 +34,6 @@ export const load: PageServerLoad = async ({ platform, params }) => {
|
|||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
if (isHttpError(err, 404)) throw err;
|
if (isHttpError(err, 404)) throw err;
|
||||||
console.error('Error fetching series detail:', err);
|
console.error('Error fetching series detail:', err);
|
||||||
throw error(500, '读取系列失败');
|
throw error(500, '读取详情失败');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -25,8 +25,9 @@ function createExcerpt(source: string): string {
|
|||||||
return plainText ? `${plainText}...` : '';
|
return plainText ? `${plainText}...` : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ platform, params, url }) => {
|
export const load: PageServerLoad = async ({ platform, params, url, parent }) => {
|
||||||
const db = platform?.env.DB;
|
const db = platform?.env.DB;
|
||||||
|
const { aliases } = await parent();
|
||||||
if (!db) throw error(500, '数据库还未成功相连');
|
if (!db) throw error(500, '数据库还未成功相连');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -34,7 +35,7 @@ export const load: PageServerLoad = async ({ platform, params, url }) => {
|
|||||||
.prepare('SELECT id, name FROM tags WHERE name = ? COLLATE NOCASE')
|
.prepare('SELECT id, name FROM tags WHERE name = ? COLLATE NOCASE')
|
||||||
.bind(params.tag)
|
.bind(params.tag)
|
||||||
.first<{ id: number; name: string }>();
|
.first<{ id: number; name: string }>();
|
||||||
if (!tag) throw error(404, '尚未录入此标签或原归类已被卸除');
|
if (!tag) throw error(404, `未找到该${aliases?.tag || '标签'}`);
|
||||||
|
|
||||||
const countResult = await db
|
const countResult = await db
|
||||||
.prepare('SELECT COUNT(*) AS total FROM post_tags WHERE tag_id = ?')
|
.prepare('SELECT COUNT(*) AS total FROM post_tags WHERE tag_id = ?')
|
||||||
@@ -96,6 +97,6 @@ export const load: PageServerLoad = async ({ platform, params, url }) => {
|
|||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
if (isHttpError(cause, 404)) throw cause;
|
if (isHttpError(cause, 404)) throw cause;
|
||||||
console.error('Error loading tag posts:', cause);
|
console.error('Error loading tag posts:', cause);
|
||||||
throw error(500, '读取分类标签对应内容列表受阻中断');
|
throw error(500, '读取列表失败');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user