Optimize landing server rendering

This commit is contained in:
2569718930@qq.com
2026-05-30 23:43:07 +08:00
parent 30e9513ce2
commit bf0fbe1b1d
9 changed files with 526 additions and 216 deletions
@@ -0,0 +1,35 @@
export type LandingLocale = "zh-CN" | "en-US";
export const LANDING_LOCALE_COOKIE = "polyweather.locale";
export const DEFAULT_LANDING_LOCALE: LandingLocale = "zh-CN";
export function normalizeLandingLocale(value: string | null | undefined): LandingLocale | null {
if (!value) return null;
const normalized = value.trim().toLowerCase();
if (normalized === "zh" || normalized === "zh-cn" || normalized.startsWith("zh-")) {
return "zh-CN";
}
if (normalized === "en" || normalized === "en-us" || normalized.startsWith("en-")) {
return "en-US";
}
return null;
}
export function pickLandingLocale(
cookieLocale: string | null | undefined,
acceptLanguage: string | null | undefined,
): LandingLocale {
const fromCookie = normalizeLandingLocale(cookieLocale);
if (fromCookie) return fromCookie;
for (const part of String(acceptLanguage || "").split(",")) {
const locale = normalizeLandingLocale(part.split(";")[0]);
if (locale) return locale;
}
return DEFAULT_LANDING_LOCALE;
}
export function nextLandingLocale(locale: LandingLocale): LandingLocale {
return locale === "zh-CN" ? "en-US" : "zh-CN";
}