优化SEO

This commit is contained in:
biss committed 2026-07-19 12:06:35 +08:00
1 parent b502d21818
commit 1ba06d3ff3
24 files changed
+224 -34

No files matched your search

+6 -4
View File
@@ -12,7 +12,8 @@
- 留言墙:接入 Twikoo 后可在页面中留言。
- 全站搜索:通过 Typesense 搜索并筛选时间线、照片、文章和同学公开资料。
- PWA:支持添加到主屏幕,并离线访问站点外壳及已浏览的同源内容。
- 字体加密:生产构建会随机混淆页面中的汉字,并生成按需裁剪的 WOFF2 字体,降低静态内容被直接复制或抓取的风险。
- SEO:默认生产构建保留可读正文,并生成 canonical、结构化数据、`robots.txt` 与站点地图,便于搜索引擎抓取。
- 可选字体保护:需要降低静态内容被直接复制的风险时,可单独执行受保护构建。
## 技术栈
@@ -34,14 +35,15 @@ npm run dev
```bash
npm run dev # 启动开发服务器
npm run build # 构建静态站点到 dist
npm run build # 构建适合搜索引擎抓取的静态站点到 dist
npm run build:protected # 可选:构建带汉字字体混淆的版本
npm run preview # 预览构建结果
npm run search:sync # 将公开内容同步到 Typesense
```
`npm run build` 会在 Astro 构建完成后加密页面字体,再生成带内容版本号的 Service Worker,并预缓存页面、样式、脚本、加密字体、应用图标和首页主视觉。照片等大体积资源采用访问后缓存,第三方接口始终走网络。
`npm run build` 会在 Astro 构建完成后生成带内容版本号的 Service Worker,并预缓存页面、样式、脚本、应用图标和首页主视觉。照片等大体积资源采用访问后缓存,第三方接口始终走网络。
字体加密只作用于 `dist` 中的生产页面,不修改源码,也不会影响本地开发。每次构建默认生成新的随机映射;如需可复现产物,可设置 `FONT_ENCRYPTION_SEED`。`code`、`pre`、表单属性以及脚本动态生成的内容会保留原文,以免影响复制和交互。字体加密只能提高批量采集成本,不能替代访问控制或版权保护。
`npm run build:protected` 会额外混淆 `dist` 页面中的汉字并生成按需裁剪的 WOFF2 字体。该模式会降低搜索引擎理解正文的能力,不适合需要 SEO 的正式部署。字体混淆不修改源码,也不能替代访问控制或版权保护。
## Typesense 全站搜索
+1 -1
View File
@@ -2,7 +2,7 @@ import { defineConfig } from "astro/config";
import { fileURLToPath } from "node:url";
export default defineConfig({
site: "https://example.com",
site: "https://www.2024612.xyz/",
vite: {
resolve: {
alias: {
+2 -1
View File
@@ -5,7 +5,8 @@
"type": "module",
"scripts": {
"dev": "astro dev",
"build": "astro build && node scripts/encrypt-font.mjs && node scripts/build-pwa.mjs",
"build": "astro build && node scripts/build-pwa.mjs",
"build:protected": "astro build && node scripts/encrypt-font.mjs && node scripts/build-pwa.mjs",
"preview": "astro preview",
"search:key": "node --env-file-if-exists=.env --env-file-if-exists=.env.local scripts/create-typesense-search-key.mjs",
"search:sync": "node --env-file-if-exists=.env --env-file-if-exists=.env.local --import tsx scripts/sync-typesense.ts"
Loaded 3 of 24 files, more files were not shown because too many files have changed in this diff. Show more