- rehype-link-cards.ts 构建期插件:段落仅含一个链接才转卡(内联链接 保持普通样式);fetch OG/twitter 元信息(UA 伪装、4s 超时、只读前 200KB)+ favicon 兜底;任何失败回落普通链接,构建绝不因外部站点挂 - content/.link-cache.json 入仓缓存(30 天刷新,构建确定性与零重复 请求);单篇上限 10 卡、并发 4,超出回落 - LinkCardStyles.astro 灰阶卡片样式:hairline+圆角、favicon 16px、 标题一行/描述两行截断、域名 mono、OG 图右侧 88px(无图不占位)、 hover 1px 微浮(reduced-motion 豁免)、纯 CSS 零 JS - 安全:抓取内容全 escaping、图片地址仅 http(s) - @astrojs/markdown-remark 依赖(Astro 7 换默认 markdown 处理器后 自定义插件必须经此包生效) - 样张 content/posts/link-cards-test.md(tags 含 hidden,活样例不列出) 修复说明:264148f 提交时误带入 archives 页面对 LinkCardStyles 的 import(两车道共改同一文件),本笔补全组件与插件,恢复构建仓可用。 教训:跨车道共改文件,staged 前必须看 diff 归属。 车道:op-artalk;收编复验:本地构建 45 页 + 卡片渲染(后续专项复验) 验证: pnpm astro build 45 页 exit 0;link-cards 样张页渲染正常 Spec: none (链接卡片,车道级交付) Co-authored-by: GLM-5.3
38 lines
1.4 KiB
JavaScript
38 lines
1.4 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';
|
||
import rehypeLinkCards, { linkCardsReport } from './src/lib/rehype-link-cards';
|
||
|
||
// 构建透明(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(), linkCardsReport()],
|
||
markdown: {
|
||
// 独立成段的裸链接 → OG 预览卡(构建期抓取,失败回落普通链接;见 src/lib/rehype-link-cards.ts)
|
||
rehypePlugins: [rehypeLinkCards],
|
||
},
|
||
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),
|
||
},
|
||
},
|
||
});
|