This commit is contained in:
z.ai committed 2026-10-08 11:09:37 +08:00
1 parent c1541b80df
commit b4c7908029
97 files changed
+12403 -154

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
/** 合并 className:clsx 处理条件类,tailwind-merge 消解冲突的 Tailwind 类 */
export function cn(...inputs: ClassValue[]): string {
return twMerge(clsx(inputs));
}
/** 将日期格式化为中文可读形式,如 2025 年 3 月 8 日 */
export function formatDate(date: string, locale = "zh-CN"): string {
return new Intl.DateTimeFormat(locale, {
year: "numeric",
month: "long",
day: "numeric",
timeZone: "UTC",
}).format(new Date(`${date}T00:00:00Z`));
}
/** 机器可读日期,用于 <time dateTime> */
export function toDateTimeAttribute(date: string): string {
return new Date(`${date}T00:00:00Z`).toISOString();
}
/** 拼接绝对 URL,用于 canonical / OG / sitemap */
export function absoluteUrl(base: string, pathname: string): string {
const base$ = base.replace(/\/+$/, "");
const path$ = pathname.startsWith("/") ? pathname : `/${pathname}`;
return `${base$}${path$}`;
}