方案:用现成的 satteri-katex(MDAST 插件,40 行,是 rehype-katex 的移植), 而不是自己写。它跑在 MDAST 阶段,天然绕开下面这个坑。 为什么不能用 HAST 阶段做 Sätteri 把块级公式输出成 <pre><code class="language-math math-display">, 而 expressive-code 过滤所有 <pre>,会把它当成未知语言渲染成带行号的 plaintext 代码块 —— 实测 10 个块级公式全部被吃掉(math-display: 0)。 unified 时期没这问题,是因为 rehype-katex 排在 rehypePlugins 第一位, 先把 <pre><code> 换掉了。satteri-katex 的源码注释里记录的是同一个坑。 插件顺序 satteriKatex() 放在 mdastPlugins 最后:它把 math 节点换成 KaTeX 的 html 节点,若排在 reading-time / excerpt 之前,字数统计会把 KaTeX 标记也算进去。 顺带修掉一个之前漏掉的回归 reading-time / excerpt 原本用 ctx.textContent(),但它只拼接纯 text 节点, 会漏掉代码块、行内代码、公式、图片 alt。实测 LaTeX 那篇字数 830 → 488。 改用 mdast-util-to-string 的 toString()(与迁移前的实现一致),字数完全复原。 之前没发现是因为我的对比脚本只截取了 <article> 区域,而字数在它外面的 header 里。 现改为整页对比。 清理依赖(10 个,已确认无引用) remark-math / rehype-katex / remark-directive / remark-github-admonitions-to-directives / remark-sectionize / rehype-slug / rehype-components / rehype-autolink-headings / @astrojs/markdown-remark / hastscript / unist-util-visit 验证(与 unified() 基线整页对比,41 页) - 39 页语义完全一致;2 页只剩智能标点在中文/emoji 旁的引号方向差异 (Sätteri 的结果更正确:把开引号排成 “ 而不是 ”)。 - LaTeX 页:class="katex" 76、katex-display 10,与基线完全一致; 块级公式不再被 expressive-code 吞掉。 - 字数/阅读时长与基线逐篇一致(830/4、1042/5、416/2)。 - pnpm build 41 页 + pagefind 通过;astro check 仍是 1 error/0 warnings (原有 footer.astro 报错,与本次无关)。
105 lines
3.4 KiB
JSON
105 lines
3.4 KiB
JSON
{
|
|
"name": "tianxuetao-blog",
|
|
"version": "0.1.0",
|
|
"private": true,
|
|
"type": "module",
|
|
"scripts": {
|
|
"dev": "astro dev",
|
|
"start": "astro dev",
|
|
"build": "node scripts/fetch-reading.mjs --soft && astro build && pagefind --site dist",
|
|
"preview": "astro preview",
|
|
"check": "astro check",
|
|
"new-post": "node scripts/new-post.mjs",
|
|
"new-thought": "node scripts/new-thought.mjs",
|
|
"reading": "node scripts/fetch-reading.mjs"
|
|
},
|
|
"dependencies": {
|
|
"@astrojs/markdown-satteri": "^0.4.1",
|
|
"@astrojs/mdx": "^8.0.1",
|
|
"@astrojs/react": "^6.0.6",
|
|
"@astrojs/rss": "^4.0.19",
|
|
"@astrojs/sitemap": "^3.7.4",
|
|
"@aws-sdk/client-s3": "^3.1037.0",
|
|
"@expressive-code/core": "^0.44.2",
|
|
"@expressive-code/plugin-collapsible-sections": "^0.44.2",
|
|
"@expressive-code/plugin-line-numbers": "^0.44.2",
|
|
"@hookform/resolvers": "^3.10.0",
|
|
"@radix-ui/react-accordion": "1.2.2",
|
|
"@radix-ui/react-alert-dialog": "1.1.4",
|
|
"@radix-ui/react-aspect-ratio": "1.1.1",
|
|
"@radix-ui/react-avatar": "1.1.2",
|
|
"@radix-ui/react-checkbox": "1.1.3",
|
|
"@radix-ui/react-collapsible": "1.1.2",
|
|
"@radix-ui/react-context-menu": "2.2.4",
|
|
"@radix-ui/react-dialog": "1.1.4",
|
|
"@radix-ui/react-dropdown-menu": "2.1.4",
|
|
"@radix-ui/react-hover-card": "1.1.4",
|
|
"@radix-ui/react-label": "2.1.1",
|
|
"@radix-ui/react-menubar": "1.1.4",
|
|
"@radix-ui/react-navigation-menu": "1.2.3",
|
|
"@radix-ui/react-popover": "1.1.4",
|
|
"@radix-ui/react-progress": "1.1.1",
|
|
"@radix-ui/react-radio-group": "1.2.2",
|
|
"@radix-ui/react-scroll-area": "1.2.2",
|
|
"@radix-ui/react-select": "2.1.4",
|
|
"@radix-ui/react-separator": "1.1.1",
|
|
"@radix-ui/react-slider": "1.2.2",
|
|
"@radix-ui/react-slot": "1.1.1",
|
|
"@radix-ui/react-switch": "1.1.2",
|
|
"@radix-ui/react-tabs": "1.1.2",
|
|
"@radix-ui/react-toast": "1.2.4",
|
|
"@radix-ui/react-toggle": "1.1.1",
|
|
"@radix-ui/react-toggle-group": "1.1.1",
|
|
"@radix-ui/react-tooltip": "1.1.6",
|
|
"@swup/astro": "^1.8.0",
|
|
"@tabler/icons-react": "^3.40.0",
|
|
"astro-expressive-code": "^0.44.2",
|
|
"autoprefixer": "^10.4.20",
|
|
"bcryptjs": "^3.0.2",
|
|
"class-variance-authority": "^0.7.1",
|
|
"clsx": "^2.1.1",
|
|
"cmdk": "1.0.4",
|
|
"crypto-js": "^4.2.0",
|
|
"date-fns": "4.1.0",
|
|
"embla-carousel-react": "8.5.1",
|
|
"gray-matter": "^4.0.3",
|
|
"input-otp": "1.4.1",
|
|
"katex": "^0.16.22",
|
|
"lucide-react": "^0.454.0",
|
|
"markdown-it": "^14.1.0",
|
|
"mdast-util-to-string": "^4.0.0",
|
|
"pagefind": "^1.4.0",
|
|
"react": "19.2.0",
|
|
"react-day-picker": "9.8.0",
|
|
"react-dom": "19.2.0",
|
|
"react-hook-form": "^7.60.0",
|
|
"react-resizable-panels": "^2.1.7",
|
|
"reading-time": "^1.5.0",
|
|
"recharts": "2.15.4",
|
|
"sanitize-html": "^2.17.0",
|
|
"satteri": "^0.10.5",
|
|
"satteri-katex": "^0.1.1",
|
|
"sonner": "^1.7.4",
|
|
"tailwind-merge": "^2.5.5",
|
|
"tailwindcss-animate": "^1.0.7",
|
|
"vaul": "^1.1.2",
|
|
"zod": "3.25.76"
|
|
},
|
|
"devDependencies": {
|
|
"@astrojs/check": "^0.9.6",
|
|
"@tailwindcss/postcss": "^4.1.9",
|
|
"@tailwindcss/typography": "^0.5.19",
|
|
"@types/crypto-js": "^4.2.2",
|
|
"@types/markdown-it": "^14.1.2",
|
|
"@types/node": "^22",
|
|
"@types/react": "^19",
|
|
"@types/react-dom": "^19",
|
|
"@types/sanitize-html": "^2.16.0",
|
|
"astro": "^7.3.3",
|
|
"postcss": "^8.5",
|
|
"tailwindcss": "^4.1.9",
|
|
"tw-animate-css": "1.3.3",
|
|
"typescript": "^5"
|
|
}
|
|
}
|