@sandboxsonny/ace-kit 0.11.0 → 0.12.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @sandboxsonny/ace-kit
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4d64734: Add a sitemap and `robots.txt`. `getSitemapResponse` and `getRobotsResponse` (Astro), and `sitemapLoader` and `robotsLoader` (React Router), each make the file in one line. The sitemap lists the site's live pages from the CMS, leaving out content types whose entries aren't pages of their own, with when each last changed. Also adds `client.getSitemap()`, and the pure `sitemapXml`, `robotsTxt` and `publicOrigin` helpers.
8
+
3
9
  ## 0.11.0
4
10
 
5
11
  ### Minor Changes
package/dist/astro.d.ts CHANGED
@@ -53,6 +53,14 @@ type AceSite = {
53
53
  favicon: AceFavicon | null;
54
54
  };
55
55
 
56
+ /** One page of the site as the CMS lists it for the sitemap. */
57
+ type AceSitemapEntry = {
58
+ /** The address visitors use: "/" for the home entry, otherwise "/{content type}/{entry}". */
59
+ path: string;
60
+ /** When the entry was last changed, as an ISO date and time. */
61
+ updated_at: string;
62
+ };
63
+
56
64
  /** A redirect the CMS has for an address, as its public API returns it. */
57
65
  type AceRedirect = {
58
66
  /** The old address the redirect is for. */
@@ -122,6 +130,13 @@ type AceValuesOf<Handle extends string> = Handle extends keyof AceContentTypes
122
130
  ? AceContentTypes[Handle]
123
131
  : Record<string, unknown>;
124
132
 
133
+ type RobotsOptions = {
134
+ /** Asks every crawler to stay away, for a site that isn't live yet. */
135
+ disallowAll?: boolean;
136
+ /** The site's address, e.g. `https://example.com`. Left out, the address the request came to is used. */
137
+ origin?: string;
138
+ };
139
+
125
140
  /** What to do with a request for a page: show an entry, redirect, or explain. */
126
141
  type AcePage<Values = Record<string, unknown>> =
127
142
  | { kind: "entry"; status: 200; entry: AceEntry<Values>; headers: Record<string, string> }
@@ -140,6 +155,7 @@ declare const ace: {
140
155
  }): Promise<AceEntry<AceValuesOf<Handle>>[]>;
141
156
  getMenu(handle: string): Promise<AceMenu | null>;
142
157
  getRedirect(address: string): Promise<AceRedirect | null>;
158
+ getSitemap(): Promise<AceSitemapEntry[]>;
143
159
  getSite(): Promise<AceSite | null>;
144
160
  getContentTypes(): Promise<AceContentTypeSchema[]>;
145
161
  };
@@ -188,5 +204,31 @@ declare function getPage<Values = Record<string, unknown>>(astro: {
188
204
  headers: Headers;
189
205
  };
190
206
  }): Promise<AcePage<Values>>;
207
+ /**
208
+ * The response for `/sitemap.xml`: the site's live pages (of the content types that have pages), with when each last
209
+ * changed. Make `src/pages/sitemap.xml.ts` with
210
+ *
211
+ * import { getSitemapResponse } from "@sandboxsonny/ace-kit/astro";
212
+ * export const GET = ({ url }) => getSitemapResponse({ url });
213
+ *
214
+ * The addresses use https unless the site is on localhost; pass `{ origin: "https://example.com" }` to choose.
215
+ */
216
+ declare const getSitemapResponse: (astro: {
217
+ url: URL;
218
+ }, options?: {
219
+ origin?: string;
220
+ }) => Promise<Response>;
221
+ /**
222
+ * The response for `/robots.txt`, which lets crawlers in and points them at the sitemap. Make `src/pages/robots.txt.ts`
223
+ * with
224
+ *
225
+ * import { getRobotsResponse } from "@sandboxsonny/ace-kit/astro";
226
+ * export const GET = ({ url }) => getRobotsResponse({ url });
227
+ *
228
+ * Pass `{ disallowAll: true }` for a site that isn't live yet.
229
+ */
230
+ declare const getRobotsResponse: (astro: {
231
+ url: URL;
232
+ }, options?: RobotsOptions) => Response;
191
233
 
192
- export { ace, applyPage, getEntries, getEntry, getMenu, getMenuLinks, getPage, getSite };
234
+ export { ace, applyPage, getEntries, getEntry, getMenu, getMenuLinks, getPage, getRobotsResponse, getSite, getSitemapResponse };
package/dist/astro.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createAceClient, loadMenuLinks, loadPage } from './chunk-PXT3H7C6.js';
1
+ import { createAceClient, loadMenuLinks, loadPage, sitemapResponse, robotsResponse } from './chunk-AJLQFATM.js';
2
2
  import './chunk-M5WR5TCR.js';
3
3
  import './chunk-YLO6IAXF.js';
4
4
  import { ACE_SITE_DOMAIN, ACE_API_URL } from 'astro:env/server';
@@ -21,5 +21,7 @@ async function getPage(astro) {
21
21
  applyPage(astro.response, page);
22
22
  return page;
23
23
  }
24
+ var getSitemapResponse = (astro, options = {}) => sitemapResponse(ace, astro.url, options);
25
+ var getRobotsResponse = (astro, options = {}) => robotsResponse(astro.url, options);
24
26
 
25
- export { ace, applyPage, getEntries, getEntry, getMenu, getMenuLinks, getPage, getSite };
27
+ export { ace, applyPage, getEntries, getEntry, getMenu, getMenuLinks, getPage, getRobotsResponse, getSite, getSitemapResponse };
@@ -98,6 +98,10 @@ function createAceClient({
98
98
  const goesSomewhereSafe = redirect !== null && typeof redirect.to === "string" && (redirect.to.startsWith("/") && !redirect.to.startsWith("//") && !redirect.to.includes("\\") || /^https?:\/\/[^\s]+$/i.test(redirect.to)) && (redirect.status === 301 || redirect.status === 302);
99
99
  return goesSomewhereSafe ? redirect : null;
100
100
  },
101
+ /** The site's live pages for its sitemap, by path. Pages of content types that have no pages of their own are left out. */
102
+ async getSitemap() {
103
+ return await get("/public/sitemap") ?? [];
104
+ },
101
105
  /** The site itself: its name, and the social image its owners chose (null if none). */
102
106
  getSite() {
103
107
  return get("/public/site");
@@ -169,4 +173,53 @@ async function notFoundOrRedirect(client, url, previewToken, headers) {
169
173
  return { kind: "not-found", status: 404, headers };
170
174
  }
171
175
 
172
- export { AcePreviewExpiredError, AceUnavailableError, createAceClient, isCurrentPage, linksFromMenu, loadMenuLinks, loadPage };
176
+ // src/helpers/sitemap.ts
177
+ var escapeXml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
178
+ function publicOrigin(url) {
179
+ const local = url.hostname === "localhost" || url.hostname.endsWith(".localhost") || /^[\d.]+$|:/.test(url.hostname);
180
+ return local ? url.origin : `https://${url.host}`;
181
+ }
182
+ function sitemapXml(entries, origin) {
183
+ const base = origin.replace(/\/+$/, "");
184
+ const urls = entries.map((entry) => {
185
+ const lastChanged = Number.isNaN(Date.parse(entry.updated_at)) ? "" : new Date(entry.updated_at).toISOString();
186
+ return ` <url>
187
+ <loc>${escapeXml(`${base}${entry.path}`)}</loc>${lastChanged ? `
188
+ <lastmod>${lastChanged}</lastmod>` : ""}
189
+ </url>`;
190
+ }).join("\n");
191
+ return `<?xml version="1.0" encoding="UTF-8"?>
192
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
193
+ ${urls}${urls ? "\n" : ""}</urlset>
194
+ `;
195
+ }
196
+ function robotsTxt({ origin, disallowAll = false }) {
197
+ if (disallowAll) return "User-agent: *\nDisallow: /\n";
198
+ return `User-agent: *
199
+ Allow: /
200
+
201
+ Sitemap: ${origin.replace(/\/+$/, "")}/sitemap.xml
202
+ `;
203
+ }
204
+ async function sitemapResponse(client, url, options = {}) {
205
+ try {
206
+ const entries = await client.getSitemap();
207
+ return new Response(sitemapXml(entries, options.origin ?? publicOrigin(url)), {
208
+ headers: { "Content-Type": "application/xml; charset=utf-8", "Cache-Control": "public, max-age=300" }
209
+ });
210
+ } catch (error) {
211
+ if (!(error instanceof AceUnavailableError)) throw error;
212
+ console.error(error.message);
213
+ return new Response("The sitemap is unavailable right now.", {
214
+ status: 503,
215
+ headers: { "Content-Type": "text/plain; charset=utf-8", "Retry-After": "300" }
216
+ });
217
+ }
218
+ }
219
+ function robotsResponse(url, options = {}) {
220
+ return new Response(robotsTxt({ origin: options.origin ?? publicOrigin(url), disallowAll: options.disallowAll }), {
221
+ headers: { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "public, max-age=3600" }
222
+ });
223
+ }
224
+
225
+ export { AcePreviewExpiredError, AceUnavailableError, createAceClient, isCurrentPage, linksFromMenu, loadMenuLinks, loadPage, publicOrigin, robotsResponse, robotsTxt, sitemapResponse, sitemapXml };
package/dist/cli.js CHANGED
@@ -9,8 +9,8 @@ if (major < 22 || major === 22 && minor < 12) {
9
9
  process.exit(1);
10
10
  }
11
11
  try {
12
- const { createRealEnvironment } = await import("./environment-LTPUSFAK.js");
13
- const { runCli } = await import("./main-IKZ3DQLC.js");
12
+ const { createRealEnvironment } = await import("./environment-4FBNWIHO.js");
13
+ const { runCli } = await import("./main-4QMQF3L3.js");
14
14
  const environment = await createRealEnvironment();
15
15
  process.exit(await runCli(process.argv.slice(2), environment));
16
16
  } catch (error) {
@@ -145,7 +145,7 @@ function createLastApiUrl(path) {
145
145
  }
146
146
 
147
147
  // src/cli/version.ts
148
- var aceKitVersion = true ? "0.11.0" : "development";
148
+ var aceKitVersion = true ? "0.12.0" : "development";
149
149
 
150
150
  // src/cli/environment.ts
151
151
  var runCommand = (command, commandArguments, input) => new Promise((resolve, reject) => {
package/dist/index.d.ts CHANGED
@@ -133,6 +133,14 @@ type AceSite = {
133
133
  favicon: AceFavicon | null;
134
134
  };
135
135
 
136
+ /** One page of the site as the CMS lists it for the sitemap. */
137
+ type AceSitemapEntry = {
138
+ /** The address visitors use: "/" for the home entry, otherwise "/{content type}/{entry}". */
139
+ path: string;
140
+ /** When the entry was last changed, as an ISO date and time. */
141
+ updated_at: string;
142
+ };
143
+
136
144
  /**
137
145
  * A client for the CMS Ace public API. It runs on the server only, so the visitor's browser never talks to the
138
146
  * API. The API finds the site from X-Ace-Site-Domain, which this client sets to the site's domain. X-Forwarded-Host
@@ -158,6 +166,8 @@ declare function createAceClient({ apiUrl, siteDomain, cacheSeconds, fetchImplem
158
166
  * `address` is the path with its query string, e.g. "/old-page?id=7".
159
167
  */
160
168
  getRedirect(address: string): Promise<AceRedirect | null>;
169
+ /** The site's live pages for its sitemap, by path. Pages of content types that have no pages of their own are left out. */
170
+ getSitemap(): Promise<AceSitemapEntry[]>;
161
171
  /** The site itself: its name, and the social image its owners chose (null if none). */
162
172
  getSite(): Promise<AceSite | null>;
163
173
  /** What the site's content types and fields are, which is what type generation reads. */
@@ -551,6 +561,35 @@ type AceSeoProperties = {
551
561
  */
552
562
  declare function seoProperties(options: AceSeoOptions): AceSeoProperties;
553
563
 
564
+ /**
565
+ * The address a visitor reached the site at, for the full addresses in a sitemap. A site on a real domain is served
566
+ * over https, but behind a proxy the server often sees plain http, so anything that isn't `localhost` or an IP address
567
+ * is given https. Pass `origin` to the response helpers to choose it yourself.
568
+ */
569
+ declare function publicOrigin(url: URL): string;
570
+ /** The sitemap file for a site: one `<url>` per page, with when it last changed. `origin` is e.g. `https://example.com`. */
571
+ declare function sitemapXml(entries: AceSitemapEntry[], origin: string): string;
572
+ type RobotsOptions = {
573
+ /** Asks every crawler to stay away, for a site that isn't live yet. */
574
+ disallowAll?: boolean;
575
+ /** The site's address, e.g. `https://example.com`. Left out, the address the request came to is used. */
576
+ origin?: string;
577
+ };
578
+ /** The `robots.txt` for a site: everything may be crawled, and the sitemap is pointed at. */
579
+ declare function robotsTxt({ origin, disallowAll }: {
580
+ origin: string;
581
+ disallowAll?: boolean;
582
+ }): string;
583
+ /**
584
+ * The response for `/sitemap.xml`: the site's live pages from the CMS. If the CMS can't be reached it answers 503, so a
585
+ * crawler tries again later instead of reading an empty sitemap.
586
+ */
587
+ declare function sitemapResponse(client: AceClient, url: URL, options?: {
588
+ origin?: string;
589
+ }): Promise<Response>;
590
+ /** The response for `/robots.txt`. */
591
+ declare function robotsResponse(url: URL, options?: RobotsOptions): Response;
592
+
554
593
  /**
555
594
  * A text area field's text as HTML. With `multiline` (the default) blank lines start new paragraphs (`<p>`) and a
556
595
  * single new line is a line break; without it the text is one line, with no element around it. Every piece of text
@@ -592,4 +631,4 @@ type AceSection = {
592
631
  blocks: AceSectionBlock[];
593
632
  };
594
633
 
595
- export { type AceAddress, type AceClient, type AceClientOptions, type AceContentTypeHandle, type AceContentTypeSchema, type AceContentTypes, type AceDateFormat, type AceEntry, type AceFavicon, type AceFieldSchema, type AceImageAttributes, type AceImageData, type AceImageOptions, type AceLinkAttributes, type AceLinkData, type AceMenu, type AceMenuItem, type AceNavigationLink, type AcePage, AcePreviewExpiredError, type AceRedirect, type AceRichTextDocument, type AceRichTextMark, type AceRichTextNode, type AceSection, type AceSectionBlock, type AceSeoOptions, type AceSeoProperties, type AceSite, AceUnavailableError, type AceValuesOf, type BlockDefinition, type SectionDefinition, type SectionFieldDefinition, type SectionFieldType, type SectionOf, type SectionTypesPayload, type ValuesOfFields, addFramingPolicy, addressFromPath, checkSectionDefinition, createAceClient, defineSection, formatAceDate, framingPolicy, headingLevel, homeAddress, imageAttributes, isCurrentPage, isHomeAddress, isInternalPath, isRefreshRequest, linkAddress, linkAttributes, linksFromMenu, listStart, listenForPreviewRefresh, loadMenuLinks, loadPage, originOf, pageNotices, pathOfAddress, previewHeaders, previewParameter, previewTokenFrom, refreshMessageType, refreshPageContent, renderRichText, renderTextArea, richTextImageSizes, sectionTypesPayload, seoDescriptionHandle, seoProperties, seoTitleHandle, swapPageContent, visitablePath };
634
+ export { type AceAddress, type AceClient, type AceClientOptions, type AceContentTypeHandle, type AceContentTypeSchema, type AceContentTypes, type AceDateFormat, type AceEntry, type AceFavicon, type AceFieldSchema, type AceImageAttributes, type AceImageData, type AceImageOptions, type AceLinkAttributes, type AceLinkData, type AceMenu, type AceMenuItem, type AceNavigationLink, type AcePage, AcePreviewExpiredError, type AceRedirect, type AceRichTextDocument, type AceRichTextMark, type AceRichTextNode, type AceSection, type AceSectionBlock, type AceSeoOptions, type AceSeoProperties, type AceSite, type AceSitemapEntry, AceUnavailableError, type AceValuesOf, type BlockDefinition, type RobotsOptions, type SectionDefinition, type SectionFieldDefinition, type SectionFieldType, type SectionOf, type SectionTypesPayload, type ValuesOfFields, addFramingPolicy, addressFromPath, checkSectionDefinition, createAceClient, defineSection, formatAceDate, framingPolicy, headingLevel, homeAddress, imageAttributes, isCurrentPage, isHomeAddress, isInternalPath, isRefreshRequest, linkAddress, linkAttributes, linksFromMenu, listStart, listenForPreviewRefresh, loadMenuLinks, loadPage, originOf, pageNotices, pathOfAddress, previewHeaders, previewParameter, previewTokenFrom, publicOrigin, refreshMessageType, refreshPageContent, renderRichText, renderTextArea, richTextImageSizes, robotsResponse, robotsTxt, sectionTypesPayload, seoDescriptionHandle, seoProperties, seoTitleHandle, sitemapResponse, sitemapXml, swapPageContent, visitablePath };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { pageNotices } from './chunk-XPZY5R5A.js';
2
2
  export { headingLevel, imageAttributes, isInternalPath, linkAddress, linkAttributes, listStart, renderRichText, renderTextArea, richTextImageSizes } from './chunk-FVR55GIU.js';
3
3
  export { listenForPreviewRefresh, refreshPageContent } from './chunk-YN7LJWGI.js';
4
- export { AcePreviewExpiredError, AceUnavailableError, createAceClient, isCurrentPage, linksFromMenu, loadMenuLinks, loadPage } from './chunk-PXT3H7C6.js';
4
+ export { AcePreviewExpiredError, AceUnavailableError, createAceClient, isCurrentPage, linksFromMenu, loadMenuLinks, loadPage, publicOrigin, robotsResponse, robotsTxt, sitemapResponse, sitemapXml } from './chunk-AJLQFATM.js';
5
5
  export { addressFromPath, homeAddress, isHomeAddress, pathOfAddress, visitablePath } from './chunk-M5WR5TCR.js';
6
6
  export { addFramingPolicy, framingPolicy, isRefreshRequest, originOf, previewHeaders, previewParameter, previewTokenFrom, refreshMessageType, swapPageContent } from './chunk-YLO6IAXF.js';
7
7
 
@@ -1376,6 +1376,10 @@ function createAceClient({
1376
1376
  const goesSomewhereSafe = redirect !== null && typeof redirect.to === "string" && (redirect.to.startsWith("/") && !redirect.to.startsWith("//") && !redirect.to.includes("\\") || /^https?:\/\/[^\s]+$/i.test(redirect.to)) && (redirect.status === 301 || redirect.status === 302);
1377
1377
  return goesSomewhereSafe ? redirect : null;
1378
1378
  },
1379
+ /** The site's live pages for its sitemap, by path. Pages of content types that have no pages of their own are left out. */
1380
+ async getSitemap() {
1381
+ return await get("/public/sitemap") ?? [];
1382
+ },
1379
1383
  /** The site itself: its name, and the social image its owners chose (null if none). */
1380
1384
  getSite() {
1381
1385
  return get("/public/site");
@@ -136,6 +136,14 @@ type AceRedirect = {
136
136
  status: 301 | 302;
137
137
  };
138
138
 
139
+ /** One page of the site as the CMS lists it for the sitemap. */
140
+ type AceSitemapEntry = {
141
+ /** The address visitors use: "/" for the home entry, otherwise "/{content type}/{entry}". */
142
+ path: string;
143
+ /** When the entry was last changed, as an ISO date and time. */
144
+ updated_at: string;
145
+ };
146
+
139
147
  /**
140
148
  * A client for the CMS Ace public API. It runs on the server only, so the visitor's browser never talks to the
141
149
  * API. The API finds the site from X-Ace-Site-Domain, which this client sets to the site's domain. X-Forwarded-Host
@@ -161,6 +169,8 @@ declare function createAceClient({ apiUrl, siteDomain, cacheSeconds, fetchImplem
161
169
  * `address` is the path with its query string, e.g. "/old-page?id=7".
162
170
  */
163
171
  getRedirect(address: string): Promise<AceRedirect | null>;
172
+ /** The site's live pages for its sitemap, by path. Pages of content types that have no pages of their own are left out. */
173
+ getSitemap(): Promise<AceSitemapEntry[]>;
164
174
  /** The site itself: its name, and the social image its owners chose (null if none). */
165
175
  getSite(): Promise<AceSite | null>;
166
176
  /** What the site's content types and fields are, which is what type generation reads. */
@@ -169,6 +179,13 @@ declare function createAceClient({ apiUrl, siteDomain, cacheSeconds, fetchImplem
169
179
  /** The client `createAceClient` returns. */
170
180
  type AceClient = ReturnType<typeof createAceClient>;
171
181
 
182
+ type RobotsOptions = {
183
+ /** Asks every crawler to stay away, for a site that isn't live yet. */
184
+ disallowAll?: boolean;
185
+ /** The site's address, e.g. `https://example.com`. Left out, the address the request came to is used. */
186
+ origin?: string;
187
+ };
188
+
172
189
  /** What the root loader (`createRootLoader`) puts in the root route's data, for `useAceMenu` and `useAcePreview`. */
173
190
  type AceRootData = {
174
191
  ace: {
@@ -229,6 +246,31 @@ declare function createPageLoader<Values = Record<string, unknown>>(): ({ reques
229
246
  entry: AceEntry<Values>;
230
247
  headers: Record<string, string>;
231
248
  }>>;
249
+ /**
250
+ * The loader for `/sitemap.xml`: the site's live pages (of the content types that have pages), with when each last
251
+ * changed. Add a route `route("sitemap.xml", "routes/sitemap.tsx")` (before the catch-all) whose file is
252
+ *
253
+ * export { sitemapLoader as loader } from "@sandboxsonny/ace-kit/react-router/server";
254
+ *
255
+ * It uses https unless the site is on localhost; for another address use `createSitemapLoader({ origin })`.
256
+ */
257
+ declare const createSitemapLoader: (options?: {
258
+ origin?: string;
259
+ }) => ({ request }: {
260
+ request: Request;
261
+ }) => Promise<Response>;
262
+ /** `createSitemapLoader()` with the defaults. */
263
+ declare const sitemapLoader: ({ request }: {
264
+ request: Request;
265
+ }) => Promise<Response>;
266
+ /** The loader for `/robots.txt`, which lets crawlers in and points them at the sitemap. See `createSitemapLoader`. */
267
+ declare const createRobotsLoader: (options?: RobotsOptions) => ({ request }: {
268
+ request: Request;
269
+ }) => Response;
270
+ /** `createRobotsLoader()` with the defaults. */
271
+ declare const robotsLoader: ({ request }: {
272
+ request: Request;
273
+ }) => Response;
232
274
  /** `createPageLoader()` for a site that has not generated types for its content. */
233
275
  declare const loader: ({ request }: {
234
276
  request: Request;
@@ -281,4 +323,4 @@ declare const streamTimeout = 5000;
281
323
  */
282
324
  declare function handleRequest(request: Request, responseStatusCode: number, responseHeaders: Headers, routerContext: EntryContext, _loadContext: AppLoadContext): Promise<Response>;
283
325
 
284
- export { createPageLoader, createRootLoader, getAceClient, getEntries, getEntry, getMenu, getMenuLinks, getSite, handleRequest, headers, loader, streamTimeout };
326
+ export { createPageLoader, createRobotsLoader, createRootLoader, createSitemapLoader, getAceClient, getEntries, getEntry, getMenu, getMenuLinks, getSite, handleRequest, headers, loader, robotsLoader, sitemapLoader, streamTimeout };
@@ -1,4 +1,4 @@
1
- import { createAceClient, loadMenuLinks, loadPage } from './chunk-PXT3H7C6.js';
1
+ import { createAceClient, loadMenuLinks, loadPage, sitemapResponse, robotsResponse } from './chunk-AJLQFATM.js';
2
2
  import './chunk-M5WR5TCR.js';
3
3
  import { hostedAdminOrigin, hostedApiUrl } from './chunk-N5DIMG3X.js';
4
4
  import { previewTokenFrom, addFramingPolicy } from './chunk-YLO6IAXF.js';
@@ -43,6 +43,14 @@ function createPageLoader() {
43
43
  return data(page, { status: page.status, headers: page.headers });
44
44
  };
45
45
  }
46
+ var createSitemapLoader = (options = {}) => function loader2({ request }) {
47
+ return sitemapResponse(getAceClient(), new URL(request.url), options);
48
+ };
49
+ var sitemapLoader = createSitemapLoader();
50
+ var createRobotsLoader = (options = {}) => function loader2({ request }) {
51
+ return robotsResponse(new URL(request.url), options);
52
+ };
53
+ var robotsLoader = createRobotsLoader();
46
54
  var loader = createPageLoader();
47
55
  var headers = ({ loaderHeaders }) => loaderHeaders;
48
56
  function createRootLoader({ menu, fallback = [] }) {
@@ -88,4 +96,4 @@ function handleRequest(request, responseStatusCode, responseHeaders, routerConte
88
96
  });
89
97
  }
90
98
 
91
- export { createPageLoader, createRootLoader, getAceClient, getEntries, getEntry, getMenu, getMenuLinks, getSite, handleRequest, headers, loader, streamTimeout };
99
+ export { createPageLoader, createRobotsLoader, createRootLoader, createSitemapLoader, getAceClient, getEntries, getEntry, getMenu, getMenuLinks, getSite, handleRequest, headers, loader, robotsLoader, sitemapLoader, streamTimeout };
@@ -86,13 +86,14 @@ Types: `AceSection`, `AceSectionBlock`, `SectionDefinition`, `SectionFieldDefini
86
86
 
87
87
  `@sandboxsonny/ace-kit/astro` (uses the integration's settings, so there is no client to create):
88
88
 
89
- | | |
90
- | ----------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
91
- | `getPage(Astro)` | What to show for the page being requested; also sets the response's status and headers. A `redirect` is returned for you to act on with `Astro.redirect`. |
92
- | `getEntry(contentType, handle)`, `getEntries(contentType, { limit? })`, `getMenu(handle)` | As on the client. |
93
- | `getMenuLinks(handle, { fallback? })` | A menu's links, or the fallback if the menu is missing or the CMS is down. |
94
- | `applyPage(response, page)` | Puts a page's status and headers on a response. |
95
- | `ace` | The client these use. |
89
+ | | |
90
+ | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
91
+ | `getPage(Astro)` | What to show for the page being requested; also sets the response's status and headers. A `redirect` is returned for you to act on with `Astro.redirect`. |
92
+ | `getEntry(contentType, handle)`, `getEntries(contentType, { limit? })`, `getMenu(handle)` | As on the client. |
93
+ | `getSitemapResponse({ url }, { origin? })`, `getRobotsResponse({ url }, { origin?, disallowAll? })` | The responses for `/sitemap.xml` and `/robots.txt` (see [Astro](./astro.md)). |
94
+ | `getMenuLinks(handle, { fallback? })` | A menu's links, or the fallback if the menu is missing or the CMS is down. |
95
+ | `applyPage(response, page)` | Puts a page's status and headers on a response. |
96
+ | `ace` | The client these use. |
96
97
 
97
98
  Components, by file: `AceImage.astro`, `AceLink.astro`, `AceSections.astro`, `AceRichText.astro`, `AceTextArea.astro`, `AceMenu.astro`, `AceNotice.astro`, `AcePreviewRefresh.astro`.
98
99
 
@@ -110,13 +111,14 @@ Components, by file: `AceImage.astro`, `AceLink.astro`, `AceSections.astro`, `Ac
110
111
 
111
112
  `@sandboxsonny/ace-kit/react-router/server` (server only):
112
113
 
113
- | | |
114
- | ------------------------------------------------------------------- | ---------------------------------------------------------------- |
115
- | `createPageLoader<Values>()`, `loader` | The loader for the catch-all route that draws every page. |
116
- | `headers` | The route's `headers` export. |
117
- | `createRootLoader({ menu, fallback? })` | The root loader: the menu's links and whether this is a preview. |
118
- | `handleRequest`, `streamTimeout` | The server entry. |
119
- | `getEntry`, `getEntries`, `getMenu`, `getMenuLinks`, `getAceClient` | Read content from your own loaders. |
114
+ | | |
115
+ | ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
116
+ | `createPageLoader<Values>()`, `loader` | The loader for the catch-all route that draws every page. |
117
+ | `headers` | The route's `headers` export. |
118
+ | `createRootLoader({ menu, fallback? })` | The root loader: the menu's links and whether this is a preview. |
119
+ | `handleRequest`, `streamTimeout` | The server entry. |
120
+ | `sitemapLoader`, `robotsLoader`, `createSitemapLoader(options)`, `createRobotsLoader(options)` | The loaders for `/sitemap.xml` and `/robots.txt` (see [React Router](./react-router.md)). |
121
+ | `getEntry`, `getEntries`, `getMenu`, `getMenuLinks`, `getAceClient` | Read content from your own loaders. |
120
122
 
121
123
  ## React (`@sandboxsonny/ace-kit/react`)
122
124
 
package/docs/astro.md CHANGED
@@ -48,6 +48,24 @@ if (page.kind === "redirect") return Astro.redirect(page.location, page.status);
48
48
 
49
49
  Addresses are `/{content type}/{entry}` as on Shopify, `/` is the `home` entry of `pages`, and `/pages/home` redirects to `/`. An address with no page is redirected too if the site's owners set up a redirect for it in the CMS (Redirects), so old addresses from a site you moved keep working. `page.kind` is `entry`, `redirect`, `not-found`, `unavailable` or `preview-expired`. `AceNotice` draws a heading and a message for the last three; draw your own if you prefer.
50
50
 
51
+ ## Sitemap and robots.txt
52
+
53
+ Search engines find a site's pages through `/sitemap.xml` and are pointed at it by `/robots.txt`. Both are one small file each; the sitemap lists the live pages from the CMS (only the content types that have "Entries have their own pages" ticked), with when each last changed.
54
+
55
+ ```ts
56
+ // src/pages/sitemap.xml.ts
57
+ import { getSitemapResponse } from "@sandboxsonny/ace-kit/astro";
58
+ export const GET = ({ url }) => getSitemapResponse({ url });
59
+ ```
60
+
61
+ ```ts
62
+ // src/pages/robots.txt.ts
63
+ import { getRobotsResponse } from "@sandboxsonny/ace-kit/astro";
64
+ export const GET = ({ url }) => getRobotsResponse({ url });
65
+ ```
66
+
67
+ Addresses in the sitemap use `https` unless the site is on `localhost`; pass `{ origin: "https://www.example.com" }` to either to choose. `getRobotsResponse({ url }, { disallowAll: true })` asks crawlers to stay away, for a site that isn't live yet. Delete any `robots.txt` in `public/`, which would take its place.
68
+
51
69
  ## Reading content
52
70
 
53
71
  Anywhere in a page or component:
@@ -102,6 +102,22 @@ From `@sandboxsonny/ace-kit/react-router` (these are safe in the browser):
102
102
  - **AceImage** is an `<img>` with `src`, `srcset`, `sizes`, size and alt text. Set `sizes` to how wide it is shown, and `lazy={false}` for the image at the top of the page.
103
103
  - **AceNotice** is the heading and message for a page that isn't an entry. Give it a `className`.
104
104
 
105
+ ## Sitemap and robots.txt
106
+
107
+ Search engines find a site's pages through `/sitemap.xml` and are pointed at it by `/robots.txt`. Add two routes before the catch-all in `app/routes.ts`: `route("sitemap.xml", "routes/sitemap.tsx")` and `route("robots.txt", "routes/robots.tsx")`, whose files are one line each:
108
+
109
+ ```ts
110
+ // app/routes/sitemap.tsx
111
+ export { sitemapLoader as loader } from "@sandboxsonny/ace-kit/react-router/server";
112
+ ```
113
+
114
+ ```ts
115
+ // app/routes/robots.tsx
116
+ export { robotsLoader as loader } from "@sandboxsonny/ace-kit/react-router/server";
117
+ ```
118
+
119
+ The sitemap lists the live pages from the CMS (only the content types that have "Entries have their own pages" ticked), with when each last changed. Addresses use `https` unless the site is on `localhost`. For another address, or to keep crawlers away from a site that isn't live yet, use `createSitemapLoader({ origin })` and `createRobotsLoader({ origin, disallowAll })`.
120
+
105
121
  ## Reading content in your own loaders
106
122
 
107
123
  From `@sandboxsonny/ace-kit/react-router/server`, with no client to create:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sandboxsonny/ace-kit",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Everything a website needs to use CMS Ace: a typed client, addressing, images, menus, rich text, live preview, and Astro and React adapters.",
5
5
  "keywords": [
6
6
  "cms",