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

@@ -9,6 +9,8 @@ import { apiUnlockPost, apiUnlockPostPassword } from "@/lib/api";
import { CSRF_COOKIE } from "@/lib/cookies";
import { toast } from "@/lib/toast";
import { hideKindLabel, type HideKind } from "@/lib/hideBlocks";
import { postPath } from "@/lib/urlStyle";
import { useUrlStyle } from "@/components/SiteBrandProvider";
/** 若浏览器尚无 CSRF cookie,请求公开接口以触发后端签发 */
async function ensureGuestCSRF() {
@@ -44,6 +46,7 @@ export default function MdHideBlock({
children,
}: MdHideBlockProps) {
const router = useRouter();
const urlStyle = useUrlStyle();
const pwdErrId = useId();
const [busy, setBusy] = useState(false);
const [pwd, setPwd] = useState("");
@@ -51,7 +54,9 @@ export default function MdHideBlock({
const label = hideKindLabel(kind);
const loginTo =
loginHref ||
(postId ? `/login?redirect=${encodeURIComponent(`/post/${postId}`)}` : "/login");
(postId
? `/login?redirect=${encodeURIComponent(postPath(urlStyle, postId))}`
: "/login");
if (locked) {
const unlockPoints = async () => {
@@ -145,7 +150,7 @@ export default function MdHideBlock({
<Link
href={
postId
? `/login?redirect=${encodeURIComponent(`/post/${postId}#comment-input`)}`
? `/login?redirect=${encodeURIComponent(`${postPath(urlStyle, postId)}#comment-input`)}`
: loginTo
}
className="btn btn-primary"