feat: 新增站点版本与编译时间页脚展示,添加构建信息模块

创建站点构建信息模块,从package.json读取版本号,格式化编译时间为上海时区展示文案,添加异常容错并在页脚展示相关信息。
This commit is contained in:
2026-09-05 20:10:42 +08:00
parent fc6ed1631a
commit ac5a2cd66d
3 changed files with 46 additions and 1 deletions
File diff suppressed because one or more lines are too long
+4
View File
@@ -1,5 +1,6 @@
import { Button } from "@/components/ui/button";
import Link from "next/link";
import { SITE_BUILD_LABEL, SITE_VERSION } from "@/lib/site-build";
function Footer() {
return (
@@ -7,6 +8,9 @@ function Footer() {
<div className="px-4 py-4 text-center text-sm text-muted-foreground">
&copy; {new Date().getFullYear()} Koring Team. All rights reserved. |
</div>
<div className="px-4 pb-4 text-center text-xs text-muted-foreground/70">
v{SITE_VERSION} · {SITE_BUILD_LABEL}UTC+8
</div>
<div className="px-4 py-4 text-center text-sm text-muted-foreground">
Koring Launcher Minecraft Mojang StudiosMicrosoft
</div>
+41
View File
@@ -0,0 +1,41 @@
import pkg from "../package.json";
/**
* 站点自身构建信息(仅服务端使用)
*
* - SITE_VERSION 版本号:读取 package.json
* - SITE_BUILD_ISO 编译时间:模块首次求值时刻(静态页在 next build 预渲染时烘焙冻结;
* dev 模式下为每次服务启动/重载时刻,属预期行为)
*/
export const SITE_VERSION: string = pkg.version || "0.0.0";
export const SITE_BUILD_ISO: string = new Date().toISOString();
/** 编译时间展示文案(固定 Asia/Shanghai,与服务端时区无关) */
export const SITE_BUILD_LABEL: string = (() => {
try {
const d = new Date(SITE_BUILD_ISO);
const fmt = new Intl.DateTimeFormat("zh-CN", {
timeZone: "Asia/Shanghai",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
hour12: false,
});
const parts = fmt.formatToParts(d);
const get = (type: string) =>
parts.find((x) => x.type === type)?.value || "";
return `${get("year")}-${get("month")}-${get("day")} ${get("hour")}:${get(
"minute"
)}`;
} catch {
// 兜底:本地时间
const d = new Date(SITE_BUILD_ISO);
const p2 = (n: number) => String(n).padStart(2, "0");
return `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())} ${p2(
d.getHours()
)}:${p2(d.getMinutes())}`;
}
})();