Skip to content

Commit adbe995

Browse files
Run community shares on V2 Pages edge
1 parent 497a143 commit adbe995

6 files changed

Lines changed: 42 additions & 52 deletions

File tree

.github/workflows/generate-share-pages.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ on:
66
paths-ignore:
77
- "s/**"
88
- "og/**"
9-
schedule:
10-
# Dynamic edge rendering is immediate. This job only refreshes the static
11-
# fallback and intentionally shares the Community recovery cadence instead
12-
# of waking TableStore every five minutes.
13-
- cron: "17 */6 * * *"
149
workflow_dispatch:
1510

1611
permissions:

README.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# PythonIDE Link Site
22

3-
This directory is the static GitHub Pages origin for:
3+
This directory is the static asset source for the `pythonide-link` Cloudflare
4+
Pages project:
45

56
- `https://link.pythonide.xin/s/{scriptID}` community work shares
67
- `https://link.pythonide.xin/community/{postID}` Community V2 post and comment shares
@@ -16,37 +17,46 @@ This directory is the static GitHub Pages origin for:
1617
## Repository and deployment
1718

1819
The canonical repository is
19-
[`Python-IDE/pythonide-link`](https://github.com/Python-IDE/pythonide-link). GitHub
20-
Pages deploys from the default branch root with the custom domain
21-
`link.pythonide.xin` and enforced HTTPS.
20+
[`Python-IDE/pythonide-link`](https://github.com/Python-IDE/pythonide-link).
21+
Cloudflare Pages serves the custom domain `link.pythonide.xin` with enforced
22+
HTTPS. The repository is the reviewed source and rollback history; publishing a
23+
commit alone does not deploy the direct-upload Pages project.
2224

2325
The companion `../link-edge/` renderer server-renders per-script Open Graph
2426
metadata and creates a 1200×630 PNG card from the restricted public Community
25-
V2 work-share projection. The GitHub Actions workflow in `.github/workflows/`
26-
runs this renderer on every source publish and every six hours, committing
27-
generated `/s/*/` pages and `/og/*` cards to GitHub Pages. Dynamic edge
28-
rendering remains immediate; the generated files are only a fallback for
29-
crawlers such as WeChat that do not reliably execute page JavaScript. The six-
30-
hour cadence avoids waking the Community database every five minutes.
27+
V2 work-share projection. `_worker.js` enables Cloudflare Pages advanced mode
28+
and re-exports that canonical renderer from the published `edge/` directory.
29+
Dynamic rendering is immediate. The GitHub Actions workflow can generate
30+
reviewable `/s/*/` pages and `/og/*` cards on a source change or a manual run,
31+
but it has no recurring schedule and therefore does not wake the Community
32+
database while nobody is using the site.
3133

32-
To publish changes, copy the contents of this `link-site/` directory to that
33-
repository root and verify the Pages deployment. The DNS record is:
34+
Publish and deploy in this order:
35+
36+
```bash
37+
bash scripts/push_link_site.sh "Describe the link-site change"
38+
bash scripts/deploy_link_pages.sh
39+
```
40+
41+
The first command updates the public source repository. The second tests and
42+
deploys that exact repository commit to the `pythonide-link` Cloudflare Pages
43+
project. The DNS record is:
3444

3545
```text
3646
Type: CNAME
3747
Host: link
38-
Value: Python-IDE.github.io
39-
TTL: 10 minutes
48+
Value: pythonide-link.pages.dev
4049
```
4150

4251
Do not change the root `@` or `www` records used by the main website. Do not
4352
recreate a repository named `pythonide-link` under the previous owner because
4453
that would break GitHub's repository-transfer redirects.
4554

4655
The publish script copies `../link-edge/` into the link repository as `edge/`
47-
so the workflow and renderer always use the same tested implementation. Both
48-
the browser fallback and edge renderer use `community-api.pythonide.xin` V2;
49-
they must never restore a direct `fcapp.run` or `/v1/scripts` dependency.
56+
so Pages advanced mode and the generator always use the same tested
57+
implementation. Both the browser fallback and edge renderer use
58+
`community-api.pythonide.xin` V2; they must never restore a direct `fcapp.run`
59+
or `/v1/scripts` dependency.
5060

5161
Before either deployment, run:
5262

_worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './edge/worker.js';

edge/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Python IDE link edge renderer
22

33
This worker adds server-rendered Open Graph metadata and dynamic PNG preview
4-
cards to the existing `link.pythonide.xin` GitHub Pages site. It only reads the
4+
cards to the `link.pythonide.xin` Cloudflare Pages site. It only reads the
55
restricted Community V2 public projections and intercepts the AASA endpoint, `/s/*`,
66
`/community/*`, and `/og/*`.
77

8-
The same module also supports Cloudflare Pages advanced mode. When the Pages
8+
Cloudflare Pages advanced mode is the production owner. `link-site/_worker.js`
9+
re-exports this module from the published `edge/` directory. When the Pages
910
`ASSETS` binding is present, it reads the share template from the local Pages
1011
deployment and forwards all non-edge routes (including the public OAuth
1112
metadata and callback pages) to the static asset service. This permits the
@@ -29,5 +30,6 @@ before returning the page. That projection never contains a project package
2930
URL, OSS key, or complete ZIP. Social crawlers such as WeChat therefore receive
3031
the work title and description without executing JavaScript.
3132

32-
Run `npm test` before deploying. Deploy with Wrangler after authenticating the
33-
Cloudflare account that owns `pythonide.xin`.
33+
Run `npm test` before deploying. Use `scripts/deploy_link_pages.sh` after
34+
authenticating the Cloudflare account that owns the `pythonide-link` Pages
35+
project. Do not deploy this module as a separate routed Worker.

edge/wrangler.jsonc

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/share-page.test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ const fs = require('node:fs');
66
const path = require('node:path');
77
const core = require('../assets/share-page.js');
88

9+
test('Cloudflare Pages advanced mode reuses the canonical edge renderer', () => {
10+
const siteRoot = path.resolve(__dirname, '..');
11+
const workerAdapter = fs.readFileSync(path.join(siteRoot, '_worker.js'), 'utf8').trim();
12+
assert.equal(workerAdapter, "export { default } from './edge/worker.js';");
13+
});
14+
915
test('restores only safe same-origin fallback paths', () => {
1016
assert.equal(core.safeForwardedPath('/s/scr_123?from=wechat'), '/s/scr_123?from=wechat');
1117
assert.equal(core.safeForwardedPath('//evil.example/s/123'), '');
@@ -281,8 +287,8 @@ test('share fallback calls only the canonical Community V2 API', () => {
281287
assert.match(source, /community-api\.pythonide\.xin\/v2\/community/);
282288
});
283289
assert.match(controller, /\/works\/\$\{encodeURIComponent\(route\.id\)\}\/share/);
284-
assert.match(workflow, /cron:\s*"17 \*\/6 \* \* \*"/);
285-
assert.doesNotMatch(workflow, /\*\/5 \* \* \* \*/);
290+
assert.doesNotMatch(workflow, /\bschedule\s*:/);
291+
assert.doesNotMatch(workflow, /\bcron\s*:/);
286292
});
287293

288294
test('AASA hands Community V2 shares to the app without claiming reserved short links', () => {

0 commit comments

Comments
 (0)