@seamlet/astro 0.9.0 → 0.10.0

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/README.md CHANGED
@@ -10,7 +10,19 @@ Connects an [Astro](https://astro.build) site to the Seamlet CMS ([source](https
10
10
  npm install @seamlet/astro
11
11
  ```
12
12
 
13
- 2. Describe the content with a schema, and mark the elements that show it:
13
+ 2. Name the site in `seamlet.json` at its root: its id in the CMS (lower-case letters, digits and single hyphens; its address there, `/sites/<id>`, the name of its content and the host of its preview), how the CMS names it, and the CMS it belongs to. The CMS reads the same file from the site's repository, so the id is written once.
14
+
15
+ ```json
16
+ {
17
+ "id": "zerno",
18
+ "title": "Кофейня «Зерно»",
19
+ "cms": "https://cms.seamlet.ru"
20
+ }
21
+ ```
22
+
23
+ The environment variable `CMS_ORIGIN` takes the place of `cms` when it is set: a build for a CMS in development, or the CMS's own builder. A build without the file, or with a field it cannot read, stops and says which field to fix.
24
+
25
+ 3. Describe the content with a schema, and mark the elements that show it:
14
26
 
15
27
  ```ts
16
28
  // src/schema.ts
@@ -46,7 +58,7 @@ Connects an [Astro](https://astro.build) site to the Seamlet CMS ([source](https
46
58
  <h1 {...edit("title")}>{content.title}</h1>
47
59
  ```
48
60
 
49
- 3. Describe the site for the CMS: its address and name there, its schema, the content it starts with, and its pages, each with the name the editor gives it and the component that renders it (it takes the content as its `content` prop). The home page `/` comes first; `searchTexts` names where the content holds a page's title and description for search engines, a group of a `title` and a `description` text (`seoFields`).
61
+ 4. Describe the site for the CMS in `src/seamlet.ts`: its schema, the content it starts with, and its pages, each with the name the editor gives it and the component that renders it (it takes the content as its `content` prop). The home page `/` comes first; `searchTexts` names where the content holds a page's title and description for search engines, a group of a `title` and a `description` text (`seoFields`).
50
62
 
51
63
  ```ts
52
64
  // src/seamlet.ts
@@ -56,8 +68,6 @@ Connects an [Astro](https://astro.build) site to the Seamlet CMS ([source](https
56
68
  import { schema } from "./schema";
57
69
 
58
70
  export default defineSeamletSite({
59
- id: "zerno",
60
- title: "Кофейня «Зерно»",
61
71
  schema,
62
72
  initialContent,
63
73
  pages: {
@@ -68,20 +78,18 @@ Connects an [Astro](https://astro.build) site to the Seamlet CMS ([source](https
68
78
 
69
79
  The CMS takes all of it from the site itself, so connecting a site, or changing its schema, needs no change of the CMS.
70
80
 
71
- 4. Add the integration:
81
+ 5. Add the integration; it reads `seamlet.json` and `src/seamlet.ts` itself:
72
82
 
73
83
  ```js
74
84
  // astro.config.mjs
75
85
  import seamlet from "@seamlet/astro";
76
86
 
77
87
  export default defineConfig({
78
- integrations: [
79
- seamlet({ cms: "https://cms.example.com", site: "./src/seamlet.ts" }),
80
- ],
88
+ integrations: [seamlet()],
81
89
  });
82
90
  ```
83
91
 
84
- The site's pages take their published content with `site.loadPublishedContent()`: at build time for a static site, on request otherwise. A module that needs the content without importing every page takes it with `loadPublishedContent(id, schema)` of `@seamlet/astro/site`.
92
+ The site's pages take their published content with `site.loadPublishedContent()`: at build time for a static site, on request otherwise. A module that needs the content without importing every page takes it with `loadPublishedContent(schema)` of `@seamlet/astro/site`.
85
93
 
86
94
  ## Fields
87
95
 
@@ -142,8 +150,6 @@ const MENU_FILES = import.meta.glob<{ default: ImageMetadata }>(
142
150
  );
143
151
 
144
152
  export default defineSeamletSite({
145
- id: "zerno",
146
- title: "Кофейня «Зерно»",
147
153
  schema,
148
154
  initialContent,
149
155
  pages: { "/": { title: "Главная", component: HomePage } },
@@ -228,7 +234,7 @@ What was opened stays open while the page is rendered anew after every edit.
228
234
 
229
235
  - `/preview` and `/preview/<page>`: the preview the CMS's editor frames. `GET` shows the published content; `POST` with the content as JSON shows that content without saving it, which is how the editor shows every edit at once. Only the CMS may frame it (`Content-Security-Policy: frame-ancestors`), and it is never indexed or cached.
230
236
  - The bridge on the preview: it tells the editor where the marked elements are and what a person does on the page, and types texts in place, formatted ones too.
231
- - `/seamlet/site.json`: what the site tells the CMS about itself (`SITE_DESCRIPTION_PATH`): its name, its schema, the content it starts with and its pages. The CMS reads it with `readSiteDescription` whenever the site is opened in its editor.
237
+ - `/seamlet/site.json`: what the site tells the CMS about itself (`SITE_DESCRIPTION_PATH`): its id and name from `seamlet.json`, its schema, the content it starts with and its pages. The CMS reads it with `readSiteDescription` whenever the site is opened in its editor.
232
238
  - `/seamlet-photos/<address>`: the site's own photo at an address its content gives it, found by `photos` of `defineSeamletSite`, for the CMS's editor.
233
239
  - `/media/<site>/<file>`: the photos uploaded in the CMS, taken from it on request; a static build copies every uploaded photo its built pages refer to next to them, so a static host serves them too.
234
240
 
package/dist/bridge.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  shortcutOf,
19
19
  toggleList,
20
20
  toggleMark
21
- } from "./chunk-UBBVOSON.js";
21
+ } from "./chunk-2E7VDSUK.js";
22
22
  import {
23
23
  FIELD_PATH_ATTRIBUTE,
24
24
  REVEALED_ATTRIBUTE,
@@ -27,7 +27,7 @@ import {
27
27
  asOneParagraph,
28
28
  readRichText,
29
29
  resolveFieldPath
30
- } from "./chunk-NFUGV7JJ.js";
30
+ } from "./chunk-DRDPKFHZ.js";
31
31
 
32
32
  // src/bridge/typed-fields.ts
33
33
  function typedKindAt(schema, path) {
@@ -3,7 +3,7 @@ import {
3
3
  normalizedLine,
4
4
  readRichText,
5
5
  resolveFieldPath
6
- } from "./chunk-NFUGV7JJ.js";
6
+ } from "./chunk-DRDPKFHZ.js";
7
7
 
8
8
  // src/bridge/editor-shortcuts.ts
9
9
  function shortcutOf(event) {
@@ -917,16 +917,54 @@ function isCount(value) {
917
917
  return isNumber(value) && Number.isInteger(value) && value >= 0;
918
918
  }
919
919
 
920
+ // src/schema/site-config.ts
921
+ var SITE_CONFIG_FILE = "seamlet.json";
922
+ var SITE_ID = /^[a-z0-9]+(-[a-z0-9]+)*$/u;
923
+ var LONGEST_SITE_ID = 63;
924
+ var WEB_PROTOCOLS = /* @__PURE__ */ new Set(["https:", "http:"]);
925
+ var SITE_CONFIG_FIELDS = ["id", "title", "cms"];
926
+ function isSiteId(value) {
927
+ return typeof value === "string" && value.length <= LONGEST_SITE_ID && SITE_ID.test(value);
928
+ }
929
+ function readSiteConfig(input) {
930
+ const fields = isRecord3(input) ? input : {};
931
+ const { id, title } = fields;
932
+ const cms = originOf(fields["cms"]);
933
+ const hasId = isSiteId(id);
934
+ const hasTitle = isText(title);
935
+ const hasCms = cms !== void 0;
936
+ if (hasId && hasTitle && hasCms) {
937
+ return { status: "read", config: { id, title: title.trim(), cms } };
938
+ }
939
+ const validity = {
940
+ id: hasId,
941
+ title: hasTitle,
942
+ cms: hasCms
943
+ };
944
+ const invalidFields = SITE_CONFIG_FIELDS.filter((field) => !validity[field]);
945
+ return { status: "invalid", invalidFields };
946
+ }
947
+ function originOf(value) {
948
+ if (typeof value !== "string" || !URL.canParse(value)) return void 0;
949
+ const url2 = new URL(value);
950
+ return WEB_PROTOCOLS.has(url2.protocol) ? url2.origin : void 0;
951
+ }
952
+ function isText(value) {
953
+ return typeof value === "string" && value.trim() !== "";
954
+ }
955
+ function isRecord3(value) {
956
+ return typeof value === "object" && value !== null && !Array.isArray(value);
957
+ }
958
+
920
959
  // src/schema/site-description.ts
921
960
  var SITE_DESCRIPTION_PATH = "/seamlet/site.json";
922
- var SITE_ID = /^[a-z0-9]+(-[a-z0-9]+)*$/u;
923
961
  var PAGE_PATH = /^(\/[a-z0-9][a-z0-9-]*)+$/u;
924
962
  var HOME_PAGE_PATH = "/";
925
963
  function readSiteDescription(input) {
926
- if (!isRecord3(input)) return void 0;
964
+ if (!isRecord4(input)) return void 0;
927
965
  const { id, title } = input;
928
966
  const schema = readFields(input["schema"]);
929
- const isNamed = typeof id === "string" && SITE_ID.test(id) && isText(title);
967
+ const isNamed = isSiteId(id) && isText2(title);
930
968
  if (!isNamed || schema === void 0) return void 0;
931
969
  const initial = parseContent(schema, input["initialContent"]);
932
970
  const pages = readPages(schema, input["pages"]);
@@ -950,18 +988,18 @@ function readPages(schema, input) {
950
988
  return isSound ? [first, ...rest] : void 0;
951
989
  }
952
990
  function readPage(schema, input) {
953
- if (!isRecord3(input)) return void 0;
991
+ if (!isRecord4(input)) return void 0;
954
992
  const { path, title, searchTexts } = input;
955
993
  const isPath = typeof path === "string" && (path === HOME_PAGE_PATH || PAGE_PATH.test(path));
956
- if (!isPath || !isText(title)) return void 0;
994
+ if (!isPath || !isText2(title)) return void 0;
957
995
  if (searchTexts === void 0) return { path, title };
958
996
  const isSearchTexts = typeof searchTexts === "string" && isSearchTextsGroup(schema, searchTexts);
959
997
  return isSearchTexts ? { path, title, searchTexts } : void 0;
960
998
  }
961
- function isRecord3(value) {
999
+ function isRecord4(value) {
962
1000
  return typeof value === "object" && value !== null && !Array.isArray(value);
963
1001
  }
964
- function isText(value) {
1002
+ function isText2(value) {
965
1003
  return typeof value === "string" && value.trim() !== "";
966
1004
  }
967
1005
 
@@ -1012,6 +1050,9 @@ export {
1012
1050
  WEEKDAYS,
1013
1051
  openingHoursField,
1014
1052
  readFields,
1053
+ SITE_CONFIG_FILE,
1054
+ isSiteId,
1055
+ readSiteConfig,
1015
1056
  SITE_DESCRIPTION_PATH,
1016
1057
  readSiteDescription,
1017
1058
  isSearchTextsGroup
package/dist/index.d.ts CHANGED
@@ -1,11 +1,5 @@
1
1
  import { AstroIntegration } from 'astro';
2
2
 
3
- interface SeamletOptions {
4
- /** The address of the CMS, such as `https://cms.example.com`. */
5
- readonly cms: string;
6
- /** The module of the site, relative to the project: `defineSeamletSite(…)` as its default export. */
7
- readonly site: string;
8
- }
9
- declare function seamlet(options: SeamletOptions): AstroIntegration;
3
+ declare function seamlet(): AstroIntegration;
10
4
 
11
- export { type SeamletOptions, seamlet as default };
5
+ export { seamlet as default };
package/dist/index.js CHANGED
@@ -2,14 +2,17 @@ import {
2
2
  OWN_PHOTOS_PATH
3
3
  } from "./chunk-3BS5CE26.js";
4
4
  import {
5
- SITE_DESCRIPTION_PATH
6
- } from "./chunk-NFUGV7JJ.js";
5
+ SITE_CONFIG_FILE,
6
+ SITE_DESCRIPTION_PATH,
7
+ readSiteConfig
8
+ } from "./chunk-DRDPKFHZ.js";
7
9
  import {
8
10
  isUploadedPhoto
9
11
  } from "./chunk-P2OQOZBC.js";
10
12
 
11
13
  // src/index.ts
12
- import { fileURLToPath } from "url";
14
+ import process from "process";
15
+ import { fileURLToPath as fileURLToPath2 } from "url";
13
16
 
14
17
  // src/uploaded-photos.ts
15
18
  import { mkdir, readdir, readFile, writeFile } from "fs/promises";
@@ -53,22 +56,78 @@ async function htmlFilesIn(directory) {
53
56
  return entries.filter((entry) => entry.isFile() && entry.name.endsWith(HTML_EXTENSION)).map((entry) => join(entry.parentPath, entry.name));
54
57
  }
55
58
 
59
+ // src/site-config-file.ts
60
+ import { readFile as readFile2 } from "fs/promises";
61
+ import { fileURLToPath } from "url";
62
+ var FIELD_RULES = {
63
+ id: "the site's id in the CMS: lower-case letters, digits and single hyphens, such as coffee-shop",
64
+ title: "how the CMS names the site, such as \xAB\u041A\u043E\u0444\u0435\u0439\u043D\u044F \xAB\u0417\u0435\u0440\u043D\u043E\xBB\xBB",
65
+ cms: "the address of the CMS, such as https://cms.seamlet.ru"
66
+ };
67
+ async function loadSiteConfig(root, cmsOverride) {
68
+ const file = new URL(SITE_CONFIG_FILE, root);
69
+ const parsed = await readJsonFile(file);
70
+ const input = cmsOverride === void 0 ? parsed : { ...asObject(parsed), cms: cmsOverride };
71
+ const reading = readSiteConfig(input);
72
+ if (reading.status === "read") return reading.config;
73
+ throw new Error(invalidFieldsMessage(file, reading.invalidFields));
74
+ }
75
+ async function readJsonFile(file) {
76
+ let text;
77
+ try {
78
+ text = await readFile2(file, "utf8");
79
+ } catch (error) {
80
+ throw new Error(
81
+ `@seamlet/astro: ${fileURLToPath(file)} is missing: the site names its id, its title and its CMS there`,
82
+ { cause: error }
83
+ );
84
+ }
85
+ try {
86
+ return JSON.parse(text);
87
+ } catch (error) {
88
+ throw new Error(`@seamlet/astro: ${fileURLToPath(file)} is not JSON`, {
89
+ cause: error
90
+ });
91
+ }
92
+ }
93
+ function asObject(value) {
94
+ return typeof value === "object" && value !== null ? value : {};
95
+ }
96
+ function invalidFieldsMessage(file, fields) {
97
+ const lines = fields.map((field) => ` "${field}": ${FIELD_RULES[field]}`);
98
+ return [
99
+ `@seamlet/astro: ${fileURLToPath(file)} needs these fields:`,
100
+ ...lines
101
+ ].join("\n");
102
+ }
103
+
56
104
  // src/index.ts
57
105
  var CONFIG_MODULE = "virtual:seamlet/config";
58
106
  var SITE_MODULE = "virtual:seamlet/site";
59
107
  var RESOLVED_CONFIG_MODULE = `\0${CONFIG_MODULE}`;
60
- function seamlet(options) {
61
- const cmsOrigin = new URL(options.cms).origin;
108
+ var SITE_MODULE_FILE = "src/seamlet.ts";
109
+ var CMS_ORIGIN_VARIABLE = "CMS_ORIGIN";
110
+ function seamlet() {
111
+ let siteConfig;
62
112
  return {
63
113
  name: "@seamlet/astro",
64
114
  hooks: {
65
- "astro:config:setup": ({
115
+ "astro:config:setup": async ({
66
116
  config,
117
+ addWatchFile,
67
118
  injectRoute,
68
119
  injectScript,
69
120
  updateConfig
70
121
  }) => {
71
- const siteModule = fileURLToPath(new URL(options.site, config.root));
122
+ const loaded = await loadSiteConfig(
123
+ config.root,
124
+ process.env[CMS_ORIGIN_VARIABLE]
125
+ );
126
+ siteConfig = loaded;
127
+ addWatchFile(new URL(SITE_CONFIG_FILE, config.root));
128
+ const siteModule = fileURLToPath2(
129
+ new URL(SITE_MODULE_FILE, config.root)
130
+ );
72
131
  updateConfig({
73
132
  vite: {
74
133
  plugins: [
@@ -79,7 +138,7 @@ function seamlet(options) {
79
138
  if (id === SITE_MODULE) return siteModule;
80
139
  return void 0;
81
140
  },
82
- load: (id) => id === RESOLVED_CONFIG_MODULE ? `export const cmsOrigin = ${JSON.stringify(cmsOrigin)};` : void 0
141
+ load: (id) => id === RESOLVED_CONFIG_MODULE ? configModuleOf(loaded) : void 0
83
142
  }
84
143
  ]
85
144
  }
@@ -110,15 +169,23 @@ function seamlet(options) {
110
169
  // the built pages refer to are copied next to them. Pages rendered on request take them
111
170
  // through the route above.
112
171
  "astro:build:done": async ({ dir, logger }) => {
172
+ if (siteConfig === void 0) return;
113
173
  const copied = await copyUploadedPhotos({
114
- directory: fileURLToPath(dir),
115
- cmsOrigin
174
+ directory: fileURLToPath2(dir),
175
+ cmsOrigin: siteConfig.cms
116
176
  });
117
177
  if (copied > 0) logger.info(`copied ${String(copied)} uploaded photos`);
118
178
  }
119
179
  }
120
180
  };
121
181
  }
182
+ function configModuleOf(config) {
183
+ return [
184
+ `export const siteId = ${JSON.stringify(config.id)};`,
185
+ `export const siteTitle = ${JSON.stringify(config.title)};`,
186
+ `export const cmsOrigin = ${JSON.stringify(config.cms)};`
187
+ ].join("\n");
188
+ }
122
189
  export {
123
190
  seamlet as default
124
191
  };
package/dist/protocol.js CHANGED
@@ -22,8 +22,8 @@ import {
22
22
  shortcutOf,
23
23
  toggleList,
24
24
  toggleMark
25
- } from "./chunk-UBBVOSON.js";
26
- import "./chunk-NFUGV7JJ.js";
25
+ } from "./chunk-2E7VDSUK.js";
26
+ import "./chunk-DRDPKFHZ.js";
27
27
  export {
28
28
  OWN_PHOTOS_PATH,
29
29
  PROTOCOL_VERSION,
package/dist/schema.d.ts CHANGED
@@ -175,4 +175,27 @@ declare function openingHoursField(options?: {
175
175
  /** The schema the input describes, or undefined when it is not one. */
176
176
  declare function readFields(input: unknown): Fields | undefined;
177
177
 
178
- export { ChoicesField, CollectionField, type CollectionRecords, Content, ContentOf, type ContentPath, FIELD_PATH_ATTRIBUTE, Field, type FieldMarker, FieldPath, type FieldTarget, Fields, GroupField, ImageField, ImageValue, LinkField, type LinkKind, type LinkTarget, LinkValue, RECORD_ID_KEY, REVEALED_ATTRIBUTE, REVEAL_ATTRIBUTE, REVEAL_EVENT, RecordFields, TextField, TimeField, UrlField, WEEKDAYS, collectionAt, contactsFields, editable, findRecord, hrefOf, imagePosition, isRecordId, linkTargetOf, newRecord, openingHoursField, readFields, resolveFieldPath, seoFields, withRecordIds };
178
+ /** The file at the root of a site's repository. */
179
+ declare const SITE_CONFIG_FILE = "seamlet.json";
180
+ interface SiteConfig {
181
+ /** The site's id in the CMS: its address there (`/sites/<id>`) and the name of its content. */
182
+ readonly id: string;
183
+ /** How the CMS names the site: «Кофейня «Зерно»». */
184
+ readonly title: string;
185
+ /** The origin of the CMS the site belongs to: `https://cms.seamlet.ru`. */
186
+ readonly cms: string;
187
+ }
188
+ type SiteConfigField = keyof SiteConfig;
189
+ type SiteConfigReading = {
190
+ readonly status: "read";
191
+ readonly config: SiteConfig;
192
+ } | {
193
+ readonly status: "invalid";
194
+ /** The fields that are missing or not what they must be. */
195
+ readonly invalidFields: readonly SiteConfigField[];
196
+ };
197
+ declare function isSiteId(value: unknown): value is string;
198
+ /** The config the input gives (the parsed `seamlet.json`); fields it does not know are left out. */
199
+ declare function readSiteConfig(input: unknown): SiteConfigReading;
200
+
201
+ export { ChoicesField, CollectionField, type CollectionRecords, Content, ContentOf, type ContentPath, FIELD_PATH_ATTRIBUTE, Field, type FieldMarker, FieldPath, type FieldTarget, Fields, GroupField, ImageField, ImageValue, LinkField, type LinkKind, type LinkTarget, LinkValue, RECORD_ID_KEY, REVEALED_ATTRIBUTE, REVEAL_ATTRIBUTE, REVEAL_EVENT, RecordFields, SITE_CONFIG_FILE, type SiteConfig, type SiteConfigField, type SiteConfigReading, TextField, TimeField, UrlField, WEEKDAYS, collectionAt, contactsFields, editable, findRecord, hrefOf, imagePosition, isRecordId, isSiteId, linkTargetOf, newRecord, openingHoursField, readFields, readSiteConfig, resolveFieldPath, seoFields, withRecordIds };
package/dist/schema.js CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  REVEALED_ATTRIBUTE,
5
5
  REVEAL_ATTRIBUTE,
6
6
  REVEAL_EVENT,
7
+ SITE_CONFIG_FILE,
7
8
  SITE_DESCRIPTION_PATH,
8
9
  WEEKDAYS,
9
10
  asOneParagraph,
@@ -26,6 +27,7 @@ import {
26
27
  imagePosition,
27
28
  isRecordId,
28
29
  isSearchTextsGroup,
30
+ isSiteId,
29
31
  link,
30
32
  linkTargetOf,
31
33
  newRecord,
@@ -36,6 +38,7 @@ import {
36
38
  plainTextOf,
37
39
  readFields,
38
40
  readRichText,
41
+ readSiteConfig,
39
42
  readSiteDescription,
40
43
  reference,
41
44
  references,
@@ -48,13 +51,14 @@ import {
48
51
  toggle,
49
52
  url,
50
53
  withRecordIds
51
- } from "./chunk-NFUGV7JJ.js";
54
+ } from "./chunk-DRDPKFHZ.js";
52
55
  export {
53
56
  FIELD_PATH_ATTRIBUTE,
54
57
  RECORD_ID_KEY,
55
58
  REVEALED_ATTRIBUTE,
56
59
  REVEAL_ATTRIBUTE,
57
60
  REVEAL_EVENT,
61
+ SITE_CONFIG_FILE,
58
62
  SITE_DESCRIPTION_PATH,
59
63
  WEEKDAYS,
60
64
  asOneParagraph,
@@ -77,6 +81,7 @@ export {
77
81
  imagePosition,
78
82
  isRecordId,
79
83
  isSearchTextsGroup,
84
+ isSiteId,
80
85
  link,
81
86
  linkTargetOf,
82
87
  newRecord,
@@ -87,6 +92,7 @@ export {
87
92
  plainTextOf,
88
93
  readFields,
89
94
  readRichText,
95
+ readSiteConfig,
90
96
  readSiteDescription,
91
97
  reference,
92
98
  references,
package/dist/site.d.ts CHANGED
@@ -11,11 +11,8 @@ interface SeamletPage {
11
11
  /** Where the content holds the page's title and description for search engines (`seo.menu`). */
12
12
  readonly searchTexts?: string;
13
13
  }
14
+ /** The site's content and pages; its id and title come from `seamlet.json`. */
14
15
  interface SeamletSiteDefinition<F extends Fields> {
15
- /** The site's address in the CMS: `/sites/<id>`. */
16
- readonly id: string;
17
- /** How the CMS names the site: «Кофейня «Зерно»». */
18
- readonly title: string;
19
16
  readonly schema: F;
20
17
  /** The content the site shows, and the CMS edits, until the first publication. */
21
18
  readonly initialContent: ContentOf<F>;
@@ -42,9 +39,9 @@ interface SeamletSite<F extends Fields = Fields> {
42
39
  /** Describes the site for the integration: `src/seamlet.ts` exports it as its default. */
43
40
  declare function defineSeamletSite<F extends Fields>(definition: SeamletSiteDefinition<F>): SeamletSite<F>;
44
41
  /**
45
- * What the CMS published for the site with this id, in the shape of its schema: the site's initial
46
- * content until the first publication. For a module that needs the content without the pages.
42
+ * What the CMS published for the site, in the shape of its schema: the site's initial content until
43
+ * the first publication. For a module that needs the content without the pages.
47
44
  */
48
- declare function loadPublishedContent<F extends Fields>(siteId: string, schema: F): Promise<ContentOf<F>>;
45
+ declare function loadPublishedContent<F extends Fields>(schema: F): Promise<ContentOf<F>>;
49
46
 
50
47
  export { type SeamletPage, type SeamletSite, type SeamletSiteDefinition, defineSeamletSite, loadPublishedContent };
package/dist/site.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  parseContent
3
- } from "./chunk-NFUGV7JJ.js";
3
+ } from "./chunk-DRDPKFHZ.js";
4
4
 
5
5
  // src/site.ts
6
- import { cmsOrigin } from "virtual:seamlet/config";
6
+ import { cmsOrigin, siteId, siteTitle } from "virtual:seamlet/config";
7
7
 
8
8
  // src/site-descriptions.ts
9
- function describeSite(definition) {
9
+ function describeSite(identity, definition) {
10
10
  const pages = Object.entries(definition.pages).map(
11
11
  ([path, page]) => ({
12
12
  path,
@@ -16,11 +16,11 @@ function describeSite(definition) {
16
16
  );
17
17
  const [home, ...rest] = pages;
18
18
  if (home === void 0) {
19
- throw new Error(`The site "${definition.id}" has no pages`);
19
+ throw new Error(`The site "${identity.id}" has no pages`);
20
20
  }
21
21
  return {
22
- id: definition.id,
23
- title: definition.title,
22
+ id: identity.id,
23
+ title: identity.title,
24
24
  schema: definition.schema,
25
25
  initialContent: definition.initialContent,
26
26
  pages: [home, ...rest]
@@ -32,20 +32,20 @@ var HOME_PAGE_PATH = "/";
32
32
  function defineSeamletSite(definition) {
33
33
  const pages = new Map(Object.entries(definition.pages));
34
34
  return {
35
- id: definition.id,
35
+ id: siteId,
36
36
  schema: definition.schema,
37
37
  pageAt: (rest) => pages.get(rest === void 0 ? HOME_PAGE_PATH : `/${rest}`)?.component,
38
- loadPublishedContent: () => loadPublishedContent(definition.id, definition.schema),
38
+ loadPublishedContent: () => loadPublishedContent(definition.schema),
39
39
  ownPhotoAt: (src) => definition.photos?.(src),
40
- description: describeSite(definition)
40
+ description: describeSite({ id: siteId, title: siteTitle }, definition)
41
41
  };
42
42
  }
43
- async function loadPublishedContent(siteId, schema) {
43
+ async function loadPublishedContent(schema) {
44
44
  const published = await fetchPublished(siteId);
45
45
  return parseContent(schema, published).content;
46
46
  }
47
- async function fetchPublished(siteId) {
48
- const url = new URL(`/api/sites/${siteId}/published`, cmsOrigin);
47
+ async function fetchPublished(id) {
48
+ const url = new URL(`/api/sites/${id}/published`, cmsOrigin);
49
49
  const response = await fetch(url);
50
50
  if (!response.ok) {
51
51
  throw new Error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamlet/astro",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Connects an Astro site to the Seamlet CMS: the schema of its content, the preview the editor frames, and its published content.",
5
5
  "license": "MIT",
6
6
  "type": "module",