@velocity-astro/cms-astro 0.0.0-stage → 0.1.0-beta.11
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/LICENSE +21 -0
- package/README.md +12 -2
- package/bin/velocity-cms.mjs +6 -0
- package/dist/admin-files.d.ts +21 -0
- package/dist/admin-files.d.ts.map +1 -0
- package/dist/admin-files.js +83 -0
- package/dist/admin-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/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +76 -0
- package/dist/cli.js.map +1 -0
- package/dist/connection.d.ts +26 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +87 -0
- package/dist/connection.js.map +1 -0
- package/dist/editor.d.ts +67 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +194 -0
- package/dist/editor.js.map +1 -0
- package/dist/entry-page.d.ts +37 -0
- package/dist/entry-page.d.ts.map +1 -0
- package/dist/entry-page.js +56 -0
- package/dist/entry-page.js.map +1 -0
- package/dist/form-post.d.ts +114 -0
- package/dist/form-post.d.ts.map +1 -0
- package/dist/form-post.js +298 -0
- package/dist/form-post.js.map +1 -0
- 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/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +35 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +140 -0
- package/dist/init.js.map +1 -0
- package/dist/integration.d.ts +72 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +143 -0
- package/dist/integration.js.map +1 -0
- package/dist/link.d.ts +32 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +80 -0
- package/dist/link.js.map +1 -0
- package/dist/live-loader.d.ts +44 -0
- package/dist/live-loader.d.ts.map +1 -0
- package/dist/live-loader.js +98 -0
- package/dist/live-loader.js.map +1 -0
- package/dist/live-pages.d.ts +69 -0
- package/dist/live-pages.d.ts.map +1 -0
- package/dist/live-pages.js +94 -0
- package/dist/live-pages.js.map +1 -0
- package/dist/loader.d.ts +22 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +62 -0
- package/dist/loader.js.map +1 -0
- package/dist/media-store.d.ts +61 -0
- package/dist/media-store.d.ts.map +1 -0
- package/dist/media-store.js +178 -0
- package/dist/media-store.js.map +1 -0
- package/dist/menu.d.ts +51 -0
- package/dist/menu.d.ts.map +1 -0
- package/dist/menu.js +81 -0
- package/dist/menu.js.map +1 -0
- package/dist/page-head.d.ts +23 -0
- package/dist/page-head.d.ts.map +1 -0
- package/dist/page-head.js +66 -0
- package/dist/page-head.js.map +1 -0
- 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 +92 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +192 -0
- package/dist/preview.js.map +1 -0
- package/dist/resend-mailer.d.ts +63 -0
- package/dist/resend-mailer.d.ts.map +1 -0
- package/dist/resend-mailer.js +116 -0
- package/dist/resend-mailer.js.map +1 -0
- package/dist/secret.d.ts +8 -0
- package/dist/secret.d.ts.map +1 -0
- package/dist/secret.js +17 -0
- package/dist/secret.js.map +1 -0
- 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-editor.d.ts +41 -0
- package/dist/site-editor.d.ts.map +1 -0
- package/dist/site-editor.js +140 -0
- package/dist/site-editor.js.map +1 -0
- package/dist/site-forms.d.ts +54 -0
- package/dist/site-forms.d.ts.map +1 -0
- package/dist/site-forms.js +100 -0
- package/dist/site-forms.js.map +1 -0
- package/dist/site-images.d.ts +17 -0
- package/dist/site-images.d.ts.map +1 -0
- package/dist/site-images.js +22 -0
- package/dist/site-images.js.map +1 -0
- 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 +22 -0
- package/dist/site-media.d.ts.map +1 -0
- package/dist/site-media.js +52 -0
- package/dist/site-media.js.map +1 -0
- 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-plugins.d.ts +10 -0
- package/dist/site-plugins.d.ts.map +1 -0
- package/dist/site-plugins.js +23 -0
- package/dist/site-plugins.js.map +1 -0
- package/dist/site-search.d.ts +12 -0
- package/dist/site-search.d.ts.map +1 -0
- package/dist/site-search.js +79 -0
- package/dist/site-search.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 +56 -3
- package/routes/admin.ts +10 -0
- package/routes/api.ts +15 -0
- package/routes/auth.ts +10 -0
- package/routes/due.ts +12 -0
- package/routes/editor.ts +49 -0
- package/routes/form-client.js.ts +173 -0
- package/routes/media.ts +10 -0
- package/routes/pages.ts +13 -0
- package/routes/plugins.ts +10 -0
- package/routes/preview-client.js.ts +18 -0
- package/routes/published.ts +29 -0
- package/routes/schedule.ts +20 -0
- package/routes/search-client.js.ts +33 -0
- package/routes/search.json.ts +10 -0
- package/routes/share-image.png.ts +33 -0
- package/routes/sitemap-live.xml.ts +16 -0
- package/routes/sites.ts +11 -0
- package/routes/submit.ts +22 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { NotFoundError } from '@velocity-astro/cms-core';
|
|
2
|
+
import { sharedConnection, SITE } from './connection.js';
|
|
3
|
+
import { siteKey } from './hosted.js';
|
|
4
|
+
/**
|
|
5
|
+
* The answer to a request for an uploaded file. A file never changes once it is kept and its
|
|
6
|
+
* name is never given to another, so browsers and the CDN may keep it for good.
|
|
7
|
+
*
|
|
8
|
+
* With a width (`/media/kitchen.webp?w=640`, one of `IMAGE_WIDTHS`) the answer is a copy no
|
|
9
|
+
* wider than that. It is made when asked for and kept by the browser and the CDN like the
|
|
10
|
+
* image itself, so a width is made once.
|
|
11
|
+
*/
|
|
12
|
+
export async function uploadedFile(key, width) {
|
|
13
|
+
const { cms } = await sharedConnection({});
|
|
14
|
+
try {
|
|
15
|
+
// `?w=640` asks for a small copy. Anything that is not a whole number is no width at all.
|
|
16
|
+
if (width != null && !/^[1-9]\d{2,3}$/.test(width))
|
|
17
|
+
throw new NotFoundError('Image', key);
|
|
18
|
+
const file = await cms.media.file(key, width == null ? undefined : Number(width));
|
|
19
|
+
return new Response(file.bytes, {
|
|
20
|
+
headers: {
|
|
21
|
+
'content-type': file.contentType,
|
|
22
|
+
'content-length': String(file.bytes.length),
|
|
23
|
+
'cache-control': 'public, max-age=31536000, immutable',
|
|
24
|
+
// The file is shown as the image it was checked to be, and as nothing else.
|
|
25
|
+
'x-content-type-options': 'nosniff',
|
|
26
|
+
'content-security-policy': "default-src 'none'",
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof NotFoundError)
|
|
32
|
+
return new Response(null, { status: 404, headers: { 'cache-control': 'no-store' } });
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** The uploaded images of each site this server draws pages for. */
|
|
37
|
+
const latest = new Map();
|
|
38
|
+
/**
|
|
39
|
+
* Reads the uploaded images again. The site's middleware does this before each page is
|
|
40
|
+
* rendered, so a page never misses an image that was uploaded a moment ago, whichever server
|
|
41
|
+
* renders it.
|
|
42
|
+
*/
|
|
43
|
+
export async function refreshUploadedImages() {
|
|
44
|
+
const { cms } = await sharedConnection({});
|
|
45
|
+
latest.set(siteKey(), new Map((await cms.media.uploads(SITE)).map((image) => [image.name, image])));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The uploaded image with this name, as it was when the page began to render: its address on
|
|
49
|
+
* this site and its size. `undefined` when no upload has the name.
|
|
50
|
+
*/
|
|
51
|
+
export const uploadedImage = (name) => latest.get(siteKey())?.get(name);
|
|
52
|
+
//# sourceMappingURL=site-media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-media.js","sourceRoot":"","sources":["../src/site-media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAW,EAAE,KAAqB;IACnE,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC3C,IAAI,CAAC;QACH,0FAA0F;QAC1F,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,MAAM,IAAI,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC1F,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAClF,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE;YAC9B,OAAO,EAAE;gBACP,cAAc,EAAE,IAAI,CAAC,WAAW;gBAChC,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;gBAC3C,eAAe,EAAE,qCAAqC;gBACtD,4EAA4E;gBAC5E,wBAAwB,EAAE,SAAS;gBACnC,yBAAyB,EAAE,oBAAoB;aAChD;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,aAAa;YAAE,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;QACzH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,oEAAoE;AACpE,MAAM,MAAM,GAAG,IAAI,GAAG,EAA0C,CAAC;AAEjE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC3C,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,IAAI,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACtG,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAyB,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Cms } from '@velocity-astro/cms-core';
|
|
2
|
+
/**
|
|
3
|
+
* What the site is called, when nothing fixes it: the name published on the page of the settings
|
|
4
|
+
* that holds it (a template's "Business details"), then what an owner saved under Settings,
|
|
5
|
+
* General. `null` when neither says, so the name from the site's code stands. One field names
|
|
6
|
+
* the site for its visitors, its editor and its emails.
|
|
7
|
+
*/
|
|
8
|
+
export declare function siteNameNow(cms: Cms): Promise<string | null>;
|
|
9
|
+
//# sourceMappingURL=site-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-name.d.ts","sourceRoot":"","sources":["../src/site-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAG9E;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAUlE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isLiveType, siteNameFrom } from '@velocity-astro/cms-core';
|
|
2
|
+
import { DEFAULT_LOCALE, entriesOf } from './link.js';
|
|
3
|
+
/**
|
|
4
|
+
* What the site is called, when nothing fixes it: the name published on the page of the settings
|
|
5
|
+
* that holds it (a template's "Business details"), then what an owner saved under Settings,
|
|
6
|
+
* General. `null` when neither says, so the name from the site's code stands. One field names
|
|
7
|
+
* the site for its visitors, its editor and its emails.
|
|
8
|
+
*/
|
|
9
|
+
export async function siteNameNow(cms) {
|
|
10
|
+
const type = (await cms.schema.list()).find((candidate) => isLiveType(candidate) && candidate.siteNamePath !== undefined);
|
|
11
|
+
if (type) {
|
|
12
|
+
const published = (await entriesOf(cms, type)).filter((entry) => entry.published !== undefined);
|
|
13
|
+
// The first language's name is the site's: an email is not written in a visitor's language.
|
|
14
|
+
const entry = published.find((candidate) => candidate.locale === DEFAULT_LOCALE) ?? published[0];
|
|
15
|
+
const name = entry?.published ? siteNameFrom(type, entry.published.data) : null;
|
|
16
|
+
if (name !== null)
|
|
17
|
+
return name;
|
|
18
|
+
}
|
|
19
|
+
return cms.settings.siteName();
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=site-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-name.js","sourceRoot":"","sources":["../src/site-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAY,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAQ;IACxC,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC;IAC1H,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,SAAS,GAAG,CAAC,MAAM,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;QAChG,4FAA4F;QAC5F,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,KAAK,cAAc,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;QACjG,MAAM,IAAI,GAAG,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAChF,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;IACjC,CAAC;IACD,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Called once by the file the integration adds, before any request is answered. */
|
|
2
|
+
export declare function registerSitePlugins(found: readonly unknown[]): void;
|
|
3
|
+
export declare const sitePlugins: () => readonly unknown[];
|
|
4
|
+
/**
|
|
5
|
+
* Every plugin a site has: the ones its config names, then the ones that come with the CMS,
|
|
6
|
+
* which wait switched off for an owner to activate. A site's own plugin wins a name, so a
|
|
7
|
+
* developer can put their own in place of one that ships.
|
|
8
|
+
*/
|
|
9
|
+
export declare function allPlugins(): readonly unknown[];
|
|
10
|
+
//# sourceMappingURL=site-plugins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-plugins.d.ts","sourceRoot":"","sources":["../src/site-plugins.ts"],"names":[],"mappings":"AASA,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI,CAEnE;AAED,eAAO,MAAM,WAAW,QAAO,SAAS,OAAO,EAAa,CAAC;AAI7D;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,SAAS,OAAO,EAAE,CAG/C"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { catalogue } from '@velocity-astro/cms-plugins';
|
|
2
|
+
/**
|
|
3
|
+
* The plugins a site named in its config. They are the site's own files, so the site's bundler
|
|
4
|
+
* reads them: a small file compiled with the site hands them over here when the server starts,
|
|
5
|
+
* and the site's one connection starts them before anything reads content.
|
|
6
|
+
*/
|
|
7
|
+
let plugins = [];
|
|
8
|
+
/** Called once by the file the integration adds, before any request is answered. */
|
|
9
|
+
export function registerSitePlugins(found) {
|
|
10
|
+
plugins = found;
|
|
11
|
+
}
|
|
12
|
+
export const sitePlugins = () => plugins;
|
|
13
|
+
const nameOf = (plugin) => (typeof plugin === 'object' && plugin !== null && 'name' in plugin ? plugin.name : undefined);
|
|
14
|
+
/**
|
|
15
|
+
* Every plugin a site has: the ones its config names, then the ones that come with the CMS,
|
|
16
|
+
* which wait switched off for an owner to activate. A site's own plugin wins a name, so a
|
|
17
|
+
* developer can put their own in place of one that ships.
|
|
18
|
+
*/
|
|
19
|
+
export function allPlugins() {
|
|
20
|
+
const taken = new Set(plugins.map(nameOf));
|
|
21
|
+
return [...plugins, ...catalogue.filter((plugin) => !taken.has(plugin.name))];
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=site-plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-plugins.js","sourceRoot":"","sources":["../src/site-plugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD;;;;GAIG;AACH,IAAI,OAAO,GAAuB,EAAE,CAAC;AAErC,oFAAoF;AACpF,MAAM,UAAU,mBAAmB,CAAC,KAAyB;IAC3D,OAAO,GAAG,KAAK,CAAC;AAClB,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,GAAuB,EAAE,CAAC,OAAO,CAAC;AAE7D,MAAM,MAAM,GAAG,CAAC,MAAe,EAAE,EAAE,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAElI;;;;GAIG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,OAAO,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SearchDocument, SearchResults } from '@velocity-astro/cms-core';
|
|
2
|
+
/**
|
|
3
|
+
* The searchable part of a finished page: what sits inside `data-pagefind-body`, the mark Velocity
|
|
4
|
+
* layouts already put on real content. A page without it (search results, 404) is not searchable.
|
|
5
|
+
*/
|
|
6
|
+
export declare function toSearchDocument(address: string, html: string): SearchDocument | null;
|
|
7
|
+
/** Reads these pages again from the running site and updates their search entries. */
|
|
8
|
+
export declare function indexPages(origin: string, addresses: readonly string[]): Promise<number>;
|
|
9
|
+
/** Every page: the ones the build made, read from `clientDir`, and the live ones. Run once after a deploy. */
|
|
10
|
+
export declare function indexSite(origin: string, clientDir: string, addresses: readonly string[]): Promise<number>;
|
|
11
|
+
export declare function searchSite(text: string, locale: string | undefined): Promise<SearchResults>;
|
|
12
|
+
//# sourceMappingURL=site-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-search.d.ts","sourceRoot":"","sources":["../src/site-search.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAa9E;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAgBrF;AAID,sFAAsF;AACtF,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAmB9F;AAED,8GAA8G;AAC9G,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAYhH;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,CAEjG"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search for a live site, kept in the CMS database. A search document is a page as a visitor
|
|
3
|
+
* reads it, so results match what is on the site. After a publish only the pages that changed
|
|
4
|
+
* are read again, which keeps search as fresh as the page.
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { sharedConnection } from './connection.js';
|
|
9
|
+
const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' };
|
|
10
|
+
const decode = (text) => text
|
|
11
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, code) => String.fromCodePoint(parseInt(code, 16)))
|
|
12
|
+
.replace(/&#(\d+);/g, (_, code) => String.fromCodePoint(Number(code)))
|
|
13
|
+
.replace(/&(amp|lt|gt|quot|apos|nbsp);/g, (_, name) => ENTITIES[name] ?? '');
|
|
14
|
+
const plain = (html) => decode(html.replace(/<[^>]+>/g, ' ')).replace(/\s+/g, ' ').trim();
|
|
15
|
+
const documentId = (address) => `page:${address}`;
|
|
16
|
+
/**
|
|
17
|
+
* The searchable part of a finished page: what sits inside `data-pagefind-body`, the mark Velocity
|
|
18
|
+
* layouts already put on real content. A page without it (search results, 404) is not searchable.
|
|
19
|
+
*/
|
|
20
|
+
export function toSearchDocument(address, html) {
|
|
21
|
+
const start = html.search(/<[^>]+\sdata-pagefind-body/);
|
|
22
|
+
if (start === -1)
|
|
23
|
+
return null;
|
|
24
|
+
const end = html.indexOf('</main>', start);
|
|
25
|
+
const content = html
|
|
26
|
+
.slice(start, end === -1 ? undefined : end)
|
|
27
|
+
.replace(/<(script|style|svg|template|noscript)\b[\s\S]*?<\/\1>/g, ' ');
|
|
28
|
+
const heading = content.match(/<h1\b[^>]*>([\s\S]*?)<\/h1>/)?.[1];
|
|
29
|
+
const title = heading ? plain(heading) : decode(html.match(/<title>([^<]*)<\/title>/)?.[1] ?? address);
|
|
30
|
+
return {
|
|
31
|
+
id: documentId(address),
|
|
32
|
+
locale: html.match(/<html[^>]*\slang="([^"]+)"/)?.[1] ?? 'en',
|
|
33
|
+
url: address,
|
|
34
|
+
title,
|
|
35
|
+
body: plain(content),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const index = async () => (await sharedConnection({})).search;
|
|
39
|
+
/** Reads these pages again from the running site and updates their search entries. */
|
|
40
|
+
export async function indexPages(origin, addresses) {
|
|
41
|
+
const documents = [];
|
|
42
|
+
const gone = [];
|
|
43
|
+
const queue = [...addresses];
|
|
44
|
+
const worker = async () => {
|
|
45
|
+
for (let address = queue.shift(); address !== undefined; address = queue.shift()) {
|
|
46
|
+
// Only the site's own pages are read: an address that leads elsewhere is passed over.
|
|
47
|
+
const target = new URL(address, origin);
|
|
48
|
+
const response = target.origin === new URL(origin).origin ? await fetch(target) : null;
|
|
49
|
+
const document = response?.ok ? toSearchDocument(address, await response.text()) : null;
|
|
50
|
+
if (document)
|
|
51
|
+
documents.push(document);
|
|
52
|
+
else
|
|
53
|
+
gone.push(documentId(address));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
await Promise.all(Array.from({ length: 8 }, worker));
|
|
57
|
+
const search = await index();
|
|
58
|
+
await search.put(documents);
|
|
59
|
+
await search.remove(gone);
|
|
60
|
+
return documents.length;
|
|
61
|
+
}
|
|
62
|
+
/** Every page: the ones the build made, read from `clientDir`, and the live ones. Run once after a deploy. */
|
|
63
|
+
export async function indexSite(origin, clientDir, addresses) {
|
|
64
|
+
const built = fs
|
|
65
|
+
.readdirSync(clientDir, { recursive: true })
|
|
66
|
+
.map(String)
|
|
67
|
+
.filter((file) => file.endsWith('index.html'))
|
|
68
|
+
.map((file) => {
|
|
69
|
+
const address = `/${file.replaceAll('\\', '/').replace(/index\.html$/, '')}`;
|
|
70
|
+
return toSearchDocument(address, fs.readFileSync(path.join(clientDir, file), 'utf8'));
|
|
71
|
+
})
|
|
72
|
+
.filter((document) => document !== null);
|
|
73
|
+
await (await index()).put(built);
|
|
74
|
+
return built.length + (await indexPages(origin, addresses));
|
|
75
|
+
}
|
|
76
|
+
export async function searchSite(text, locale) {
|
|
77
|
+
return (await index()).search({ text, ...(locale !== undefined && { locale }) });
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=site-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-search.js","sourceRoot":"","sources":["../src/site-search.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,QAAQ,GAA2B,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AACzG,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAC9B,IAAI;KACD,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;KAC3F,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;KAC7E,OAAO,CAAC,+BAA+B,EAAE,CAAC,CAAC,EAAE,IAAY,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;AACzF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAElG,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,QAAQ,OAAO,EAAE,CAAC;AAE1D;;;GAG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,SAA4B;IAC7F,MAAM,KAAK,GAAG,EAAE;SACb,WAAW,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;SAC3C,GAAG,CAAC,MAAM,CAAC;SACX,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;SAC7C,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,EAAE,CAAC;QAC7E,OAAO,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACxF,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC;IAC3C,MAAM,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,MAAM,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAY,EAAE,MAA0B;IACvE,OAAO,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type BucketAccount, type MediaStore, type NameLookup, type StorageRoom, type StoredFile } from '@velocity-astro/cms-core';
|
|
2
|
+
export interface SiteMediaStoreOptions {
|
|
3
|
+
/** The bucket an owner named in the editor's settings, read when it is needed. */
|
|
4
|
+
readonly account: () => Promise<BucketAccount | null>;
|
|
5
|
+
/** The store the server's own settings or the site's host name. It wins over the editor's. */
|
|
6
|
+
readonly fixed?: MediaStore | undefined;
|
|
7
|
+
/** Whether a host runs this site among many. Its uploads are then the host's to place, and the editor's settings are never used. */
|
|
8
|
+
readonly hosted?: boolean;
|
|
9
|
+
/** The folder on the server's disk, where there is one: where uploads go until a bucket is named, and where earlier ones are still read. */
|
|
10
|
+
readonly folder?: MediaStore | undefined;
|
|
11
|
+
/** Every address a host's name leads to, so a bucket's address that leads to a private machine is refused. */
|
|
12
|
+
readonly lookup: NameLookup;
|
|
13
|
+
/** Defaults to the platform's own `fetch`. */
|
|
14
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
15
|
+
/** How long the editor's settings are believed before they are read again. Defaults to five seconds. */
|
|
16
|
+
readonly believeForMs?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Where one site's uploads are kept, decided as each file is kept or read: the store the server
|
|
20
|
+
* or the host fixed, then the bucket an owner named in the editor, then the folder on the
|
|
21
|
+
* server's disk. The editor's settings are read again every few seconds, so every running copy
|
|
22
|
+
* follows a change. A file kept on the disk before a bucket was named is still read from there.
|
|
23
|
+
*/
|
|
24
|
+
export declare class SiteMediaStore implements MediaStore {
|
|
25
|
+
#private;
|
|
26
|
+
constructor(options: SiteMediaStoreOptions);
|
|
27
|
+
ready(): Promise<boolean>;
|
|
28
|
+
put(key: string, file: StoredFile): Promise<void>;
|
|
29
|
+
get(key: string): Promise<StoredFile | null>;
|
|
30
|
+
remove(key: string): Promise<void>;
|
|
31
|
+
/** What the settings screen asks: who decides, where an upload would go, and whether the named bucket works. */
|
|
32
|
+
room(): StorageRoom;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=site-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-storage.d.ts","sourceRoot":"","sources":["../src/site-storage.ts"],"names":[],"m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+
/** 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":["../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AC,MAAM,KAAK,KAAK,CAAC,MAAM;gBAAE,MAAM,IAAI,aAAa,CAAC,yGAAyG,CAAC,CAAC;QAC9L,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,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,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velocity-astro/cms-astro",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-beta.11",
|
|
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
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Velocity-Astro/velocity-cms.git",
|
|
10
|
+
"directory": "packages/cms-astro"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://docs.deployvelocity.com/cms/",
|
|
13
|
+
"bugs": "https://github.com/Velocity-Astro/velocity-cms/issues",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22.23.4"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./middleware": {
|
|
26
|
+
"types": "./dist/preview.d.ts",
|
|
27
|
+
"default": "./dist/preview.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"routes",
|
|
33
|
+
"bin",
|
|
34
|
+
"!dist/**/*.test.*"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@velocity-astro/cms-admin": "0.1.0-beta.11",
|
|
38
|
+
"@velocity-astro/cms-api": "0.1.0-beta.11",
|
|
39
|
+
"@velocity-astro/cms-core": "0.1.0-beta.11",
|
|
40
|
+
"@velocity-astro/cms-db": "0.1.0-beta.11",
|
|
41
|
+
"@velocity-astro/cms-plugins": "0.1.0-beta.11",
|
|
42
|
+
"@velocity-astro/cms-auth": "0.1.0-beta.11"
|
|
43
|
+
},
|
|
44
|
+
"optionalDependencies": {
|
|
45
|
+
"sharp": "^0.35.4"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"astro": "^7.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"astro": "7.4.5"
|
|
52
|
+
},
|
|
53
|
+
"astro": {
|
|
54
|
+
"external": true
|
|
55
|
+
},
|
|
56
|
+
"bin": {
|
|
57
|
+
"velocity-cms": "bin/velocity-cms.mjs"
|
|
58
|
+
}
|
|
6
59
|
}
|
package/routes/admin.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { APIRoute } from 'astro';
|
|
2
|
+
import { editor } from './editor.ts';
|
|
3
|
+
|
|
4
|
+
export const prerender = false;
|
|
5
|
+
|
|
6
|
+
/** The editor's page and the files it loads. */
|
|
7
|
+
export const ALL: APIRoute = ({ request, cache }) => {
|
|
8
|
+
cache.set(false);
|
|
9
|
+
return editor(request, (host) => host.admin(request));
|
|
10
|
+
};
|
package/routes/api.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { APIRoute } from 'astro';
|
|
2
|
+
import { editor, ownOrigin, showPublished } from './editor.ts';
|
|
3
|
+
|
|
4
|
+
export const prerender = false;
|
|
5
|
+
|
|
6
|
+
/** The CMS over HTTP, for the editor. Every rule is in the API and the services behind it. */
|
|
7
|
+
export const ALL: APIRoute = ({ request, cache }) => {
|
|
8
|
+
// The API serves drafts. Nothing it answers may be kept.
|
|
9
|
+
cache.set(false);
|
|
10
|
+
return editor(request, async (host) => {
|
|
11
|
+
const response = await host.api(request);
|
|
12
|
+
await showPublished(host, cache, ownOrigin(request));
|
|
13
|
+
return response;
|
|
14
|
+
});
|
|
15
|
+
};
|
package/routes/auth.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { APIRoute } from 'astro';
|
|
2
|
+
import { editor } from './editor.ts';
|
|
3
|
+
|
|
4
|
+
export const prerender = false;
|
|
5
|
+
|
|
6
|
+
/** Sign-in: email links and passkeys. */
|
|
7
|
+
export const ALL: APIRoute = ({ request, cache }) => {
|
|
8
|
+
cache.set(false);
|
|
9
|
+
return editor(request, (host) => host.signIn(request));
|
|
10
|
+
};
|
package/routes/due.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Looks, on a request for a page, for entries whose time to be published has come. The host
|
|
3
|
+
* looks at most every half minute, so nearly every request passes straight through; the one that
|
|
4
|
+
* finds something waits for it, and so is the first to see the new page.
|
|
5
|
+
*/
|
|
6
|
+
import type { MiddlewareHandler } from 'astro';
|
|
7
|
+
import { publishDue } from './editor.ts';
|
|
8
|
+
|
|
9
|
+
export const onRequest: MiddlewareHandler = async (context, next) => {
|
|
10
|
+
if (!context.isPrerendered) await publishDue(context.request, context.cache).catch(() => undefined);
|
|
11
|
+
return next();
|
|
12
|
+
};
|
package/routes/editor.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the editor's three routes share. Compiled with the site, like every file here, so it can
|
|
3
|
+
* read the settings the integration wrote and the site's own mailer.
|
|
4
|
+
*/
|
|
5
|
+
import { currentSite, indexPages, pagesOrigin, siteCacheTag, siteEditorHost, withEditor, type EditorHost, type SiteEditorSettings } from '@velocity-astro/cms-astro';
|
|
6
|
+
import images from 'virtual:velocity-cms/images';
|
|
7
|
+
import mailer from 'virtual:velocity-cms/mailer';
|
|
8
|
+
import options from 'virtual:velocity-cms/options';
|
|
9
|
+
|
|
10
|
+
const settings: SiteEditorSettings = { ...options.editor, dev: import.meta.env.DEV, mailer, images };
|
|
11
|
+
|
|
12
|
+
export const editor = (request: Request, answer: (host: EditorHost) => Response | Promise<Response>) =>
|
|
13
|
+
withEditor(request, settings, answer);
|
|
14
|
+
|
|
15
|
+
/** What a request can clear kept pages with. */
|
|
16
|
+
interface PageCache {
|
|
17
|
+
invalidate(options: { tags: string[] }): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Where the site reads its own pages from: never an address a request merely claims. `null` when it cannot tell. */
|
|
21
|
+
export const ownOrigin = (request: Request): string | null => pagesOrigin(request, settings);
|
|
22
|
+
|
|
23
|
+
/** A publish must be seen at once: drops the kept pages, then reads the changed ones for search. */
|
|
24
|
+
export async function showPublished(host: EditorHost, cache: PageCache, origin: string | null): Promise<void> {
|
|
25
|
+
const changed = host.takePublished();
|
|
26
|
+
if (!changed) return;
|
|
27
|
+
await cache.invalidate({ tags: [siteCacheTag()] });
|
|
28
|
+
if (origin === null) return;
|
|
29
|
+
await indexPages(origin, changed).catch((error: unknown) => console.error('[velocity-cms] Search was not updated.', error));
|
|
30
|
+
}
|
|
31
|
+
|
|
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
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Publishes what was set to go out by now, and shows it. A site whose editor is not set up has
|
|
37
|
+
* nothing scheduled, so that is passed over in silence.
|
|
38
|
+
*/
|
|
39
|
+
export async function publishDue(request: Request, cache: PageCache, options: { now?: boolean } = {}): Promise<void> {
|
|
40
|
+
const site = currentSite()?.id ?? '';
|
|
41
|
+
if (Date.now() - (notSetUpAt.get(site) ?? 0) < 30_000) return;
|
|
42
|
+
const host = await siteEditorHost(request, settings).catch(() => null);
|
|
43
|
+
if (!host) {
|
|
44
|
+
notSetUpAt.set(site, Date.now());
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
await host.publishDue(options);
|
|
48
|
+
await showPublished(host, cache, ownOrigin(request));
|
|
49
|
+
}
|