Files
jiang13-bbs/frontend/lib/canonicalMeta.ts
freefire 40bbad2c82 公开页补齐自引用 Canonical 与按类型的结构化数据,图片补上说明文字。
后台设置和内容编辑改成可导航布局;部署用访客 origin 生成 Canonical,避免落到容器地址。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-20 00:11:24 +08:00

23 lines
786 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { headers } from "next/headers";
import { canonicalFields, metadataBaseURL, type QueryBag } from "@/lib/siteUrl";
import type { Metadata } from "next";
/**
* 请求时再读 SITE_URL,避免预渲染把构建环境的 origin 打进 HTML。
* 使用 headers() 而非 connection():后者会把 metadata 推迟到 </head> 之后,
* 插件只扫 head 时仍显示 Missing。
* 根布局只设 metadataBase,各公开页再调本函数写入自身 Canonical。
*/
export async function requestCanonical(
pathname: string,
query?: QueryBag
): Promise<Pick<Metadata, "alternates">> {
await headers();
return canonicalFields(pathname, query);
}
export async function requestMetadataBase(): Promise<URL | undefined> {
await headers();
return metadataBaseURL();
}