From 1cc32953a0342152b33a63aed633bfb13bfdeb8b Mon Sep 17 00:00:00 2001 From: Todos Date: Mon, 9 Nov 2026 14:26:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(site):=20=E5=9F=9F=E5=90=8D=E6=94=B6?= =?UTF-8?q?=E6=95=9B=E5=8D=95=E4=B8=80=E7=9C=9F=E6=BA=90=EF=BC=8Ccanonical?= =?UTF-8?q?=20=E6=94=B9=E7=94=A8=20workerhub.github.io?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `astro.config.ts` 的 `site`、4 处 User-Agent、构建摘要标签、canonical/og/sitemap/robots 全部从 `src/lib/site.ts` 的 `SITE.url` 派生;新增守卫测试断言完整字面量只出现在真源一处。 部署线称谓对调:GitHub Pages = 主站,Cloudflare = 副线;推翻 SPEC §10 旧口径(副线继续 serving 同一份产物,不再 canonical),部署通道与绑定设置未改。 README/CONTRIBUTING、工作流注释与 `astro.config.ts` 的 tsconfig 覆盖同步。 --- .github/workflows/deploy.yml | 14 +++++----- CONTRIBUTING.md | 2 +- README.md | 4 +-- astro.config.mjs => astro.config.ts | 9 ++++--- scripts/fetch-og-images.ts | 3 ++- src/layouts/base-layout.astro | 2 +- src/lib/build-info.ts | 6 ++--- src/lib/build-summary.ts | 10 ++++--- src/lib/github-meta.ts | 4 ++- src/lib/link-health.ts | 4 ++- src/lib/site.ts | 11 ++++---- src/lib/submission-checks.ts | 3 ++- src/pages/sitemap.xml.ts | 2 +- tests/build-info.test.ts | 10 +++---- tests/build-summary.test.ts | 19 ++++++++++--- tests/site-single-source.test.ts | 42 +++++++++++++++++++++++++++++ tsconfig.json | 2 +- wrangler.jsonc | 2 +- 18 files changed, 108 insertions(+), 41 deletions(-) rename astro.config.mjs => astro.config.ts (72%) create mode 100644 tests/site-single-source.test.ts diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 995192d..03b6015 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,8 +2,8 @@ name: 双线部署 # 双线部署(SPEC §0 / §8.1 / §9.2 / §9.3): # 同一提交 → 同一份静态产物(dist/)→ 两条独立发布通道 -# ① GitHub Pages 镜像(来源 = GitHub Actions,自定义域名栏必须留空) -# ② Cloudflare Pages 主站 hub.oneboy.app(deploy hook 触发同版重建) +# ① GitHub Pages 主站(来源 = GitHub Actions,自定义域名栏必须留空) +# ② Cloudflare Pages 副线 hub.oneboy.app(deploy hook 触发同版重建) # 一侧失败不阻塞另一侧:两个发布 job 互相不依赖,各自独立报错(§0 / §9.2)。 # # 触发: @@ -191,7 +191,7 @@ jobs: if-no-files-found: warn publish-github-pages: - name: 发布 GitHub Pages 镜像 + name: 发布 GitHub Pages 主站 runs-on: ubuntu-latest needs: build # 与 CF 侧完全独立:只依赖 build,一侧失败不影响另一侧(§0 / §9.2) @@ -242,7 +242,7 @@ jobs: uses: actions/deploy-pages@v5 publish-cloudflare-pages: - name: 触发 Cloudflare Pages 主站重建 + name: 触发 Cloudflare Pages 副线重建 runs-on: ubuntu-latest needs: build # 与 Pages 侧完全独立:只依赖 build,一侧失败不影响另一侧(§0 / §9.2) @@ -251,7 +251,7 @@ jobs: DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }} SIMULATE_FAILURE: ${{ github.event.inputs.simulate_failure || 'none' }} steps: - - name: 演练|模拟触发主站重建(不调用 deploy hook) + - name: 演练|模拟触发副线重建(不调用 deploy hook) if: env.DRY_RUN == 'true' run: | set -euo pipefail @@ -263,7 +263,7 @@ jobs: fi echo "演练:Cloudflare Pages 侧触发成功(模拟)" - - name: 触发主站同版重建(deploy hook,URL 只从 GitHub Secrets 读取) + - name: 触发副线同版重建(deploy hook,URL 只从 GitHub Secrets 读取) if: env.DRY_RUN != 'true' env: CLOUDFLARE_PAGES_DEPLOY_HOOK: ${{ secrets.CLOUDFLARE_PAGES_DEPLOY_HOOK }} @@ -279,7 +279,7 @@ jobs: -X POST "$CLOUDFLARE_PAGES_DEPLOY_HOOK" || echo '000') echo "deploy hook 响应:HTTP $status" case "$status" in - 2??) echo "已触发 Cloudflare Pages 主站重建(同提交、同版本号)" ;; + 2??) echo "已触发 Cloudflare Pages 副线重建(同提交、同版本号)" ;; *) echo "::error::deploy hook 触发失败(HTTP $status)——本侧独立报错,不影响 GitHub Pages 侧" exit 1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8fbdaa5..70e652a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,7 @@ WorkerHub(hub)是 Cloudflare Workers 生态的中文精选应用目录:自 这份文件是投稿规则的**唯一真源**:站点的 `/submit/` 页面在构建时直接引入本文件渲染,页面与本文不得分叉——要改规则,改这里,不要改页面。数据校验 CI 的每一条规则也都与本文一一对应(见第 8 节)。 -- 站点主域名:`https://hub.oneboy.app` +- 站点主域名:`https://workerhub.github.io` - 仓库:`https://github.com/WorkerHub/workerhub.github.io` - 投稿方式:**向本仓库提 Pull Request**(没有站内表单、没有后台、没有账号系统) - 维护者联系方式:GitHub 组织页 diff --git a/README.md b/README.md index 41f677f..73ac863 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ Cloudflare Workers 生态的中文精选应用目录:自研项目 + 经收录 ## 在线访问 -- 主站: -- 镜像: +- 主站: +- 副线: ## 收录什么 diff --git a/astro.config.mjs b/astro.config.ts similarity index 72% rename from astro.config.mjs rename to astro.config.ts index 9c719a1..31dcb5f 100644 --- a/astro.config.mjs +++ b/astro.config.ts @@ -1,16 +1,17 @@ -// @ts-check import { defineConfig } from 'astro/config'; import react from '@astrojs/react'; import tailwindcss from '@tailwindcss/vite'; +import { SITE } from './src/lib/site.ts'; + /** * SPEC §8.1:Astro + TypeScript,纯静态输出(SSG)+ Tailwind CSS。 * 交互部分挂 React island(搜索/筛选/排序、主题切换),静态页面的卡片在构建期渲染为 HTML、零 JS。 - * canonical / sitemap 绝对地址恒写主域名(§10),镜像站不得按访问域名动态生成—— - * 由 `site` 固定为 https://hub.oneboy.app 保证,页面与 sitemap 都不读请求域名。 + * canonical / sitemap 绝对地址恒写主域名,副线站不得按访问域名动态生成—— + * 这里不写域名字面量:`site` 从 `src/lib/site.ts` 的唯一真源派生,页面与 sitemap 都不读请求域名。 */ export default defineConfig({ - site: 'https://hub.oneboy.app', + site: SITE.url, output: 'static', trailingSlash: 'always', build: { format: 'directory' }, diff --git a/scripts/fetch-og-images.ts b/scripts/fetch-og-images.ts index 93cc94f..91a39f3 100644 --- a/scripts/fetch-og-images.ts +++ b/scripts/fetch-og-images.ts @@ -22,6 +22,7 @@ import { } from '../src/lib/build-config.js'; import { readMetaCache } from '../src/lib/github-meta.js'; import { OG_IMAGE_PUBLIC_DIR, ogImageFileName } from '../src/lib/og-path.js'; +import { SITE } from '../src/lib/site.js'; const PUBLIC_DIR = resolve('public'); const OG_DIR = resolve(PUBLIC_DIR, OG_IMAGE_PUBLIC_DIR); @@ -67,7 +68,7 @@ async function download(repo: string): Promise { const source = cache.repos[repo]?.openGraphImage ?? `https://opengraph.githubassets.com/1/${repo}`; const headers: Record = { - 'user-agent': 'workerhub-hub-build (+https://hub.oneboy.app)', + 'user-agent': `workerhub-hub-build (+${SITE.url})`, }; if (GITHUB_TOKEN) headers.authorization = `Bearer ${GITHUB_TOKEN}`; diff --git a/src/layouts/base-layout.astro b/src/layouts/base-layout.astro index f5a5493..5d76e7c 100644 --- a/src/layouts/base-layout.astro +++ b/src/layouts/base-layout.astro @@ -2,7 +2,7 @@ /** * 全站基础布局:SEO/分享元数据、主题防闪烁、页头页脚、无障碍跳转。 * - * SPEC §10 硬性:canonical / og:url 恒写主域名 `https://hub.oneboy.app`,镜像侧也不按访问域名动态生成 + * canonical / og:url 恒写主域名(`src/lib/site.ts` 的真源 `SITE.url`),副线侧也不按访问域名动态生成 * —— 这里只从 `src/lib/site.ts` 的常量拼绝对地址,从不读 `Astro.url.host`。 */ import '../styles/global.css'; diff --git a/src/lib/build-info.ts b/src/lib/build-info.ts index 958ac0a..a348b1b 100644 --- a/src/lib/build-info.ts +++ b/src/lib/build-info.ts @@ -1,7 +1,7 @@ /** * 版本号与构建时间(SPEC §0 / §12 第 8 条:页脚版本号由构建时注入,仓库源码里不写死)。 * - * 主站(Cloudflare Pages)与镜像(GitHub Pages)**共用本文件这一段取值逻辑**, + * 主站(GitHub Pages)与副线(Cloudflare Pages)**共用本文件这一段取值逻辑**, * 不各写一套(§12 第 10 条「双线同版」的前提)。回退链优先级固定为: * ① `HUB_VERSION` 仅本地 / 特殊场景覆盖,生产**不**用它钉死版本 * ② `git describe --tags --always` @@ -10,12 +10,12 @@ * * ②→③ 这一跳是本文件存在的原因:CF Pages 的 Git 集成用浅克隆(shallow clone), * 构建环境里没有 tag 也没有完整历史,`git describe` 必然失败;而 CF Pages 自身 - * 提供 `CF_PAGES_COMMIT_SHA`(本次构建对应的完整提交 SHA),截 7 位后与镜像侧 + * 提供 `CF_PAGES_COMMIT_SHA`(本次构建对应的完整提交 SHA),截 7 位后与 GitHub Pages 侧 * `git describe --always` 的无 tag 输出形态一致(短 SHA),两侧页脚即可比对。 * * 刻意**不带 `--dirty`**(双线部署需要):构建本身会改写自动字段缓存 * `src/data/cache/github-meta.json`,带 `--dirty` 会让每次 CI 构建都得到 - * `-dirty`,主站与镜像两侧、两次构建之间都无法比较,页脚也难看。 + * `-dirty`,主站与副线两侧、两次构建之间都无法比较,页脚也难看。 * 版本号只标识「哪一次提交的源码」,构建产物差异由构建时间承担。 */ import { execFileSync } from 'node:child_process'; diff --git a/src/lib/build-summary.ts b/src/lib/build-summary.ts index e8d54eb..6f39db6 100644 --- a/src/lib/build-summary.ts +++ b/src/lib/build-summary.ts @@ -9,6 +9,7 @@ import { z } from 'zod'; import { linkHealthReportSchema, type LinkHealthReport } from './link-health.js'; +import { SITE } from './site.js'; // --------------------------------------------------------------------------- // 输入:抓取报告(由 scripts/fetch-github-meta.ts 产出) @@ -110,9 +111,12 @@ const table = (header: string[], rows: string[][]): string => .concat(rows.map((row) => `| ${row.map(cell).join(' | ')} |`)) .join('\n'); +/** canonical 主机名取自真源,摘要里不写第二份域名字面量 */ +const CANONICAL_HOST = new URL(SITE.url).host; + const PUBLISH_LABELS: Record = { - 'github-pages': 'GitHub Pages 镜像(workerhub.github.io)', - 'cloudflare-pages': 'Cloudflare Pages 主站(hub.oneboy.app)', + 'github-pages': `GitHub Pages 主站(${CANONICAL_HOST})`, + 'cloudflare-pages': 'Cloudflare Pages 副线', }; const RESULT_LABELS: Record = { @@ -314,7 +318,7 @@ export function renderBuildSummary(input: BuildSummaryInput): string { return [ '## 双线重建摘要(hub)', '', - '同一提交 → 同一份 `dist/` 产物 → 双线发布:GitHub Pages 镜像 + Cloudflare Pages 主站(SPEC §0 / §8.1 / §9.2)。', + '同一提交 → 同一份 `dist/` 产物 → 双线发布:GitHub Pages 主站 + Cloudflare Pages 副线(SPEC §0 / §8.1 / §9.2)。', '', '### 本次运行', '', diff --git a/src/lib/github-meta.ts b/src/lib/github-meta.ts index ad3b3d0..3f32fba 100644 --- a/src/lib/github-meta.ts +++ b/src/lib/github-meta.ts @@ -12,6 +12,8 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { dirname } from 'node:path'; import { z } from 'zod'; +import { SITE } from './site.js'; + export const META_CACHE_SCHEMA_VERSION = 1; export const DEFAULT_API_BASE = 'https://api.github.com'; export const DEFAULT_TIMEOUT_MS = 8_000; @@ -164,7 +166,7 @@ async function getJson(url: string, repo: string, options: FetchOptions): Promis const headers: Record = { accept: 'application/vnd.github+json', 'x-github-api-version': '2022-11-28', - 'user-agent': 'workerhub-hub-build (+https://hub.oneboy.app)', + 'user-agent': `workerhub-hub-build (+${SITE.url})`, }; if (options.token) headers.authorization = `Bearer ${options.token}`; diff --git a/src/lib/link-health.ts b/src/lib/link-health.ts index e79e554..646a3f4 100644 --- a/src/lib/link-health.ts +++ b/src/lib/link-health.ts @@ -14,6 +14,8 @@ import { existsSync, readFileSync } from 'node:fs'; import { z } from 'zod'; +import { SITE } from './site.js'; + /** 巡检的外链字段(§9.3「全部外链」:仓库入口 + 数据文件里的全部人工外链) */ export const LINK_FIELDS = ['repo', 'docs_url', 'deploy.url', 'deploy.guide_url'] as const; export type LinkField = (typeof LINK_FIELDS)[number]; @@ -25,7 +27,7 @@ export const DEFAULT_TIMEOUT_MS = 10_000; export const DEFAULT_RETRIES = 1; export const DEFAULT_CONCURRENCY = 6; -const USER_AGENT = 'workerhub-hub-link-health (+https://hub.oneboy.app)'; +const USER_AGENT = `workerhub-hub-link-health (+${SITE.url})`; /** 巡检输入所需的最小项目形状(`ProjectInput` 满足它) */ export interface LinkSourceProject { diff --git a/src/lib/site.ts b/src/lib/site.ts index 5f0c666..2623584 100644 --- a/src/lib/site.ts +++ b/src/lib/site.ts @@ -1,12 +1,13 @@ /** - * 站点级常量与绝对地址(SPEC §10:canonical / OG / sitemap 一律写主域名,镜像侧不按访问域名动态生成)。 + * 站点级常量与绝对地址(canonical / OG / sitemap 一律写主域名,副线侧不按访问域名动态生成)。 * - * 唯一的域名来源就是这个常量 + `astro.config.mjs` 的 `site`, - * 页面、sitemap、robots 都引用这里,任何页面都不得读 `Astro.url.host`。 + * 域名只有一个真源:就是下面 `SITE.url` 这一份字面量。`astro.config.ts` 的 `site` + * 从这里读取,页面、端点、库、脚本一律由它派生,任何页面都不得读 `Astro.url.host`, + * 也不得再写第二份域名字面量(副线继续 serving 同一份产物,但不参与地址生成)。 */ export const SITE = { name: 'WorkerHub', - url: 'https://hub.oneboy.app', + url: 'https://workerhub.github.io', title: 'WorkerHub · Cloudflare Workers 中文精选应用目录', description: '汇集可自部署的 Cloudflare Workers 应用:自研项目与经收录把关的第三方开源项目,标清部署方式、所需资源、难度与验证等级,直达仓库与部署入口。', @@ -16,7 +17,7 @@ export const SITE = { locale: 'zh_CN', } as const; -/** 站内路径 → 主域名绝对地址(canonical / OG / sitemap 共用) */ +/** 站内路径 → 主域名绝对地址(canonical / og:url / og:image / sitemap / robots 共用) */ export function absoluteUrl(pathname: string): string { return new URL(pathname, SITE.url).href; } diff --git a/src/lib/submission-checks.ts b/src/lib/submission-checks.ts index 76a4551..e68bf24 100644 --- a/src/lib/submission-checks.ts +++ b/src/lib/submission-checks.ts @@ -21,6 +21,7 @@ import { existsSync, readFileSync, statSync } from 'node:fs'; import { basename, join } from 'node:path'; import { imageSize } from 'image-size'; import type { ProjectInput } from './project-schema.js'; +import { SITE } from './site.js'; /** §7 截图规格:webp、宽 ≥1200px、体积 ≤300KB */ export const SCREENSHOT_MIN_WIDTH = 1200; @@ -32,7 +33,7 @@ export const DEFAULT_LINK_CONCURRENCY = 6; /** CDN bot 防护拒绝 CI 探针时返回的状态码:不判「不可达」,降级为 warning */ export const BOT_PROTECTION_STATUS = 403; export const DEFAULT_API_BASE = 'https://api.github.com'; -const USER_AGENT = 'workerhub-hub-ci (+https://hub.oneboy.app)'; +const USER_AGENT = `workerhub-hub-ci (+${SITE.url})`; export type CheckName = 'repos' | 'links' | 'screenshots'; export type Severity = 'error' | 'warning'; diff --git a/src/pages/sitemap.xml.ts b/src/pages/sitemap.xml.ts index 40b656f..cec0489 100644 --- a/src/pages/sitemap.xml.ts +++ b/src/pages/sitemap.xml.ts @@ -1,6 +1,6 @@ /** * sitemap.xml(SPEC §10):构建时生成,含首页 + 列表/提交/关于 + 全部项目详情页 + 全部分类页; - * 绝对地址一律写主域名 `https://hub.oneboy.app`(镜像站不按访问域名生成)。 + * 绝对地址一律取真源 `SITE.url`(副线站也不按访问域名生成)。 */ import type { APIRoute } from 'astro'; diff --git a/tests/build-info.test.ts b/tests/build-info.test.ts index ec23eef..008cf5d 100644 --- a/tests/build-info.test.ts +++ b/tests/build-info.test.ts @@ -1,8 +1,8 @@ /** * 页脚版本号回退链的单测(SPEC §0 / §12 第 8、10 条): * ① HUB_VERSION → ② git describe → ③ CF_PAGES_COMMIT_SHA 截 7 位 → ④ v0.0.0-dev。 - * 主站(CF Pages 浅克隆,`git describe` 必失败)与镜像(完整历史)共用这段逻辑, - * 所以「③ 生效且形态与镜像的短 SHA 一致」是双线同版的关键一条。 + * 主站(GitHub Pages,`git describe` 成功)与副线(Cloudflare Pages 浅克隆,`git describe` 必失败) + * 共用这段逻辑,所以「③ 生效且形态与主站侧的短 SHA 一致」是双线同版的关键一条。 */ import assert from 'node:assert/strict'; import { test } from 'node:test'; @@ -21,19 +21,19 @@ test('① HUB_VERSION 覆盖优先于 git describe(本地覆盖不退化)', assert.equal(resolveVersion({ HUB_VERSION: ' v1.2.3 ' }, describeFails), 'v1.2.3'); }); -test('② git describe 成功时直接采用(镜像侧路径)', () => { +test('② git describe 成功时直接采用(主站侧路径)', () => { assert.equal(resolveVersion({}, describeOk('10f8fa9')), '10f8fa9'); assert.equal(resolveVersion({}, describeOk('v1.0.0-3-gabcdef1')), 'v1.0.0-3-gabcdef1'); }); -test('③ git describe 失败时取 CF_PAGES_COMMIT_SHA 并截短为 7 位(主站侧路径)', () => { +test('③ git describe 失败时取 CF_PAGES_COMMIT_SHA 并截短为 7 位(副线侧路径)', () => { const version = resolveVersion({ CF_PAGES_COMMIT_SHA: FULL_SHA }, describeFails); assert.equal(version, '10f8fa9'); assert.equal(version.length, 7); assert.notEqual(version, 'v0.0.0-dev'); }); -test('③ 短 SHA 形态与镜像侧 git describe 输出一致(双线可比对)', () => { +test('③ 短 SHA 形态与主站侧 git describe 输出一致(双线可比对)', () => { assert.equal( resolveVersion({ CF_PAGES_COMMIT_SHA: FULL_SHA }, describeFails), resolveVersion({}, describeOk('10f8fa9')), diff --git a/tests/build-summary.test.ts b/tests/build-summary.test.ts index 98ce913..d77c1c3 100644 --- a/tests/build-summary.test.ts +++ b/tests/build-summary.test.ts @@ -14,6 +14,12 @@ import { type MetaReport, } from '../src/lib/build-summary.js'; import type { LinkHealthReport } from '../src/lib/link-health.js'; +import { SITE } from '../src/lib/site.js'; + +/** 期望的部署线标签从真源拼出(不在测试里写第二份域名) */ +const CANONICAL_HOST = new URL(SITE.url).host; +const GITHUB_PAGES_LABEL = `GitHub Pages 主站(${CANONICAL_HOST})`; +const CLOUDFLARE_PAGES_LABEL = 'Cloudflare Pages 副线'; const context: BuildSummaryContext = { event: 'schedule', @@ -92,7 +98,7 @@ test('摘要含自动字段刷新结果与异常项目清单(§12 第 7 条) links, linksExpected: true, publishing: [ - { side: 'github-pages', result: 'success', detail: '已发布镜像' }, + { side: 'github-pages', result: 'success', detail: '已发布主站' }, { side: 'cloudflare-pages', result: 'success', detail: 'deploy hook 已触发(HTTP 200)' }, ], }); @@ -120,8 +126,15 @@ test('一侧失败时摘要逐侧标注并声明独立报错', () => { ], }); - assert.match(summary, /GitHub Pages 镜像(workerhub\.github\.io) \| ❌ 失败/); - assert.match(summary, /Cloudflare Pages 主站(hub\.oneboy\.app) \| ✅ 成功/); + assert.ok( + summary.includes(`${GITHUB_PAGES_LABEL} | ❌ 失败`), + '摘要应把 GitHub Pages 标为主站(canonical)', + ); + assert.ok( + summary.includes(`${CLOUDFLARE_PAGES_LABEL} | ✅ 成功`), + '摘要应把 Cloudflare 标为副线', + ); + assert.match(summary, /双线发布:GitHub Pages 主站 \+ Cloudflare Pages 副线/); assert.match(summary, /独立报错/); assert.match(summary, /未调用 GitHub Pages 发布动作、未调用 Cloudflare deploy hook/); }); diff --git a/tests/site-single-source.test.ts b/tests/site-single-source.test.ts new file mode 100644 index 0000000..9dea89e --- /dev/null +++ b/tests/site-single-source.test.ts @@ -0,0 +1,42 @@ +/** + * 域名单一真源守卫(canonical 收敛定版):完整 canonical 字面量只许出现在 `src/lib/site.ts` 一处, + * 页面、端点、库、脚本、构建配置一律从真源派生。 + * + * 扫描串取自真源本身(`SITE.url`),本文件不写第二份字面量——否则守卫自己就会破坏它守的东西。 + */ +import assert from 'node:assert/strict'; +import { readdirSync, readFileSync } from 'node:fs'; +import { join, relative, sep } from 'node:path'; +import { test } from 'node:test'; + +import { SITE } from '../src/lib/site.js'; + +const ROOT = process.cwd(); +/** 与验收 grep 的范围一致:src/、scripts/、tests/ + 根目录 astro.config.* */ +const SCAN_DIRS = ['src', 'scripts', 'tests']; +const TEXT_FILE = /\.(ts|tsx|astro|mjs|cjs|js|json|ya?ml)$/i; + +const walk = (dir: string): string[] => + readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { + const path = join(dir, entry.name); + if (entry.isDirectory()) return walk(path); + return TEXT_FILE.test(entry.name) ? [path] : []; + }); + +test('完整 canonical 字面量只出现在真源文件', () => { + const configs = readdirSync(ROOT) + .filter((name) => name.startsWith('astro.config.')) + .map((name) => join(ROOT, name)); + const files = [...SCAN_DIRS.flatMap((dir) => walk(join(ROOT, dir))), ...configs]; + + const hits = files + .filter((file) => readFileSync(file, 'utf8').includes(SITE.url)) + .map((file) => relative(ROOT, file).split(sep).join('/')) + .sort(); + + assert.deepEqual( + hits, + ['src/lib/site.ts'], + `完整域名字面量必须只出现在真源 src/lib/site.ts,实际命中:${hits.join('、')}`, + ); +}); diff --git a/tsconfig.json b/tsconfig.json index c58c180..5b9ce0b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "astro/tsconfigs/strict", - "include": [".astro/types.d.ts", "src/**/*", "scripts/**/*", "tests/**/*"], + "include": [".astro/types.d.ts", "astro.config.ts", "src/**/*", "scripts/**/*", "tests/**/*"], "exclude": ["dist"], "compilerOptions": { "strictNullChecks": true, diff --git a/wrangler.jsonc b/wrangler.jsonc index bc0851c..5c04663 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -1,4 +1,4 @@ -// Cloudflare Workers 静态资源部署配置(主站 hub.oneboy.app 走 Workers + assets)。 +// Cloudflare Workers 静态资源部署配置(副线 hub.oneboy.app 走 Workers + assets)。 // 纯静态站点:构建产物 dist/ 直接作为 Static Assets 上传,无 bindings / Durable Objects / 数据库。 // 冻结契约:Worker 名固定 hub;产物目录固定 ./dist(与 package.json 的 build 脚本输出一致)。 { From ae7817db727728b37e82cb60b018009586a2e9d3 Mon Sep 17 00:00:00 2001 From: Todos Date: Mon, 9 Nov 2026 15:01:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(robots):=20=E6=B3=A8=E9=87=8A=E9=87=8C?= =?UTF-8?q?=E3=80=8C=E9=95=9C=E5=83=8F=E7=AB=99=E3=80=8D=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E3=80=8C=E5=89=AF=E7=BA=BF=E7=AB=99=E3=80=8D=EF=BC=8C=E4=B8=8E?= =?UTF-8?q?=E6=96=B0=E4=B8=BB=E5=89=AF=E7=BA=BF=E5=8F=A3=E5=BE=84=E4=B8=80?= =?UTF-8?q?=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/robots.txt.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/robots.txt.ts b/src/pages/robots.txt.ts index 0cfcc3d..6186ef2 100644 --- a/src/pages/robots.txt.ts +++ b/src/pages/robots.txt.ts @@ -1,6 +1,6 @@ /** * robots.txt(SPEC §10):放行抓取并指向主域名的 sitemap。 - * 镜像站同样输出这一份(canonical 恒写主域名,不按访问域名生成)。 + * 副线站同样输出这一份(canonical 恒写真源 SITE.url,不按访问域名生成)。 */ import type { APIRoute } from 'astro';