Files
blog/astro.config.mjs
T
wait4xandGLM-5.3 c74815b516 feat(i18n): /en/ 双语骨架——路由/切换/hreflang/回退/AI 标注
- astro i18n(zh 默认无前缀,en /en/)+ locale.ts 路径工具
- Header 语言切换(同路径跨前缀跳转,预构建毫秒级)
- /en/index + /en/archives/{slug}(postsEn 优先,缺译回退 zh 正文
  + AiTranslatedBadge 虚线标注 TMT);en RSS(标题回退同策略)
- BaseLayout hreflang 双向 + x-default 指向 zh 源
- posts-en 集合(postsSchema.extend locked 润色锁)
- 坑:ts 端点文件误带 --- 开头会以 undefined:2:7 报 Unexpected token

验证: astro build 18 页 exit 0;/en/ 六文章路由+首页+rss 产物断言过;
      zh 侧零回归(11 页不变);hreflang 抽查 dist/index.html

Spec: 2026-10-25_add-blog-i18n
Co-authored-by: GLM-5.3
2026-10-25 09:20:16 +08:00

33 lines
1.1 KiB
JavaScript

// @ts-check
import { defineConfig } from 'astro/config';
import pagefind from 'astro-pagefind';
import sitemap from '@astrojs/sitemap';
import { execSync } from 'node:child_process';
// 构建透明(T7):commit/时间经 vite.define 注入,页脚与 /about 引用。
// 四重回退:CI 环境变量优先(GITEA_ACTIONS/GITHUB_SHA)→ 本地 git → dev 占位。
const sha =
process.env.GITEA_COMMIT_SHA ||
process.env.GITHUB_SHA ||
(() => { try { return execSync('git rev-parse HEAD').toString().trim(); } catch { return 'dev'; } })();
const date =
process.env.GITEA_COMMIT_DATE ||
process.env.GITHUB_COMMIT_DATE ||
(() => { try { return execSync('git log -1 --format=%cI').toString().trim(); } catch { return new Date().toISOString(); } })();
export default defineConfig({
site: 'https://wait4x.online',
integrations: [pagefind(), sitemap()],
i18n: {
defaultLocale: 'zh',
locales: ['zh', 'en'],
routing: { prefixDefaultLocale: false },
},
vite: {
define: {
'import.meta.env.GIT_COMMIT_SHA': JSON.stringify(sha),
'import.meta.env.GIT_COMMIT_DATE': JSON.stringify(date),
},
},
});