feat: 可配置站点 URL 风格
- 新增 urlStyle 工具与测试:postPath/userPath/sitePagePath 统一生成链接 - 管理端新增 UrlStylePanel 设置面板,settings 服务与 handler 适配 - 全站路由链接与 JSON-LD/sitemap 切换为统一 URL 生成 - middleware 与相关组件适配
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
SiteDocMasthead,
|
||||
} from "@/components/site-doc";
|
||||
import { requestCanonical } from "@/lib/canonicalMeta";
|
||||
import { announcementPath } from "@/lib/urlStyle";
|
||||
import { webPageJsonLd } from "@/lib/jsonLd";
|
||||
import JsonLd from "@/components/JsonLd";
|
||||
|
||||
@@ -28,6 +29,7 @@ export async function generateMetadata({ params }: PageProps): Promise<Metadata>
|
||||
const { id } = await params;
|
||||
const data = await fetchAnnouncementDetail(id).catch(() => null);
|
||||
if (!data) return { title: "公告不存在" };
|
||||
const urlStyle = (await getPublicSettingsCached()).url_style;
|
||||
return {
|
||||
title: data.announcement.title,
|
||||
description: `站点公告 · ${data.announcement.tag}`,
|
||||
@@ -37,7 +39,7 @@ export async function generateMetadata({ params }: PageProps): Promise<Metadata>
|
||||
type: "article",
|
||||
publishedTime: data.announcement.created_at,
|
||||
},
|
||||
...(await requestCanonical(`/announcement/${data.announcement.id}`)),
|
||||
...(await requestCanonical(announcementPath(urlStyle, data.announcement.id))),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,6 +61,7 @@ export default async function AnnouncementPage({ params }: PageProps) {
|
||||
const announcements = overview?.announcements ?? [];
|
||||
const canManagePages = !!me.user && isAdminOrAbove(me.user.role);
|
||||
const siteLead = settings.site_description?.trim() || undefined;
|
||||
const urlStyle = settings.url_style;
|
||||
const toc = extractToc(a.content);
|
||||
const headingToc = markdownHeadingToc(toc);
|
||||
const readingMinutes = estimateReadingMinutes(a.content, a.title.length);
|
||||
@@ -77,7 +80,7 @@ export default async function AnnouncementPage({ params }: PageProps) {
|
||||
const jsonLd = webPageJsonLd({
|
||||
type: "Article",
|
||||
name: a.title,
|
||||
path: `/announcement/${a.id}`,
|
||||
path: announcementPath(urlStyle, a.id),
|
||||
datePublished: a.created_at,
|
||||
dateModified: a.updated_at,
|
||||
articleSection: "站点公告",
|
||||
|
||||
Reference in New Issue
Block a user