update
This commit is contained in:
@ -17,6 +17,10 @@ const { title, description, keywords } = Astro.props
|
||||
|
||||
const { locale, t, getRelativeLocaleUrl } = getI18n(Astro)
|
||||
|
||||
// 语言偏好跳转用的 localStorage key 与默认语言:注入到 <html> 的 data-*,供内联脚本读取
|
||||
const storedLocaleKey = STORED_LOCALE_KEY
|
||||
const defaultLocaleVal = DEFAULT_LOCALE
|
||||
|
||||
const SITE_NAME = config.siteName ?? "Xisoa"
|
||||
const siteTitle = title ? `${title} — ${SITE_NAME}` : SITE_NAME
|
||||
|
||||
@ -72,14 +76,14 @@ const headers = {
|
||||
}
|
||||
---
|
||||
<!doctype html>
|
||||
<html lang={locale === 'cn' ? 'zh-CN' : 'en'}>
|
||||
<html lang={locale === 'cn' ? 'zh-CN' : 'en'} data-stored-key={storedLocaleKey} data-default-locale={defaultLocaleVal}>
|
||||
<head>
|
||||
<script is:inline define:vars={{ defaultLocale: DEFAULT_LOCALE, storedKey: STORED_LOCALE_KEY }}>
|
||||
<script is:inline>
|
||||
// 记住语言偏好:若用户曾选过非默认语言,进首页(/ 或 /<default>)时自动跳到该语言首页
|
||||
(function () {
|
||||
try {
|
||||
var stored = localStorage.getItem(storedKey);
|
||||
var def = defaultLocale;
|
||||
var stored = localStorage.getItem(document.documentElement.dataset.storedKey);
|
||||
var def = document.documentElement.dataset.defaultLocale;
|
||||
var p = location.pathname;
|
||||
if (stored && stored !== def && (p === '/' || p === '/' + def)) {
|
||||
location.replace('/' + stored);
|
||||
|
||||
Reference in New Issue
Block a user