首页右栏接入单页入口与公告置顶/全部页;Markdown 编辑器支持可视化时间线与 Git 导入;隐藏块改为 [hide]/[timeline] 命名闭合,并修复单页/公告 GORM 更新只改 updated_at 的问题。 Co-authored-by: Cursor <cursoragent@cursor.com>
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import type { MetadataRoute } from "next";
|
|
import { fetchPosts, fetchAnnouncementsPage, fetchOverview } from "@/lib/api";
|
|
|
|
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
|
const baseUrl = "http://localhost:3000";
|
|
const entries: MetadataRoute.Sitemap = [
|
|
{ url: `${baseUrl}/`, lastModified: new Date(), changeFrequency: "daily", priority: 1 },
|
|
{
|
|
url: `${baseUrl}/announcements`,
|
|
lastModified: new Date(),
|
|
changeFrequency: "daily",
|
|
priority: 0.7,
|
|
},
|
|
];
|
|
|
|
try {
|
|
const { posts } = await fetchPosts(1, 100);
|
|
for (const post of posts) {
|
|
entries.push({
|
|
url: `${baseUrl}/post/${post.id}`,
|
|
lastModified: new Date(post.created_at),
|
|
changeFrequency: "weekly",
|
|
priority: 0.6,
|
|
});
|
|
}
|
|
} catch {
|
|
/* 忽略 API 错误 */
|
|
}
|
|
|
|
try {
|
|
const { announcements } = await fetchAnnouncementsPage(1, 100);
|
|
for (const a of announcements) {
|
|
entries.push({
|
|
url: `${baseUrl}/announcement/${a.id}`,
|
|
lastModified: new Date(a.updated_at || a.created_at),
|
|
changeFrequency: "weekly",
|
|
priority: 0.5,
|
|
});
|
|
}
|
|
} catch {
|
|
/* 忽略 */
|
|
}
|
|
|
|
// 公开单页列表 API 尚未提供:用 overview 侧栏页近似收录已发布且展示中的页面
|
|
try {
|
|
const overview = await fetchOverview();
|
|
for (const p of overview.sidebar_pages ?? []) {
|
|
entries.push({
|
|
url: `${baseUrl}/p/${p.slug}`,
|
|
lastModified: new Date(),
|
|
changeFrequency: "monthly",
|
|
priority: 0.4,
|
|
});
|
|
}
|
|
} catch {
|
|
/* 忽略 */
|
|
}
|
|
|
|
return entries;
|
|
}
|