From 339e5b5639a33940d10bb117e403985fda0b6a6c Mon Sep 17 00:00:00 2001 From: hanyixuanten Date: Mon, 26 Oct 2026 14:43:18 +0800 Subject: [PATCH] feat: sync security & SEO hardening from 2910 (keep placeholders) --- AGENTS.md | 2 +- README.md | 6 +- functions/api/messages.js | 21 +---- functions/api/submit.ts | 46 ++++++++--- public/favicon.svg | 4 + public/js/index.js | 40 ++++++++-- public/robots.txt | 3 + src/layouts/PostLayout.astro | 5 ++ src/pages/404.astro | 77 +++++++++++++++++++ src/pages/chronicle.astro | 7 ++ src/pages/contribute.astro | 4 +- src/pages/index.astro | 127 ++++++++----------------------- src/pages/music-contribute.astro | 2 + src/pages/music.astro | 7 ++ src/site.config.ts | 48 ++++++++++++ 15 files changed, 262 insertions(+), 137 deletions(-) create mode 100644 public/favicon.svg create mode 100644 public/robots.txt create mode 100644 src/pages/404.astro diff --git a/AGENTS.md b/AGENTS.md index 19ff859..967c6fa 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -10,7 +10,7 @@ ## 结构速览 -- `src/site.config.ts`:班级信息占位值,各页面引用 +- `src/site.config.ts`:班级信息占位值(`SITE`)与首页各区块文案占位值(`HOME`:简介、人物志、荣誉、记忆墙、打字机句子),各页面引用 - 示例内容(使用者应删除):`src/content/20250101.md`、`src/songs/20250101-example.json`;`public/pages/static/cover-placeholder.svg` 为占位封面 - `functions/api/submit.ts`:投稿 → GitHub App(cms-bot,见 Wiki)建分支开 PR;`functions/api/messages.js`:留言墙(D1,绑定名 `DB`) - 构建:Node ≥ 22.12,`npm run build`;本地 `npm run dev` 没有 `/api/*` diff --git a/README.md b/README.md index 58e361e..9f0db2d 100644 --- a/README.md +++ b/README.md @@ -44,10 +44,8 @@ npm run dev # http://localhost:4321 ## 定制班级信息 -1. **`src/site.config.ts`**:班级名、顶栏 logo、首屏徽章、统计数字,改这一个文件即可。 -2. **`src/pages/index.astro`**:班级简介、人物志、荣誉、记忆墙的示例文案(搜索 `20XX` 和各区块的中文示例)。 -3. **`public/js/index.js`**:首屏打字机轮播文案(`lines` 数组)。 -4. 主题色(金色 `#e6c068`)在 `public/css/*.css` 中定义。 +1. **`src/site.config.ts`**:班级名、顶栏 logo、首屏徽章、统计数字,以及首页各区块文案(`HOME`:班级简介、人物志、荣誉、记忆墙、打字机句子、SEO 描述),改这一个文件即可。 +2. 主题色(金色 `#e6c068`)在 `public/css/*.css` 中定义。 ## 内容格式 diff --git a/functions/api/messages.js b/functions/api/messages.js index 7b2fe00..929929b 100644 --- a/functions/api/messages.js +++ b/functions/api/messages.js @@ -17,11 +17,7 @@ function json(data, status = 200) { status, headers: { 'Content-Type': 'application/json; charset=utf-8', - 'Cache-Control': 'no-store', - // 如果前端和接口不同域,可加上 CORS 头;同域可删掉 - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type' + 'Cache-Control': 'no-store' } }); } @@ -53,6 +49,8 @@ const SCHEMA_SQL = [ country TEXT, created_at INTEGER NOT NULL )`, + 'CREATE INDEX IF NOT EXISTS idx_messages_ip ON messages(ip)', + 'CREATE INDEX IF NOT EXISTS idx_messages_created ON messages(created_at)', 'ALTER TABLE messages ADD COLUMN ua TEXT', 'ALTER TABLE messages ADD COLUMN country TEXT', ]; @@ -78,19 +76,6 @@ function ensureSchema(env) { return schemaPromise; } -/* ---------- OPTIONS(预检) ---------- */ -export async function onRequestOptions() { - return new Response(null, { - status: 204, - headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type', - 'Access-Control-Max-Age': '86400' - } - }); -} - /* ---------- GET:拉取列表 ---------- */ export async function onRequestGet({ env }) { if (!env.DB) return json({ ok: false, error: '数据库未绑定' }, 500); diff --git a/functions/api/submit.ts b/functions/api/submit.ts index a823562..e6cdd19 100644 --- a/functions/api/submit.ts +++ b/functions/api/submit.ts @@ -131,7 +131,7 @@ function extFromMime(mime: string): string { if (m.includes('webp')) return 'webp'; if (m.includes('gif')) return 'gif'; if (m.includes('avif')) return 'avif'; - if (m.includes('svg')) return 'svg'; + // SVG 刻意不支持:内含的 + + diff --git a/src/pages/chronicle.astro b/src/pages/chronicle.astro index 735d417..7aedabb 100644 --- a/src/pages/chronicle.astro +++ b/src/pages/chronicle.astro @@ -32,6 +32,13 @@ const items = posts 班史列表 · {SITE.className} + + + +