feat: 可配置站点 URL 风格

- 新增 urlStyle 工具与测试:postPath/userPath/sitePagePath 统一生成链接
- 管理端新增 UrlStylePanel 设置面板,settings 服务与 handler 适配
- 全站路由链接与 JSON-LD/sitemap 切换为统一 URL 生成
- middleware 与相关组件适配
This commit is contained in:
2026-09-27 04:01:42 +08:00
parent 1d862a0dd3
commit 7a44c1f2cf
64 changed files with 1183 additions and 200 deletions

View File

@@ -18,6 +18,8 @@ import {
import { toast } from "@/lib/toast";
import Avatar from "@/components/Avatar";
import { useAllowComments } from "@/components/CommentsPolicyProvider";
import { postPath, userPath } from "@/lib/urlStyle";
import { useUrlStyle } from "@/components/SiteBrandProvider";
export default function PostInteractPanels({
postId,
@@ -286,6 +288,7 @@ function PollPanel({
loggedIn: boolean;
}) {
const router = useRouter();
const urlStyle = useUrlStyle();
const [sel, setSel] = useState<number[]>(state.my_options || []);
const [busy, setBusy] = useState(false);
const showResults = state.closed || (state.my_options && state.my_options.length > 0);
@@ -418,7 +421,7 @@ function PollPanel({
<ul className="j13-poll-voters">
{namedVoters.map((v) => (
<li key={v.id}>
<Link href={`/u/${v.id}`} className="j13-poll-voter">
<Link href={userPath(urlStyle, v.id)} className="j13-poll-voter">
<Avatar name={v.nickname || v.username} src={v.avatar || undefined} size={16} />
{v.nickname || v.username}
</Link>
@@ -445,7 +448,7 @@ function PollPanel({
)}
{!loggedIn && !state.closed && (
<Link
href={`/login?redirect=${encodeURIComponent(`/post/${postId}`)}`}
href={`/login?redirect=${encodeURIComponent(postPath(urlStyle, postId))}`}
className="btn btn-line btn-sm"
>
登录后投票
@@ -559,6 +562,7 @@ function LotteryPanel({
state: LotteryState;
}) {
const router = useRouter();
const urlStyle = useUrlStyle();
const [busy, setBusy] = useState(false);
const act = async (fn: () => Promise<{ post?: unknown; error?: string }>, ok: string) => {
@@ -651,7 +655,7 @@ function LotteryPanel({
className="j13-lottery-winner-avatar"
/>
<div className="j13-lottery-winner-body">
<Link href={`/u/${w.id}`} className="j13-lottery-winner-name">
<Link href={userPath(urlStyle, w.id)} className="j13-lottery-winner-name">
{w.nickname || w.username}
</Link>
{w.prize_name ? (