Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)。
#
# 触发:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 }}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 组织页 <https://github.com/WorkerHub>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Cloudflare Workers 生态的中文精选应用目录:自研项目 + 经收录

## 在线访问

- 主站:<https://hub.oneboy.app>
- 镜像:<https://workerhub.github.io>
- 主站:<https://workerhub.github.io>
- 副线:<https://hub.oneboy.app>

## 收录什么

Expand Down
9 changes: 5 additions & 4 deletions astro.config.mjs → astro.config.ts
Original file line number Diff line number Diff line change
@@ -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' },
Expand Down
3 changes: 2 additions & 1 deletion scripts/fetch-og-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -67,7 +68,7 @@ async function download(repo: string): Promise<OgOutcome> {
const source =
cache.repos[repo]?.openGraphImage ?? `https://opengraph.githubassets.com/1/${repo}`;
const headers: Record<string, string> = {
'user-agent': 'workerhub-hub-build (+https://hub.oneboy.app)',
'user-agent': `workerhub-hub-build (+${SITE.url})`,
};
if (GITHUB_TOKEN) headers.authorization = `Bearer ${GITHUB_TOKEN}`;

Expand Down
2 changes: 1 addition & 1 deletion src/layouts/base-layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 3 additions & 3 deletions src/lib/build-info.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* 版本号与构建时间(SPEC §0 / §12 第 8 条:页脚版本号由构建时注入,仓库源码里不写死)。
*
* 主站(Cloudflare Pages)与镜像(GitHub Pages)**共用本文件这一段取值逻辑**,
* 主站(GitHub Pages)与副线(Cloudflare Pages)**共用本文件这一段取值逻辑**,
* 不各写一套(§12 第 10 条「双线同版」的前提)。回退链优先级固定为:
* ① `HUB_VERSION` 仅本地 / 特殊场景覆盖,生产**不**用它钉死版本
* ② `git describe --tags --always`
Expand All @@ -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 构建都得到
* `<sha>-dirty`,主站与镜像两侧、两次构建之间都无法比较,页脚也难看。
* `<sha>-dirty`,主站与副线两侧、两次构建之间都无法比较,页脚也难看。
* 版本号只标识「哪一次提交的源码」,构建产物差异由构建时间承担。
*/
import { execFileSync } from 'node:child_process';
Expand Down
10 changes: 7 additions & 3 deletions src/lib/build-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 产出)
Expand Down Expand Up @@ -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<PublishSide, string> = {
'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<string, string> = {
Expand Down Expand Up @@ -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)。',
'',
'### 本次运行',
'',
Expand Down
4 changes: 3 additions & 1 deletion src/lib/github-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -164,7 +166,7 @@ async function getJson(url: string, repo: string, options: FetchOptions): Promis
const headers: Record<string, string> = {
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}`;

Expand Down
4 changes: 3 additions & 1 deletion src/lib/link-health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions src/lib/site.ts
Original file line number Diff line number Diff line change
@@ -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 应用:自研项目与经收录把关的第三方开源项目,标清部署方式、所需资源、难度与验证等级,直达仓库与部署入口。',
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/submission-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/robots.txt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* robots.txt(SPEC §10):放行抓取并指向主域名的 sitemap。
* 镜像站同样输出这一份(canonical 恒写主域名,不按访问域名生成)。
* 副线站同样输出这一份(canonical 恒写真源 SITE.url,不按访问域名生成)。
*/
import type { APIRoute } from 'astro';

Expand Down
2 changes: 1 addition & 1 deletion src/pages/sitemap.xml.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* sitemap.xml(SPEC §10):构建时生成,含首页 + 列表/提交/关于 + 全部项目详情页 + 全部分类页;
* 绝对地址一律写主域名 `https://hub.oneboy.app`(镜像站不按访问域名生成)。
* 绝对地址一律取真源 `SITE.url`(副线站也不按访问域名生成)。
*/
import type { APIRoute } from 'astro';

Expand Down
10 changes: 5 additions & 5 deletions tests/build-info.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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')),
Expand Down
19 changes: 16 additions & 3 deletions tests/build-summary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)' },
],
});
Expand Down Expand Up @@ -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/);
});
Expand Down
42 changes: 42 additions & 0 deletions tests/site-single-source.test.ts
Original file line number Diff line number Diff line change
@@ -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('、')}`,
);
});
Loading
Loading