@velocity-astro/cms-astro 0.0.0-stage → 0.1.0-beta.2

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.
Files changed (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/bin/velocity-cms.mjs +6 -0
  4. package/dist/admin-files.d.ts +21 -0
  5. package/dist/admin-files.d.ts.map +1 -0
  6. package/dist/admin-files.js +77 -0
  7. package/dist/admin-files.js.map +1 -0
  8. package/dist/cli.d.ts +9 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +75 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/connection.d.ts +25 -0
  13. package/dist/connection.d.ts.map +1 -0
  14. package/dist/connection.js +62 -0
  15. package/dist/connection.js.map +1 -0
  16. package/dist/editor.d.ts +65 -0
  17. package/dist/editor.d.ts.map +1 -0
  18. package/dist/editor.js +186 -0
  19. package/dist/editor.js.map +1 -0
  20. package/dist/entry-page.d.ts +37 -0
  21. package/dist/entry-page.d.ts.map +1 -0
  22. package/dist/entry-page.js +56 -0
  23. package/dist/entry-page.js.map +1 -0
  24. package/dist/form-post.d.ts +106 -0
  25. package/dist/form-post.d.ts.map +1 -0
  26. package/dist/form-post.js +291 -0
  27. package/dist/form-post.js.map +1 -0
  28. package/dist/index.d.ts +25 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +25 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/init.d.ts +33 -0
  33. package/dist/init.d.ts.map +1 -0
  34. package/dist/init.js +125 -0
  35. package/dist/init.js.map +1 -0
  36. package/dist/integration.d.ts +63 -0
  37. package/dist/integration.d.ts.map +1 -0
  38. package/dist/integration.js +129 -0
  39. package/dist/integration.js.map +1 -0
  40. package/dist/link.d.ts +32 -0
  41. package/dist/link.d.ts.map +1 -0
  42. package/dist/link.js +76 -0
  43. package/dist/link.js.map +1 -0
  44. package/dist/live-loader.d.ts +40 -0
  45. package/dist/live-loader.d.ts.map +1 -0
  46. package/dist/live-loader.js +92 -0
  47. package/dist/live-loader.js.map +1 -0
  48. package/dist/live-pages.d.ts +69 -0
  49. package/dist/live-pages.d.ts.map +1 -0
  50. package/dist/live-pages.js +94 -0
  51. package/dist/live-pages.js.map +1 -0
  52. package/dist/loader.d.ts +22 -0
  53. package/dist/loader.d.ts.map +1 -0
  54. package/dist/loader.js +62 -0
  55. package/dist/loader.js.map +1 -0
  56. package/dist/media-store.d.ts +46 -0
  57. package/dist/media-store.d.ts.map +1 -0
  58. package/dist/media-store.js +154 -0
  59. package/dist/media-store.js.map +1 -0
  60. package/dist/menu.d.ts +51 -0
  61. package/dist/menu.d.ts.map +1 -0
  62. package/dist/menu.js +81 -0
  63. package/dist/menu.js.map +1 -0
  64. package/dist/page-head.d.ts +23 -0
  65. package/dist/page-head.d.ts.map +1 -0
  66. package/dist/page-head.js +66 -0
  67. package/dist/page-head.js.map +1 -0
  68. package/dist/preview.d.ts +60 -0
  69. package/dist/preview.d.ts.map +1 -0
  70. package/dist/preview.js +126 -0
  71. package/dist/preview.js.map +1 -0
  72. package/dist/resend-mailer.d.ts +46 -0
  73. package/dist/resend-mailer.d.ts.map +1 -0
  74. package/dist/resend-mailer.js +95 -0
  75. package/dist/resend-mailer.js.map +1 -0
  76. package/dist/secret.d.ts +8 -0
  77. package/dist/secret.d.ts.map +1 -0
  78. package/dist/secret.js +16 -0
  79. package/dist/secret.js.map +1 -0
  80. package/dist/site-editor.d.ts +41 -0
  81. package/dist/site-editor.d.ts.map +1 -0
  82. package/dist/site-editor.js +110 -0
  83. package/dist/site-editor.js.map +1 -0
  84. package/dist/site-forms.d.ts +43 -0
  85. package/dist/site-forms.d.ts.map +1 -0
  86. package/dist/site-forms.js +82 -0
  87. package/dist/site-forms.js.map +1 -0
  88. package/dist/site-images.d.ts +17 -0
  89. package/dist/site-images.d.ts.map +1 -0
  90. package/dist/site-images.js +22 -0
  91. package/dist/site-images.js.map +1 -0
  92. package/dist/site-media.d.ts +18 -0
  93. package/dist/site-media.d.ts.map +1 -0
  94. package/dist/site-media.js +43 -0
  95. package/dist/site-media.js.map +1 -0
  96. package/dist/site-plugins.d.ts +10 -0
  97. package/dist/site-plugins.d.ts.map +1 -0
  98. package/dist/site-plugins.js +23 -0
  99. package/dist/site-plugins.js.map +1 -0
  100. package/dist/site-search.d.ts +12 -0
  101. package/dist/site-search.d.ts.map +1 -0
  102. package/dist/site-search.js +79 -0
  103. package/dist/site-search.js.map +1 -0
  104. package/package.json +53 -3
  105. package/routes/admin.ts +10 -0
  106. package/routes/api.ts +15 -0
  107. package/routes/auth.ts +10 -0
  108. package/routes/due.ts +12 -0
  109. package/routes/editor.ts +48 -0
  110. package/routes/form-client.js.ts +105 -0
  111. package/routes/media.ts +10 -0
  112. package/routes/pages.ts +13 -0
  113. package/routes/plugins.ts +10 -0
  114. package/routes/preview-client.js.ts +63 -0
  115. package/routes/published.ts +29 -0
  116. package/routes/schedule.ts +20 -0
  117. package/routes/search-client.js.ts +33 -0
  118. package/routes/search.json.ts +10 -0
  119. package/routes/share-image.png.ts +33 -0
  120. package/routes/sitemap-live.xml.ts +13 -0
  121. package/routes/submit.ts +22 -0
package/dist/secret.js ADDED
@@ -0,0 +1,16 @@
1
+ import { timingSafeEqual } from 'node:crypto';
2
+ /**
3
+ * The site's one secret, from `VELOCITY_CMS_SECRET`. It signs preview links and, until the editor
4
+ * exists, proves that a publish notice comes from the site's owner. Without it both are off.
5
+ */
6
+ export const siteSecret = () => process.env.VELOCITY_CMS_SECRET || undefined;
7
+ /** Whether the request carries the secret as a bearer token. */
8
+ export function hasSiteSecret(request) {
9
+ const secret = siteSecret();
10
+ const given = request.headers.get('authorization')?.match(/^Bearer (.+)$/)?.[1];
11
+ if (!secret || !given)
12
+ return false;
13
+ const [a, b] = [Buffer.from(secret), Buffer.from(given)];
14
+ return a.length === b.length && timingSafeEqual(a, b);
15
+ }
16
+ //# sourceMappingURL=secret.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secret.js","sourceRoot":"","sources":["../src/secret.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAuB,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,SAAS,CAAC;AAEjG,gEAAgE;AAChE,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAChF,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACpC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACzD,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { type Mailer } from '@velocity-astro/cms-auth';
2
+ import type { ImageLibrary } from '@velocity-astro/cms-core';
3
+ import { EditorHost } from './editor.js';
4
+ /** What the integration tells the editor's routes about the site. */
5
+ export interface SiteEditorSettings {
6
+ /** `site` from the Astro config, if it is set. */
7
+ readonly site: string | undefined;
8
+ /** Whether this is `astro dev`. */
9
+ readonly dev: boolean;
10
+ readonly siteName: string;
11
+ readonly adminPath: string;
12
+ /** How sign-in links are delivered. Without one they are printed to the server's log. */
13
+ readonly mailer?: Mailer | undefined;
14
+ /** The site's images, for image fields. Without them there are none to choose from. */
15
+ readonly images?: ImageLibrary | undefined;
16
+ }
17
+ /** The editor cannot be served until the site's settings are completed. The message says how. */
18
+ export declare class EditorNotSetUpError extends Error {
19
+ }
20
+ /**
21
+ * The address sign-in links and passkeys are made for. It is never taken from a request on a
22
+ * deployed site: whoever sends a request chooses its `Host` header, and a link built from it
23
+ * would carry a real person's sign-in to an address of the sender's choosing.
24
+ */
25
+ export declare function editorOrigin(request: Request, settings: Pick<SiteEditorSettings, 'site' | 'dev'>): string;
26
+ /**
27
+ * The address the site reads its own pages from, for search and share images, or `null` when it
28
+ * cannot tell. The request's own address is used only when the site is known by it: whoever
29
+ * sends a request chooses its `Host` header, and a page read from an address of their choosing
30
+ * would be someone else's page, or a machine beside the site.
31
+ */
32
+ export declare function pagesOrigin(request: Request, settings: Pick<SiteEditorSettings, 'site' | 'dev'>): string | null;
33
+ /** The site's one editor host for the life of the server, made on first use. */
34
+ export declare function siteEditorHost(request: Request, settings: SiteEditorSettings): Promise<EditorHost>;
35
+ /**
36
+ * Hands a request to the site's editor host. When the editor is not set up yet, answers with
37
+ * what is missing instead, in the shape the API's errors have, so the person setting the site
38
+ * up reads it in the browser and in the log.
39
+ */
40
+ export declare function withEditor(request: Request, settings: SiteEditorSettings, answer: (host: EditorHost) => Response | Promise<Response>): Promise<Response>;
41
+ //# sourceMappingURL=site-editor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-editor.d.ts","sourceRoot":"","sources":["../src/site-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAa,MAAM,aAAa,CAAC;AAIpD,qEAAqE;AACrE,MAAM,WAAW,kBAAkB;IACjC,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,mCAAmC;IACnC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,yFAAyF;IACzF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,uFAAuF;IACvF,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;CAC5C;AAED,iGAAiG;AACjG,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,KAAK,CAAC,GAAG,MAAM,CAYzG;AAWD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,KAAK,CAAC,GAAG,MAAM,GAAG,IAAI,CAW/G;AA6BD,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CAUlG;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,kBAAkB,EAC5B,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GACzD,OAAO,CAAC,QAAQ,CAAC,CAUnB"}
@@ -0,0 +1,110 @@
1
+ import { AuthSetupError } from '@velocity-astro/cms-auth';
2
+ import { sharedConnection } from './connection.js';
3
+ import { EditorHost, LogMailer } from './editor.js';
4
+ import { mailerFromEnv } from './resend-mailer.js';
5
+ import { siteSecret } from './secret.js';
6
+ /** The editor cannot be served until the site's settings are completed. The message says how. */
7
+ export class EditorNotSetUpError extends Error {
8
+ }
9
+ /**
10
+ * The address sign-in links and passkeys are made for. It is never taken from a request on a
11
+ * deployed site: whoever sends a request chooses its `Host` header, and a link built from it
12
+ * would carry a real person's sign-in to an address of the sender's choosing.
13
+ */
14
+ export function editorOrigin(request, settings) {
15
+ const configured = process.env.VELOCITY_CMS_ORIGIN || (settings.dev ? new URL(request.url).origin : settings.site);
16
+ if (!configured) {
17
+ throw new EditorNotSetUpError('The editor needs to know the site\'s address. Set `site` in astro.config.mjs, or the VELOCITY_CMS_ORIGIN environment variable.');
18
+ }
19
+ try {
20
+ return new URL(configured).origin;
21
+ }
22
+ catch {
23
+ throw new EditorNotSetUpError(`"${configured}" is not an address. Give the site's own, such as https://example.com.`);
24
+ }
25
+ }
26
+ /** The names a host gives a deployment itself. A visitor cannot set them. */
27
+ const PLATFORM_HOSTS = ['VERCEL_URL', 'VERCEL_BRANCH_URL', 'VERCEL_PROJECT_PRODUCTION_URL', 'URL', 'DEPLOY_PRIME_URL', 'DEPLOY_URL'];
28
+ const hostOf = (address) => {
29
+ if (!address)
30
+ return null;
31
+ const full = address.includes('://') ? address : `https://${address}`;
32
+ return URL.canParse(full) ? new URL(full).host : null;
33
+ };
34
+ /**
35
+ * The address the site reads its own pages from, for search and share images, or `null` when it
36
+ * cannot tell. The request's own address is used only when the site is known by it: whoever
37
+ * sends a request chooses its `Host` header, and a page read from an address of their choosing
38
+ * would be someone else's page, or a machine beside the site.
39
+ */
40
+ export function pagesOrigin(request, settings) {
41
+ const asked = new URL(request.url);
42
+ if (settings.dev)
43
+ return asked.origin;
44
+ const configured = [process.env.VELOCITY_CMS_ORIGIN, settings.site].map(hostOf);
45
+ const known = [...configured, ...PLATFORM_HOSTS.map((name) => hostOf(process.env[name]))];
46
+ if (known.includes(asked.host))
47
+ return asked.origin;
48
+ try {
49
+ return editorOrigin(request, settings);
50
+ }
51
+ catch {
52
+ return null;
53
+ }
54
+ }
55
+ const hosts = new Map();
56
+ async function createHost(origin, settings) {
57
+ const secret = siteSecret();
58
+ if (!secret) {
59
+ throw new EditorNotSetUpError('The editor is off because VELOCITY_CMS_SECRET is not set. Set it to at least 32 random characters, for example from `openssl rand -base64 32`.');
60
+ }
61
+ try {
62
+ return new EditorHost({
63
+ connection: await sharedConnection({}),
64
+ secret,
65
+ origin,
66
+ siteName: settings.siteName,
67
+ adminPath: settings.adminPath,
68
+ // The site's own mailer first, then Resend from its settings, then the server's log.
69
+ mailer: settings.mailer ?? mailerFromEnv() ?? new LogMailer(),
70
+ ...(settings.images && { images: settings.images }),
71
+ onFault: (error) => console.error('[velocity-cms]', error),
72
+ });
73
+ }
74
+ catch (error) {
75
+ if (error instanceof AuthSetupError)
76
+ throw new EditorNotSetUpError(error.message);
77
+ throw error;
78
+ }
79
+ }
80
+ /** The site's one editor host for the life of the server, made on first use. */
81
+ export function siteEditorHost(request, settings) {
82
+ const origin = editorOrigin(request, settings);
83
+ let host = hosts.get(origin);
84
+ if (!host) {
85
+ host = createHost(origin, settings);
86
+ hosts.set(origin, host);
87
+ // A failed start must not be remembered: the next request tries again with the settings fixed.
88
+ host.catch(() => hosts.delete(origin));
89
+ }
90
+ return host;
91
+ }
92
+ /**
93
+ * Hands a request to the site's editor host. When the editor is not set up yet, answers with
94
+ * what is missing instead, in the shape the API's errors have, so the person setting the site
95
+ * up reads it in the browser and in the log.
96
+ */
97
+ export async function withEditor(request, settings, answer) {
98
+ let host;
99
+ try {
100
+ host = await siteEditorHost(request, settings);
101
+ }
102
+ catch (error) {
103
+ if (!(error instanceof EditorNotSetUpError))
104
+ throw error;
105
+ console.warn(`[velocity-cms] ${error.message}`);
106
+ return Response.json({ error: { code: 'not_set_up', message: error.message } }, { status: 503, headers: { 'cache-control': 'no-store' } });
107
+ }
108
+ return answer(host);
109
+ }
110
+ //# sourceMappingURL=site-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-editor.js","sourceRoot":"","sources":["../src/site-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;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,QAAQ,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,mBAAmB,CAAC;YAAE,MAAM,KAAK,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,kBAAkB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAChD,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;IAC7I,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC"}
@@ -0,0 +1,43 @@
1
+ import type { PublicForm } from '@velocity-astro/cms-core';
2
+ import { FormPosts } from './form-post.js';
3
+ import { type DrawnPage } from './page-head.js';
4
+ import { type SiteEditorSettings } from './site-editor.js';
5
+ /** The site's one taker of form posts for the life of the server, made on first use. */
6
+ export declare function siteFormPosts(settings: SiteEditorSettings): Promise<FormPosts>;
7
+ /** A form as a page draws it, with where it posts and the hidden fields it sends along. */
8
+ export interface SiteForm extends PublicForm {
9
+ /** Where the form posts: the `action` of its `<form method="post">`. */
10
+ readonly action: string;
11
+ /** Hidden fields to write into the form as they are: name and value. */
12
+ readonly hidden: Readonly<Record<string, string>>;
13
+ /**
14
+ * The name of a field to draw empty and out of sight (and out of reach of the keyboard and of
15
+ * screen readers). A person leaves it alone; a script that fills in everything gives itself away.
16
+ */
17
+ readonly trap: string;
18
+ }
19
+ /** The address of the script that sends a form without leaving its page (`data-cms-form`). */
20
+ export declare const FORM_SCRIPT = "/cms-form.js";
21
+ /** Which form: its key, as a template names one, or its id, as a field of type `form` holds one. */
22
+ export type FormChoice = string | {
23
+ readonly id: string;
24
+ };
25
+ /** What a page may say about the form it draws. */
26
+ export interface SiteFormOptions {
27
+ /**
28
+ * The published entry the form is about, when the page knows better than its address does: a
29
+ * listing's page says the listing, so what is sent is kept as being about it, and starts a
30
+ * deal about it when the form asks for that. `type` is the content type's key.
31
+ */
32
+ readonly about?: {
33
+ readonly type: string;
34
+ readonly slug: string;
35
+ readonly locale?: string;
36
+ };
37
+ }
38
+ /**
39
+ * A form of the CMS for the page being drawn, or `null` when there is none open under that key
40
+ * or id, so the template leaves it out. It never throws: a page is not lost over its form.
41
+ */
42
+ export declare function siteForm(page: DrawnPage, choice: FormChoice, options?: SiteFormOptions): Promise<SiteForm | null>;
43
+ //# sourceMappingURL=site-forms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-forms.d.ts","sourceRoot":"","sources":["../src/site-forms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAG3D,OAAO,EAA2F,SAAS,EAA2C,MAAM,gBAAgB,CAAC;AAC7K,OAAO,EAAU,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGxD,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAgBzE,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,SAAS,CAAC,CAwB9E;AAED,2FAA2F;AAC3F,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,8FAA8F;AAC9F,eAAO,MAAM,WAAW,iBAAiB,CAAC;AAE1C,oGAAoG;AACpG,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7F;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CA6B3H"}
@@ -0,0 +1,82 @@
1
+ import { isLiveType } from '@velocity-astro/cms-core';
2
+ import { sharedConnection, SITE } from './connection.js';
3
+ import { FORM_ABOUT_FIELD, FORM_LOCALE_FIELD, FORM_PAGE_FIELD, FORM_TOKEN_FIELD, FORM_TRAP_FIELD, FormPosts, aboutMark, formToken } from './form-post.js';
4
+ import { pageAt } from './page-head.js';
5
+ import { mailerFromEnv } from './resend-mailer.js';
6
+ import { siteSecret } from './secret.js';
7
+ import { editorOrigin } from './site-editor.js';
8
+ let posts;
9
+ const takesNotices = (mailer) => typeof mailer === 'object' && mailer !== null && typeof mailer.sendSubmissionNotice === 'function';
10
+ /** The site's address for forms. A site that has not said its address yet is taken at the request's word. */
11
+ function originOf(request, settings) {
12
+ try {
13
+ return editorOrigin(request, settings);
14
+ }
15
+ catch {
16
+ return new URL(request.url).origin;
17
+ }
18
+ }
19
+ /** The site's one taker of form posts for the life of the server, made on first use. */
20
+ export function siteFormPosts(settings) {
21
+ if (!posts) {
22
+ const made = sharedConnection({}).then(({ cms }) => new FormPosts({
23
+ cms,
24
+ origin: (request) => originOf(request, settings),
25
+ siteName: settings.siteName,
26
+ secret: siteSecret(),
27
+ entryAt: async (path) => {
28
+ const { type, entry } = await pageAt(cms, await cms.schema.list(), path);
29
+ return type && entry ? { typeId: type.id, entry: entry.translationGroup } : undefined;
30
+ },
31
+ // The site's own mailer when it sends notices, then Resend from its settings, then nobody.
32
+ mailer: takesNotices(settings.mailer) ? settings.mailer : mailerFromEnv(),
33
+ onFault: (error) => console.error('[velocity-cms]', error instanceof Error ? error.message : error),
34
+ }));
35
+ posts = made;
36
+ made.catch(() => {
37
+ if (posts === made)
38
+ posts = undefined;
39
+ });
40
+ }
41
+ return posts;
42
+ }
43
+ /** The address of the script that sends a form without leaving its page (`data-cms-form`). */
44
+ export const FORM_SCRIPT = '/cms-form.js';
45
+ /**
46
+ * A form of the CMS for the page being drawn, or `null` when there is none open under that key
47
+ * or id, so the template leaves it out. It never throws: a page is not lost over its form.
48
+ */
49
+ export async function siteForm(page, choice, options = {}) {
50
+ try {
51
+ const { cms } = await sharedConnection({});
52
+ const form = typeof choice === 'string' ? await cms.forms.forSite(choice) : await cms.forms.forSiteById(choice.id);
53
+ if (!form)
54
+ return null;
55
+ const token = await formToken(siteSecret(), form.key);
56
+ const locale = page.currentLocale;
57
+ let about;
58
+ if (options.about) {
59
+ // An entry that is not there, or not published, leaves the form as one about nothing.
60
+ const type = await cms.schema.getByKey(options.about.type).catch(() => undefined);
61
+ const entry = type && isLiveType(type) ? await cms.content.findBySlug(SITE, { typeId: type.id, locale: options.about.locale ?? locale ?? 'en', slug: options.about.slug, version: 'published' }) : null;
62
+ if (type && entry)
63
+ about = await aboutMark(siteSecret(), form.key, { typeId: type.id, entry: entry.translationGroup });
64
+ }
65
+ return {
66
+ ...form,
67
+ action: `/api/cms/submit/${encodeURIComponent(form.key)}`,
68
+ hidden: {
69
+ [FORM_PAGE_FIELD]: page.url.pathname,
70
+ ...(locale !== undefined && { [FORM_LOCALE_FIELD]: locale }),
71
+ ...(token !== undefined && { [FORM_TOKEN_FIELD]: token }),
72
+ ...(about !== undefined && { [FORM_ABOUT_FIELD]: about }),
73
+ },
74
+ trap: FORM_TRAP_FIELD,
75
+ };
76
+ }
77
+ catch (error) {
78
+ console.error('[velocity-cms] A form could not be read.', error instanceof Error ? error.message : error);
79
+ return null;
80
+ }
81
+ }
82
+ //# sourceMappingURL=site-forms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-forms.js","sourceRoot":"","sources":["../src/site-forms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAqB,MAAM,gBAAgB,CAAC;AAC7K,OAAO,EAAE,MAAM,EAAkB,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAA2B,MAAM,kBAAkB,CAAC;AAEzE,IAAI,KAAqC,CAAC;AAE1C,MAAM,YAAY,GAAG,CAAC,MAAe,EAA0B,EAAE,CAC/D,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,OAAQ,MAA6C,CAAC,oBAAoB,KAAK,UAAU,CAAC;AAE7I,6GAA6G;AAC7G,SAAS,QAAQ,CAAC,OAAgB,EAAE,QAAkD;IACpF,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,CAAC;AACH,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,aAAa,CAAC,QAA4B;IACxD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,GAAG,gBAAgB,CAAC,EAAE,CAAC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AAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;QACzH,CAAC;QACD,OAAO;YACL,GAAG,IAAI;YACP,MAAM,EAAE,mBAAmB,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YACzD,MAAM,EAAE;gBACN,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ;gBACpC,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;gBAC5D,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC;gBACzD,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC;aAC1D;YACD,IAAI,EAAE,eAAe;SACtB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC1G,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { ImageLibrary } from '@velocity-astro/cms-core';
2
+ /** An image file as the site's bundler describes it. */
3
+ export interface ImageFile {
4
+ readonly src: string;
5
+ readonly width: number;
6
+ readonly height: number;
7
+ }
8
+ /**
9
+ * The images in a folder of the project, for image fields to choose from. An image is called by
10
+ * its file name without the ending, which is how a template's pages look their images up.
11
+ *
12
+ * @param files The folder's images by path, as `import.meta.glob` gives them.
13
+ * @param small Makes the address of a small copy, for the editor to show. When it fails for an
14
+ * image, the editor loads the image itself.
15
+ */
16
+ export declare function folderImages(files: Readonly<Record<string, ImageFile>>, small?: (file: ImageFile) => Promise<string>): ImageLibrary;
17
+ //# sourceMappingURL=site-images.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-images.d.ts","sourceRoot":"","sources":["../src/site-images.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,0BAA0B,CAAC;AAExE,wDAAwD;AACxD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAKD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,YAAY,CAanI"}
@@ -0,0 +1,22 @@
1
+ /** The file's name without its folder or its ending: `/src/assets/photos/porch.jpg` is `porch`. */
2
+ const nameOf = (file) => file.slice(file.lastIndexOf('/') + 1).replace(/\.[^.]+$/, '');
3
+ /**
4
+ * The images in a folder of the project, for image fields to choose from. An image is called by
5
+ * its file name without the ending, which is how a template's pages look their images up.
6
+ *
7
+ * @param files The folder's images by path, as `import.meta.glob` gives them.
8
+ * @param small Makes the address of a small copy, for the editor to show. When it fails for an
9
+ * image, the editor loads the image itself.
10
+ */
11
+ export function folderImages(files, small) {
12
+ let listed;
13
+ const list = () => Promise.all(Object.entries(files).map(async ([path, file]) => ({
14
+ name: nameOf(path),
15
+ url: small ? await small(file).catch(() => file.src) : file.src,
16
+ width: file.width,
17
+ height: file.height,
18
+ })));
19
+ // The folder changes only with a deploy, so it is read once.
20
+ return { list: () => (listed ??= list()) };
21
+ }
22
+ //# sourceMappingURL=site-images.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-images.js","sourceRoot":"","sources":["../src/site-images.ts"],"names":[],"mappings":"AASA,mGAAmG;AACnG,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAEvG;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,KAA0C,EAAE,KAA4C;IACnH,IAAI,MAAiD,CAAC;IACtD,MAAM,IAAI,GAAG,GAAkC,EAAE,CAC/C,OAAO,CAAC,GAAG,CACT,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACjD,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;QAClB,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG;QAC/D,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CAAC,CACJ,CAAC;IACJ,6DAA6D;IAC7D,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { type SiteImage } from '@velocity-astro/cms-core';
2
+ /**
3
+ * The answer to a request for an uploaded file. A file never changes once it is kept and its
4
+ * name is never given to another, so browsers and the CDN may keep it for good.
5
+ */
6
+ export declare function uploadedFile(key: string): Promise<Response>;
7
+ /**
8
+ * Reads the uploaded images again. The site's middleware does this before each page is
9
+ * rendered, so a page never misses an image that was uploaded a moment ago, whichever server
10
+ * renders it.
11
+ */
12
+ export declare function refreshUploadedImages(): Promise<void>;
13
+ /**
14
+ * The uploaded image with this name, as it was when the page began to render: its address on
15
+ * this site and its size. `undefined` when no upload has the name.
16
+ */
17
+ export declare const uploadedImage: (name: string) => SiteImage | undefined;
18
+ //# sourceMappingURL=site-media.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-media.d.ts","sourceRoot":"","sources":["../src/site-media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGzE;;;GAGG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkBjE;AAID;;;;GAIG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAG3D;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,SAAS,GAAG,SAA6B,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { NotFoundError } from '@velocity-astro/cms-core';
2
+ import { sharedConnection, SITE } from './connection.js';
3
+ /**
4
+ * The answer to a request for an uploaded file. A file never changes once it is kept and its
5
+ * name is never given to another, so browsers and the CDN may keep it for good.
6
+ */
7
+ export async function uploadedFile(key) {
8
+ const { cms } = await sharedConnection({});
9
+ try {
10
+ const file = await cms.media.file(key);
11
+ return new Response(file.bytes, {
12
+ headers: {
13
+ 'content-type': file.contentType,
14
+ 'content-length': String(file.bytes.length),
15
+ 'cache-control': 'public, max-age=31536000, immutable',
16
+ // The file is shown as the image it was checked to be, and as nothing else.
17
+ 'x-content-type-options': 'nosniff',
18
+ 'content-security-policy': "default-src 'none'",
19
+ },
20
+ });
21
+ }
22
+ catch (error) {
23
+ if (error instanceof NotFoundError)
24
+ return new Response(null, { status: 404, headers: { 'cache-control': 'no-store' } });
25
+ throw error;
26
+ }
27
+ }
28
+ let latest = new Map();
29
+ /**
30
+ * Reads the uploaded images again. The site's middleware does this before each page is
31
+ * rendered, so a page never misses an image that was uploaded a moment ago, whichever server
32
+ * renders it.
33
+ */
34
+ export async function refreshUploadedImages() {
35
+ const { cms } = await sharedConnection({});
36
+ latest = new Map((await cms.media.uploads(SITE)).map((image) => [image.name, image]));
37
+ }
38
+ /**
39
+ * The uploaded image with this name, as it was when the page began to render: its address on
40
+ * this site and its size. `undefined` when no upload has the name.
41
+ */
42
+ export const uploadedImage = (name) => latest.get(name);
43
+ //# 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;AAEzD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAW;IAC5C,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC3C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvC,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,IAAI,MAAM,GAAmC,IAAI,GAAG,EAAE,CAAC;AAEvD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC3C,MAAM,GAAG,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;AACxF,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAyB,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,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,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