@velocity-astro/cms-astro 0.1.0-beta.1 → 0.1.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/cms.md +145 -0
- package/agents/skills/cms-add-content-type/SKILL.md +81 -0
- package/agents/skills/cms-add-form/SKILL.md +85 -0
- package/agents/skills/cms-add-section/SKILL.md +97 -0
- package/agents/skills/cms-add-to-site/SKILL.md +57 -0
- package/agents/skills/cms-connect-page/SKILL.md +64 -0
- package/agents/skills/cms-deploy/SKILL.md +64 -0
- package/agents/skills/cms-import-content/SKILL.md +63 -0
- package/agents/skills/cms-set-up-crm/SKILL.md +53 -0
- package/agents/skills/cms-write-plugin/SKILL.md +81 -0
- package/dist/admin-files.d.ts +2 -2
- package/dist/admin-files.d.ts.map +1 -1
- package/dist/admin-files.js +13 -7
- package/dist/admin-files.js.map +1 -1
- package/dist/agent-files.d.ts +23 -0
- package/dist/agent-files.d.ts.map +1 -0
- package/dist/agent-files.js +84 -0
- package/dist/agent-files.js.map +1 -0
- package/dist/challenge.d.ts +35 -0
- package/dist/challenge.d.ts.map +1 -0
- package/dist/challenge.js +84 -0
- package/dist/challenge.js.map +1 -0
- package/dist/check.d.ts +38 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +194 -0
- package/dist/check.js.map +1 -0
- package/dist/cli-content.d.ts +22 -0
- package/dist/cli-content.d.ts.map +1 -0
- package/dist/cli-content.js +309 -0
- package/dist/cli-content.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +130 -6
- package/dist/cli.js.map +1 -1
- package/dist/connection.d.ts +1 -0
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +31 -6
- package/dist/connection.js.map +1 -1
- package/dist/editor.d.ts +2 -0
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +10 -1
- package/dist/editor.js.map +1 -1
- package/dist/form-post.d.ts +9 -1
- package/dist/form-post.d.ts.map +1 -1
- package/dist/form-post.js +10 -3
- package/dist/form-post.js.map +1 -1
- package/dist/hosted.d.ts +76 -0
- package/dist/hosted.d.ts.map +1 -0
- package/dist/hosted.js +104 -0
- package/dist/hosted.js.map +1 -0
- package/dist/image-optimizer.d.ts +35 -0
- package/dist/image-optimizer.d.ts.map +1 -0
- package/dist/image-optimizer.js +76 -0
- package/dist/image-optimizer.js.map +1 -0
- package/dist/import-files.d.ts +30 -0
- package/dist/import-files.d.ts.map +1 -0
- package/dist/import-files.js +100 -0
- package/dist/import-files.js.map +1 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +2 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +16 -1
- package/dist/init.js.map +1 -1
- package/dist/integration.d.ts +9 -0
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +15 -1
- package/dist/integration.js.map +1 -1
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +6 -2
- package/dist/link.js.map +1 -1
- package/dist/live-loader.d.ts +7 -3
- package/dist/live-loader.d.ts.map +1 -1
- package/dist/live-loader.js +12 -6
- package/dist/live-loader.js.map +1 -1
- package/dist/media-store.d.ts +15 -0
- package/dist/media-store.d.ts.map +1 -1
- package/dist/media-store.js +26 -2
- package/dist/media-store.js.map +1 -1
- package/dist/page-marks.d.ts +50 -0
- package/dist/page-marks.d.ts.map +1 -0
- package/dist/page-marks.js +90 -0
- package/dist/page-marks.js.map +1 -0
- package/dist/preview.d.ts +34 -2
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +81 -15
- package/dist/preview.js.map +1 -1
- package/dist/resend-mailer.d.ts +18 -1
- package/dist/resend-mailer.d.ts.map +1 -1
- package/dist/resend-mailer.js +24 -3
- package/dist/resend-mailer.js.map +1 -1
- package/dist/secret.d.ts +1 -1
- package/dist/secret.d.ts.map +1 -1
- package/dist/secret.js +3 -2
- package/dist/secret.js.map +1 -1
- package/dist/single.d.ts +18 -0
- package/dist/single.d.ts.map +1 -0
- package/dist/single.js +37 -0
- package/dist/single.js.map +1 -0
- package/dist/site-client.d.ts +37 -0
- package/dist/site-client.d.ts.map +1 -0
- package/dist/site-client.js +73 -0
- package/dist/site-client.js.map +1 -0
- package/dist/site-editor.d.ts +1 -1
- package/dist/site-editor.d.ts.map +1 -1
- package/dist/site-editor.js +36 -6
- package/dist/site-editor.js.map +1 -1
- package/dist/site-forms.d.ts +11 -0
- package/dist/site-forms.d.ts.map +1 -1
- package/dist/site-forms.js +37 -19
- package/dist/site-forms.js.map +1 -1
- package/dist/site-mail.d.ts +45 -0
- package/dist/site-mail.d.ts.map +1 -0
- package/dist/site-mail.js +84 -0
- package/dist/site-mail.js.map +1 -0
- package/dist/site-media.d.ts +5 -1
- package/dist/site-media.d.ts.map +1 -1
- package/dist/site-media.js +14 -5
- package/dist/site-media.js.map +1 -1
- package/dist/site-name.d.ts +9 -0
- package/dist/site-name.d.ts.map +1 -0
- package/dist/site-name.js +21 -0
- package/dist/site-name.js.map +1 -0
- package/dist/site-storage.d.ts +34 -0
- package/dist/site-storage.d.ts.map +1 -0
- package/dist/site-storage.js +118 -0
- package/dist/site-storage.js.map +1 -0
- package/package.json +12 -8
- package/routes/editor.ts +7 -6
- package/routes/form-client.js.ts +68 -0
- package/routes/media.ts +2 -2
- package/routes/preview-client.js.ts +11 -56
- package/routes/published.ts +2 -2
- package/routes/sitemap-live.xml.ts +4 -1
- package/routes/sites.ts +11 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { ConflictError, isPrivateAddress } from '@velocity-astro/cms-core';
|
|
2
|
+
import { S3MediaStore, StorageRefusedError } from './media-store.js';
|
|
3
|
+
/** A small PNG: one see-through pixel. What a test keeps in the bucket, reads back and removes. */
|
|
4
|
+
const PIXEL = Uint8Array.from(atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='), (letter) => letter.charCodeAt(0));
|
|
5
|
+
/**
|
|
6
|
+
* Where one site's uploads are kept, decided as each file is kept or read: the store the server
|
|
7
|
+
* or the host fixed, then the bucket an owner named in the editor, then the folder on the
|
|
8
|
+
* server's disk. The editor's settings are read again every few seconds, so every running copy
|
|
9
|
+
* follows a change. A file kept on the disk before a bucket was named is still read from there.
|
|
10
|
+
*/
|
|
11
|
+
export class SiteMediaStore {
|
|
12
|
+
#options;
|
|
13
|
+
#named = null;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.#options = options;
|
|
16
|
+
}
|
|
17
|
+
async ready() {
|
|
18
|
+
return (await this.#place()) !== undefined;
|
|
19
|
+
}
|
|
20
|
+
async put(key, file) {
|
|
21
|
+
const place = await this.#place();
|
|
22
|
+
if (!place)
|
|
23
|
+
throw new ConflictError('This site has nowhere to keep uploads yet. An owner can set storage up under Settings, Storage.');
|
|
24
|
+
await place.put(key, file);
|
|
25
|
+
}
|
|
26
|
+
async get(key) {
|
|
27
|
+
const place = await this.#place();
|
|
28
|
+
const { folder } = this.#options;
|
|
29
|
+
const found = (await place?.get(key)) ?? null;
|
|
30
|
+
// An image uploaded before the bucket was named is still on the disk.
|
|
31
|
+
return found === null && folder && place !== folder ? folder.get(key) : found;
|
|
32
|
+
}
|
|
33
|
+
async remove(key) {
|
|
34
|
+
const place = await this.#place();
|
|
35
|
+
const { folder } = this.#options;
|
|
36
|
+
await place?.remove(key);
|
|
37
|
+
if (folder && place !== folder)
|
|
38
|
+
await folder.remove(key);
|
|
39
|
+
}
|
|
40
|
+
/** What the settings screen asks: who decides, where an upload would go, and whether the named bucket works. */
|
|
41
|
+
room() {
|
|
42
|
+
return {
|
|
43
|
+
fixedBy: () => this.#fixedBy(),
|
|
44
|
+
keeping: () => this.#keeping(),
|
|
45
|
+
test: () => this.#test(),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
#fixedBy() {
|
|
49
|
+
return this.#options.hosted === true ? 'host' : this.#options.fixed ? 'server' : null;
|
|
50
|
+
}
|
|
51
|
+
async #keeping() {
|
|
52
|
+
const place = await this.#place().catch(() => undefined);
|
|
53
|
+
return place === undefined ? 'none' : place === this.#options.folder ? 'folder' : 'bucket';
|
|
54
|
+
}
|
|
55
|
+
async #place() {
|
|
56
|
+
const { fixed, folder } = this.#options;
|
|
57
|
+
if (fixed || this.#options.hosted === true)
|
|
58
|
+
return fixed;
|
|
59
|
+
return (await this.#bucket()) ?? folder;
|
|
60
|
+
}
|
|
61
|
+
/** The bucket the editor's settings name, made anew when they are read again. */
|
|
62
|
+
#bucket() {
|
|
63
|
+
const now = Date.now();
|
|
64
|
+
if (this.#named === null || now - this.#named.at >= (this.#options.believeForMs ?? 5000)) {
|
|
65
|
+
const store = this.#options.account().then((account) => (account === null ? undefined : this.#storeFor(account)));
|
|
66
|
+
const named = { at: now, store };
|
|
67
|
+
this.#named = named;
|
|
68
|
+
// A failure is not believed for five seconds: the next file asks again.
|
|
69
|
+
store.catch(() => {
|
|
70
|
+
if (this.#named === named)
|
|
71
|
+
this.#named = null;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return this.#named.store;
|
|
75
|
+
}
|
|
76
|
+
async #storeFor(account) {
|
|
77
|
+
const host = new URL(account.endpoint).hostname;
|
|
78
|
+
const addresses = await this.#options.lookup(host).catch(() => []);
|
|
79
|
+
if (addresses.length === 0 || addresses.some(isPrivateAddress)) {
|
|
80
|
+
throw new ConflictError(`The storage service's address, ${host}, leads nowhere this site may send files. Check it under Settings, Storage.`);
|
|
81
|
+
}
|
|
82
|
+
const send = this.#options.fetch ?? globalThis.fetch;
|
|
83
|
+
// An answer that sends the request elsewhere is refused: only the address that was checked is used.
|
|
84
|
+
return new S3MediaStore({ ...account, fetch: (input, init) => send(input, { ...init, redirect: 'error' }) });
|
|
85
|
+
}
|
|
86
|
+
async #test() {
|
|
87
|
+
const account = await this.#options.account();
|
|
88
|
+
if (account === null)
|
|
89
|
+
throw new ConflictError('There is no bucket to try yet. Save its address, name and both keys first.');
|
|
90
|
+
const bucket = await this.#storeFor(account);
|
|
91
|
+
const key = `connection-test-${globalThis.crypto.randomUUID().replace(/-/g, '')}.png`;
|
|
92
|
+
try {
|
|
93
|
+
await bucket.put(key, { bytes: PIXEL, contentType: 'image/png' });
|
|
94
|
+
const back = await bucket.get(key);
|
|
95
|
+
await bucket.remove(key);
|
|
96
|
+
if (back === null || back.bytes.length !== PIXEL.length)
|
|
97
|
+
throw new ConflictError('The bucket took a file and did not give it back. Check that the keys may read from it as well as write.');
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (error instanceof ConflictError)
|
|
101
|
+
throw error;
|
|
102
|
+
if (!(error instanceof StorageRefusedError)) {
|
|
103
|
+
throw new ConflictError('The storage service could not be reached. Check its address, and the region if the service has more than one.');
|
|
104
|
+
}
|
|
105
|
+
const { status } = error;
|
|
106
|
+
throw new ConflictError(status === 401 || status === 403
|
|
107
|
+
? `The storage service refused the keys (${status}). Check that both were pasted whole, and that they may read, write and delete in this bucket.`
|
|
108
|
+
: status === 404
|
|
109
|
+
? 'The storage service knows no bucket of this name (404). Check the name, and that the address is the one for your account.'
|
|
110
|
+
: status === 400
|
|
111
|
+
? 'The storage service did not accept the request (400). Check the region: it must be the one the bucket is in.'
|
|
112
|
+
: `The storage service could not keep a file (${status}). Try again in a moment.`);
|
|
113
|
+
}
|
|
114
|
+
// What was just proved is used at once, not in five seconds.
|
|
115
|
+
this.#named = null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=site-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-storage.js","sourceRoot":"","sources":["../src/site-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAqI,MAAM,0BAA0B,CAAC;AAC9M,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MA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AAK,YAAY,aAAa;gBAAE,MAAM,KAAK,CAAC;YAChD,IAAI,CAAC,CAAC,KAAK,YAAY,mBAAmB,CAAC,EAAE,CAAC;gBAC5C,MAAM,IAAI,aAAa,CAAC,+GAA+G,CAAC,CAAC;YAC3I,CAAC;YACD,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;YACzB,MAAM,IAAI,aAAa,CACrB,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG;gBAC9B,CAAC,CAAC,yCAAyC,MAAM,gGAAgG;gBACjJ,CAAC,CAAC,MAAM,KAAK,GAAG;oBACd,CAAC,CAAC,2HAA2H;oBAC7H,CAAC,CAAC,MAAM,KAAK,GAAG;wBACd,CAAC,CAAC,8GAA8G;wBAChH,CAAC,CAAC,8CAA8C,MAAM,2BAA2B,CACxF,CAAC;QACJ,CAAC;QACD,6DAA6D;QAC7D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velocity-astro/cms-astro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.12",
|
|
4
4
|
"description": "The Astro side of Velocity CMS: a live loader for pages rendered on demand, a Content Layer loader for static builds, and the integration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,15 +31,19 @@
|
|
|
31
31
|
"dist",
|
|
32
32
|
"routes",
|
|
33
33
|
"bin",
|
|
34
|
+
"agents",
|
|
34
35
|
"!dist/**/*.test.*"
|
|
35
36
|
],
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@velocity-astro/cms-
|
|
38
|
-
"@velocity-astro/cms-
|
|
39
|
-
"@velocity-astro/cms-auth": "0.1.0-beta.
|
|
40
|
-
"@velocity-astro/cms-
|
|
41
|
-
"@velocity-astro/cms-
|
|
42
|
-
"@velocity-astro/cms-
|
|
38
|
+
"@velocity-astro/cms-admin": "0.1.0-beta.12",
|
|
39
|
+
"@velocity-astro/cms-api": "0.1.0-beta.12",
|
|
40
|
+
"@velocity-astro/cms-auth": "0.1.0-beta.12",
|
|
41
|
+
"@velocity-astro/cms-db": "0.1.0-beta.12",
|
|
42
|
+
"@velocity-astro/cms-plugins": "0.1.0-beta.12",
|
|
43
|
+
"@velocity-astro/cms-core": "0.1.0-beta.12"
|
|
44
|
+
},
|
|
45
|
+
"optionalDependencies": {
|
|
46
|
+
"sharp": "^0.35.4"
|
|
43
47
|
},
|
|
44
48
|
"peerDependencies": {
|
|
45
49
|
"astro": "^7.0.0"
|
|
@@ -51,6 +55,6 @@
|
|
|
51
55
|
"external": true
|
|
52
56
|
},
|
|
53
57
|
"bin": {
|
|
54
|
-
"velocity-cms": "
|
|
58
|
+
"velocity-cms": "bin/velocity-cms.mjs"
|
|
55
59
|
}
|
|
56
60
|
}
|
package/routes/editor.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* What the editor's three routes share. Compiled with the site, like every file here, so it can
|
|
3
3
|
* read the settings the integration wrote and the site's own mailer.
|
|
4
4
|
*/
|
|
5
|
-
import { indexPages, pagesOrigin, siteEditorHost, withEditor, type EditorHost, type SiteEditorSettings } from '@velocity-astro/cms-astro';
|
|
5
|
+
import { currentSite, indexPages, pagesOrigin, siteCacheTag, siteEditorHost, withEditor, type EditorHost, type SiteEditorSettings } from '@velocity-astro/cms-astro';
|
|
6
6
|
import images from 'virtual:velocity-cms/images';
|
|
7
7
|
import mailer from 'virtual:velocity-cms/mailer';
|
|
8
8
|
import options from 'virtual:velocity-cms/options';
|
|
@@ -24,23 +24,24 @@ export const ownOrigin = (request: Request): string | null => pagesOrigin(reques
|
|
|
24
24
|
export async function showPublished(host: EditorHost, cache: PageCache, origin: string | null): Promise<void> {
|
|
25
25
|
const changed = host.takePublished();
|
|
26
26
|
if (!changed) return;
|
|
27
|
-
await cache.invalidate({ tags: [
|
|
27
|
+
await cache.invalidate({ tags: [siteCacheTag()] });
|
|
28
28
|
if (origin === null) return;
|
|
29
29
|
await indexPages(origin, changed).catch((error: unknown) => console.error('[velocity-cms] Search was not updated.', error));
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/** When
|
|
33
|
-
|
|
32
|
+
/** When each site's editor was last found not to be set up, so a site without one is not asked on every request. */
|
|
33
|
+
const notSetUpAt = new Map<string, number>();
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Publishes what was set to go out by now, and shows it. A site whose editor is not set up has
|
|
37
37
|
* nothing scheduled, so that is passed over in silence.
|
|
38
38
|
*/
|
|
39
39
|
export async function publishDue(request: Request, cache: PageCache, options: { now?: boolean } = {}): Promise<void> {
|
|
40
|
-
|
|
40
|
+
const site = currentSite()?.id ?? '';
|
|
41
|
+
if (Date.now() - (notSetUpAt.get(site) ?? 0) < 30_000) return;
|
|
41
42
|
const host = await siteEditorHost(request, settings).catch(() => null);
|
|
42
43
|
if (!host) {
|
|
43
|
-
notSetUpAt
|
|
44
|
+
notSetUpAt.set(site, Date.now());
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
47
|
await host.publishDue(options);
|
package/routes/form-client.js.ts
CHANGED
|
@@ -15,6 +15,11 @@ export const prerender = false;
|
|
|
15
15
|
* - a submit button may carry `data-cms-form-sending`, its words while the form is on its way.
|
|
16
16
|
* They replace the button's words, or those of the `[data-cms-form-label]` inside it.
|
|
17
17
|
*
|
|
18
|
+
* - `[data-cms-form-challenge]`: where the check that the sender is a person is drawn, when an
|
|
19
|
+
* owner set one up (Cloudflare Turnstile). Without the mark it is drawn above the submit
|
|
20
|
+
* button. A site with a content security policy allows `https://challenges.cloudflare.com`
|
|
21
|
+
* for scripts and frames.
|
|
22
|
+
*
|
|
18
23
|
* Every word is written as text. Nothing the visitor typed comes back from the site.
|
|
19
24
|
*/
|
|
20
25
|
const SCRIPT = `
|
|
@@ -39,6 +44,66 @@ function say(form, state, message) {
|
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
const CHALLENGE = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
|
|
48
|
+
const challenges = new WeakMap();
|
|
49
|
+
const waiting = new WeakMap();
|
|
50
|
+
let challengeScript;
|
|
51
|
+
|
|
52
|
+
/** Loads the challenge's script once, however many forms a page has. */
|
|
53
|
+
function challengeReady() {
|
|
54
|
+
challengeScript ??= new Promise((resolve, reject) => {
|
|
55
|
+
if (window.turnstile) return resolve();
|
|
56
|
+
const script = document.createElement('script');
|
|
57
|
+
script.src = CHALLENGE;
|
|
58
|
+
script.async = true;
|
|
59
|
+
script.onload = () => resolve();
|
|
60
|
+
script.onerror = () => {
|
|
61
|
+
challengeScript = undefined;
|
|
62
|
+
reject(new Error('The challenge could not be loaded.'));
|
|
63
|
+
};
|
|
64
|
+
document.head.append(script);
|
|
65
|
+
});
|
|
66
|
+
return challengeScript;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Draws the check that the sender is a person, when the form carries a site key for one. */
|
|
70
|
+
function challenge(form) {
|
|
71
|
+
const siteKey = form.elements.namedItem('_challenge')?.value;
|
|
72
|
+
if (!siteKey || challenges.has(form)) return;
|
|
73
|
+
let place = form.querySelector('[data-cms-form-challenge]');
|
|
74
|
+
if (!place) {
|
|
75
|
+
place = document.createElement('div');
|
|
76
|
+
place.dataset.cmsFormChallenge = '';
|
|
77
|
+
const button = form.querySelector('[type="submit"]');
|
|
78
|
+
if (button) button.before(place);
|
|
79
|
+
else form.append(place);
|
|
80
|
+
}
|
|
81
|
+
challenges.set(
|
|
82
|
+
form,
|
|
83
|
+
challengeReady()
|
|
84
|
+
.then(() => window.turnstile.render(place, { sitekey: siteKey, theme: 'auto', size: 'flexible', language: document.documentElement.lang || 'auto', callback: () => waiting.get(form)?.() }))
|
|
85
|
+
// Without the challenge the form still posts. The site decides what to make of it.
|
|
86
|
+
.catch(() => undefined),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Waits, for a while, for the sender to pass a challenge that is still being worked out. */
|
|
91
|
+
async function challengePassed(form) {
|
|
92
|
+
const widget = await challenges.get(form);
|
|
93
|
+
if (widget == null || window.turnstile.getResponse(widget)) return;
|
|
94
|
+
await new Promise((resolve) => {
|
|
95
|
+
waiting.set(form, resolve);
|
|
96
|
+
setTimeout(resolve, 15000);
|
|
97
|
+
});
|
|
98
|
+
waiting.delete(form);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** An answer to the challenge is used once: a new one is asked for after every post. */
|
|
102
|
+
async function challengeAgain(form) {
|
|
103
|
+
const widget = await challenges.get(form);
|
|
104
|
+
if (widget != null) window.turnstile?.reset(widget);
|
|
105
|
+
}
|
|
106
|
+
|
|
42
107
|
async function send(form) {
|
|
43
108
|
const button = form.querySelector('[type="submit"]');
|
|
44
109
|
const words = button?.querySelector('[data-cms-form-label]') ?? button;
|
|
@@ -50,6 +115,7 @@ async function send(form) {
|
|
|
50
115
|
if (button.dataset.cmsFormSending) words.textContent = button.dataset.cmsFormSending;
|
|
51
116
|
}
|
|
52
117
|
try {
|
|
118
|
+
await challengePassed(form);
|
|
53
119
|
const response = await fetch(form.action, { method: 'POST', headers: { accept: 'application/json' }, body: new URLSearchParams(new FormData(form)) });
|
|
54
120
|
const answer = await response.json().catch(() => null);
|
|
55
121
|
if (response.ok && answer?.ok) {
|
|
@@ -75,6 +141,7 @@ async function send(form) {
|
|
|
75
141
|
} catch {
|
|
76
142
|
say(form, 'failed', form.dataset.cmsFormFailed ?? '');
|
|
77
143
|
} finally {
|
|
144
|
+
void challengeAgain(form);
|
|
78
145
|
if (button) {
|
|
79
146
|
button.disabled = false;
|
|
80
147
|
words.textContent = label;
|
|
@@ -86,6 +153,7 @@ function start() {
|
|
|
86
153
|
for (const form of document.querySelectorAll('form[data-cms-form]')) {
|
|
87
154
|
if (form.dataset.cmsFormReady) continue;
|
|
88
155
|
form.dataset.cmsFormReady = 'true';
|
|
156
|
+
challenge(form);
|
|
89
157
|
form.addEventListener('submit', (event) => {
|
|
90
158
|
event.preventDefault();
|
|
91
159
|
if (form.dataset.cmsFormState !== 'sending') void send(form);
|
package/routes/media.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { uploadedFile } from '@velocity-astro/cms-astro';
|
|
|
4
4
|
export const prerender = false;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* An image someone uploaded in the editor. It may be cached, and says so itself: a file never
|
|
7
|
+
* An image someone uploaded in the editor, or with `?w=` a smaller copy of it. It may be cached, and says so itself: a file never
|
|
8
8
|
* changes once it is kept.
|
|
9
9
|
*/
|
|
10
|
-
export const GET: APIRoute = ({ params }) => uploadedFile(params.file ?? '');
|
|
10
|
+
export const GET: APIRoute = ({ params, url }) => uploadedFile(params.file ?? '', url.searchParams.get('w'));
|
|
@@ -1,63 +1,18 @@
|
|
|
1
1
|
import type { APIRoute } from 'astro';
|
|
2
|
+
import { EDITOR_PREVIEW_VERSION, PREVIEW_BRIDGE_SCRIPT } from '@velocity-astro/cms-astro';
|
|
2
3
|
|
|
3
4
|
export const prerender = false;
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
* What the page beside the editor's form runs. The preview adds it to
|
|
7
|
-
* does nothing unless the page is in a frame of the same site.
|
|
7
|
+
* What the page beside the editor's form runs (`src/preview-bridge.ts`). The preview adds it to
|
|
8
|
+
* that page only, and it does nothing unless the page is in a frame of the same site.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* would not
|
|
10
|
+
* The page asks for it by the mark of this version, and a browser keeps that: the page is drawn
|
|
11
|
+
* again with every change in the form, and a script that is at hand runs before the page is seen,
|
|
12
|
+
* so the page comes back where it was. Asked for any other way, it is fetched each time, since a
|
|
13
|
+
* copy kept from before an upgrade would not know what the editor now says to it.
|
|
13
14
|
*/
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const sectionOf = (target) => (target instanceof Element ? target.closest('[data-cms-section]') : null);
|
|
19
|
-
|
|
20
|
-
let marked = null;
|
|
21
|
-
const mark = (section) => {
|
|
22
|
-
if (marked === section) return;
|
|
23
|
-
if (marked) marked.style.outline = marked.style.outlineOffset = marked.style.cursor = '';
|
|
24
|
-
marked = section;
|
|
25
|
-
if (!section) return;
|
|
26
|
-
section.style.outline = '2px solid Highlight';
|
|
27
|
-
section.style.outlineOffset = '-2px';
|
|
28
|
-
section.style.cursor = 'pointer';
|
|
29
|
-
};
|
|
30
|
-
document.addEventListener('mouseover', (event) => mark(sectionOf(event.target)));
|
|
31
|
-
document.documentElement.addEventListener('mouseleave', () => mark(null));
|
|
32
|
-
|
|
33
|
-
// Nothing on the page goes anywhere: a click chooses the section it is in.
|
|
34
|
-
document.addEventListener('click', (event) => {
|
|
35
|
-
event.preventDefault();
|
|
36
|
-
const section = sectionOf(event.target);
|
|
37
|
-
if (section) say({ type: 'section', id: section.dataset.cmsSection });
|
|
38
|
-
}, true);
|
|
39
|
-
document.addEventListener('submit', (event) => event.preventDefault(), true);
|
|
40
|
-
|
|
41
|
-
addEventListener('message', (event) => {
|
|
42
|
-
if (event.origin !== origin || event.source !== window.parent || event.data?.source !== 'velocity-cms') return;
|
|
43
|
-
if (event.data.type !== 'show') return;
|
|
44
|
-
const section = [...document.querySelectorAll('[data-cms-section]')].find((candidate) => candidate.dataset.cmsSection === event.data.id);
|
|
45
|
-
if (!section) return;
|
|
46
|
-
// Room for a header that stays at the top of the page.
|
|
47
|
-
section.style.scrollMarginTop = '6rem';
|
|
48
|
-
section.scrollIntoView({ block: 'start' });
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const key = 'velocity-cms:scroll:' + location.pathname;
|
|
52
|
-
try {
|
|
53
|
-
const kept = Number(sessionStorage.getItem(key));
|
|
54
|
-
if (kept > 0) scrollTo({ top: kept, behavior: 'instant' });
|
|
55
|
-
addEventListener('pagehide', () => sessionStorage.setItem(key, String(scrollY)));
|
|
56
|
-
} catch {}
|
|
57
|
-
|
|
58
|
-
say({ type: 'ready' });
|
|
59
|
-
}
|
|
60
|
-
`;
|
|
61
|
-
|
|
62
|
-
export const GET: APIRoute = () =>
|
|
63
|
-
new Response(SCRIPT, { headers: { 'Content-Type': 'text/javascript; charset=utf-8', 'Cache-Control': 'public, max-age=3600' } });
|
|
15
|
+
export const GET: APIRoute = ({ url }) => {
|
|
16
|
+
const kept = url.searchParams.get('v') === EDITOR_PREVIEW_VERSION ? 'private, max-age=31536000, immutable' : 'no-cache';
|
|
17
|
+
return new Response(PREVIEW_BRIDGE_SCRIPT, { headers: { 'Content-Type': 'text/javascript; charset=utf-8', 'Cache-Control': kept } });
|
|
18
|
+
};
|
package/routes/published.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { APIRoute } from 'astro';
|
|
2
|
-
import { hasSiteSecret, indexPages, indexSite, invalidateLiveContent } from '@velocity-astro/cms-astro';
|
|
2
|
+
import { hasSiteSecret, indexPages, indexSite, invalidateLiveContent, siteCacheTag } from '@velocity-astro/cms-astro';
|
|
3
3
|
import { ownOrigin } from './editor.ts';
|
|
4
4
|
import { addresses, clientDir } from './pages.ts';
|
|
5
5
|
|
|
@@ -18,7 +18,7 @@ interface Notice {
|
|
|
18
18
|
export const POST: APIRoute = async ({ cache, request }) => {
|
|
19
19
|
if (!hasSiteSecret(request)) return new Response(null, { status: 404 });
|
|
20
20
|
invalidateLiveContent();
|
|
21
|
-
await cache.invalidate({ tags: [
|
|
21
|
+
await cache.invalidate({ tags: [siteCacheTag()] });
|
|
22
22
|
const { reindex } = (await request.json().catch(() => ({}))) as Notice;
|
|
23
23
|
const origin = ownOrigin(request);
|
|
24
24
|
if (!reindex || origin === null) return Response.json({});
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { APIRoute } from 'astro';
|
|
2
|
+
import { currentSite } from '@velocity-astro/cms-astro';
|
|
2
3
|
import { addresses } from './pages.ts';
|
|
3
4
|
|
|
4
5
|
export const prerender = false;
|
|
5
6
|
|
|
6
7
|
/** The live pages' share of the sitemap. Point `sitemap-index.xml` here with `customSitemaps`. */
|
|
7
8
|
export const GET: APIRoute = async ({ site, url }) => {
|
|
9
|
+
// On a server that runs many sites, the addresses are the asked site's, not the template's.
|
|
10
|
+
const base = currentSite()?.origin ?? site ?? url;
|
|
8
11
|
const urls = (await addresses())
|
|
9
12
|
.filter((address) => address.listed && !address.fixed)
|
|
10
|
-
.map((address) => `<url><loc>${new URL(address.path,
|
|
13
|
+
.map((address) => `<url><loc>${new URL(address.path, base).href}</loc></url>`);
|
|
11
14
|
const xml = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${urls.join('')}</urlset>`;
|
|
12
15
|
return new Response(xml, { headers: { 'Content-Type': 'application/xml; charset=utf-8' } });
|
|
13
16
|
};
|
package/routes/sites.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chooses the site each request is for, on a server that runs many sites from this one copy.
|
|
3
|
+
* Compiled with the site, like every file here, so the site's bundler reads the file that knows
|
|
4
|
+
* the sites; it runs first, before anything reads content.
|
|
5
|
+
*/
|
|
6
|
+
import { hostedRequest, useSiteRegistry } from '@velocity-astro/cms-astro';
|
|
7
|
+
import sites from 'virtual:velocity-cms/sites';
|
|
8
|
+
|
|
9
|
+
useSiteRegistry(sites);
|
|
10
|
+
|
|
11
|
+
export const onRequest = hostedRequest;
|