@usethrottle/builder-react 0.4.3 → 0.5.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/CLAUDE.md +23 -2
- package/dist/{chunk-C57AQKJI.js → chunk-G6I4RIXU.js} +2122 -393
- package/dist/{chunk-E7SRVAFV.cjs → chunk-UNL4JWZS.cjs} +1992 -263
- package/dist/index.cjs +2251 -603
- package/dist/index.d.cts +186 -61
- package/dist/index.d.ts +186 -61
- package/dist/index.js +2218 -569
- package/dist/next.cjs +383 -13
- package/dist/next.d.cts +92 -3
- package/dist/next.d.ts +92 -3
- package/dist/next.js +385 -15
- package/dist/{seo-BYBk3Sya.d.cts → seo-iX2POfOp.d.cts} +39 -2
- package/dist/{seo-BYBk3Sya.d.ts → seo-iX2POfOp.d.ts} +39 -2
- package/dist/server.cjs +191 -24
- package/dist/server.d.cts +172 -8
- package/dist/server.d.ts +172 -8
- package/dist/server.js +174 -7
- package/package.json +4 -4
package/dist/server.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { b as ClientOptions, W as WidgetPack, e as LoadedSite, L as LoadedPage, d as LoadedRedirect, c as LoadedPart, P as PagePathResolver } from './seo-iX2POfOp.js';
|
|
2
|
+
export { a as BundleAsk, g as getBundle } from './seo-iX2POfOp.js';
|
|
3
|
+
import { TemplateAnswer } from '@usethrottle/builder';
|
|
3
4
|
export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
|
|
5
|
+
import { TemplateName } from '@usethrottle/builder-schema';
|
|
4
6
|
import 'react';
|
|
5
|
-
import '@usethrottle/builder-schema';
|
|
6
7
|
|
|
7
8
|
type LoadSiteOptions = ClientOptions & {
|
|
8
9
|
locale: string;
|
|
@@ -43,6 +44,19 @@ type LoadBuilderPageOptions = ClientOptions & {
|
|
|
43
44
|
/** The shopper's currency, as for `loadSite({ currency })`. */
|
|
44
45
|
currency?: string;
|
|
45
46
|
};
|
|
47
|
+
/** A page's own path (`/about`, D39): not the legacy `/` and `/pages/...` answers the page route covers. */
|
|
48
|
+
declare const isOwnPath: (path: unknown) => path is string;
|
|
49
|
+
/**
|
|
50
|
+
* Reads the page that answers at its own path, or the redirect of an older path of a page (`slug_redirects`).
|
|
51
|
+
* Uses the client's `pages.getByPath` when it has one; otherwise the page list (its summaries carry `path`), which
|
|
52
|
+
* also answers a 308 for a listed slug whose own path has moved. An older path that is no longer any page's slug
|
|
53
|
+
* is only found by `getByPath` (no Worker call is made per unknown path). Rejects with `BuilderNotFoundError` when nothing is at the path.
|
|
54
|
+
*/
|
|
55
|
+
declare function loadBuilderPageByPath(options: Omit<LoadBuilderPageOptions, 'slug'> & {
|
|
56
|
+
path: string;
|
|
57
|
+
}): Promise<LoadedPage | LoadedRedirect>;
|
|
58
|
+
/** The own paths (`/about`) of the published pages, for `BuilderProvider`'s `ownPagePaths`. */
|
|
59
|
+
declare function loadOwnPagePaths(options: ClientOptions): Promise<string[]>;
|
|
46
60
|
/**
|
|
47
61
|
* Reads one published page for a request. Data of the page's non-perShopper
|
|
48
62
|
* sources is resolved here, each distinct binding once, into `initialData`;
|
|
@@ -54,6 +68,25 @@ type LoadBuilderPageOptions = ClientOptions & {
|
|
|
54
68
|
*/
|
|
55
69
|
declare function loadBuilderPage(options: LoadBuilderPageOptions): Promise<LoadedPage | LoadedRedirect>;
|
|
56
70
|
|
|
71
|
+
type LoadBuilderTemplateOptions = ClientOptions & {
|
|
72
|
+
name: TemplateName;
|
|
73
|
+
locale: string;
|
|
74
|
+
packs?: readonly WidgetPack[];
|
|
75
|
+
/** The shopper's currency, as for `loadBuilderPage`. */
|
|
76
|
+
currency?: string | undefined;
|
|
77
|
+
/** What the bundle answer holds once for every document (saved sections, code runtime). */
|
|
78
|
+
shared?: Pick<TemplateAnswer, 'savedSections' | 'code'>;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Reads one published template (`client.getTemplate`) for a request, with the data of its non-perShopper sources
|
|
82
|
+
* resolved once. `context.*` bindings are the loader's and are not resolved here. An unpublished template is an empty
|
|
83
|
+
* document, never an error; `BuilderUnavailableError` is the client's own answer when it has no last good one.
|
|
84
|
+
*/
|
|
85
|
+
declare function loadBuilderTemplate(options: LoadBuilderTemplateOptions): Promise<{
|
|
86
|
+
part: LoadedPart;
|
|
87
|
+
meta: TemplateAnswer['meta'];
|
|
88
|
+
}>;
|
|
89
|
+
|
|
57
90
|
type BuilderSitemapOptions = ClientOptions & {
|
|
58
91
|
/** The store's origin (`https://shop.example.com`). The Builder does not publish it, so it is required: without a valid one the sitemap is empty. */
|
|
59
92
|
storeUrl?: string;
|
|
@@ -67,11 +100,142 @@ type BuilderSitemapOptions = ClientOptions & {
|
|
|
67
100
|
/** Where your store serves a page, as for `createBuilderPage`. Pass the same function. */
|
|
68
101
|
pagePath?: PagePathResolver;
|
|
69
102
|
};
|
|
70
|
-
/**
|
|
71
|
-
declare
|
|
103
|
+
/** URLs per sitemap file (the sitemaps.org limit). */
|
|
104
|
+
declare const SITEMAP_MAX_URLS = 50000;
|
|
105
|
+
/** A source of extra URLs (the catalog pack's products, collections, ...). `loc` is an absolute URL on the store's origin. */
|
|
106
|
+
type SitemapContributor = () => AsyncIterable<{
|
|
107
|
+
loc: string;
|
|
108
|
+
lastmod?: Date | string | undefined;
|
|
109
|
+
}>;
|
|
110
|
+
type BuilderSitemapExtras = {
|
|
111
|
+
contributors?: readonly SitemapContributor[] | undefined;
|
|
112
|
+
};
|
|
113
|
+
type SitemapEntry = {
|
|
72
114
|
url: string;
|
|
73
|
-
lastModified
|
|
74
|
-
}
|
|
115
|
+
lastModified?: Date;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* The sitemap in files of at most 50,000 URLs, with the XML of the sitemap index when there is more than one
|
|
119
|
+
* (`<origin>/sitemap/<n>.xml`, Next's `generateSitemaps` numbering). Pages first, then each contributor; a URL is
|
|
120
|
+
* listed once; a contributor that throws, or answers another origin, loses only that URL or source.
|
|
121
|
+
*/
|
|
122
|
+
declare function builderSitemapParts(options: BuilderSitemapOptions, extras?: BuilderSitemapExtras): Promise<{
|
|
123
|
+
parts: SitemapEntry[][];
|
|
124
|
+
indexXml?: string;
|
|
125
|
+
}>;
|
|
126
|
+
/**
|
|
127
|
+
* The published pages (and the contributors' URLs) as sitemap entries. An unavailable Builder, or no key at all, gives an
|
|
128
|
+
* empty list and a warning, never a failed sitemap (a build-mode client fails the build instead). Beyond 50,000 URLs use
|
|
129
|
+
* `builderSitemapParts`.
|
|
130
|
+
*/
|
|
131
|
+
declare function builderSitemap(options: BuilderSitemapOptions, extras?: BuilderSitemapExtras): Promise<SitemapEntry[]>;
|
|
132
|
+
|
|
133
|
+
type Rec = Record<string, unknown>;
|
|
134
|
+
/** The default disallow list (spec §11.4). */
|
|
135
|
+
declare const DEFAULT_ROBOTS_DISALLOW: readonly ["/cart", "/account", "/sign-in", "/sign-up", "/order/", "/search"];
|
|
136
|
+
/** The site as the SEO helpers read it: the published settings (v1 or v2; the v2 `seo` fields are all optional). */
|
|
137
|
+
type SeoSite = {
|
|
138
|
+
settings?: Rec | undefined;
|
|
139
|
+
};
|
|
140
|
+
type SeoSiteOptions = {
|
|
141
|
+
/** The store's origin, the base of the `Sitemap:` line when the settings carry no `seo.canonicalBase`. */
|
|
142
|
+
storeUrl?: string | undefined;
|
|
143
|
+
};
|
|
144
|
+
/** The site origin for absolute URLs: `seo.canonicalBase`, else `storeUrl` (an option, then `settings.storeUrl`). */
|
|
145
|
+
declare function siteOriginOf(site: SeoSite, options?: SeoSiteOptions): string | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* The text of `robots.txt`: `User-agent: *`, the disallow list (the site's, else the default), a `Sitemap:` line, then up
|
|
148
|
+
* to 50 extra lines the merchant wrote. An extra line is kept only when it is one plain line that starts with a robots
|
|
149
|
+
* directive (`User-agent`, `Allow`, `Disallow`, `Crawl-delay`, `Sitemap`) or `#`, and is not a bare `Disallow: /`.
|
|
150
|
+
*
|
|
151
|
+
* Next's `app/robots.ts` must return a `MetadataRoute.Robots` object, not text, so do NOT use this there: serve it from
|
|
152
|
+
* `app/robots.txt/route.ts` with `builderRobotsResponse` (or `new Response(builderRobots(...))`).
|
|
153
|
+
*/
|
|
154
|
+
declare function builderRobots(site: SeoSite, options?: SeoSiteOptions): string;
|
|
155
|
+
/** `builderRobots` as a `text/plain` response, for an `app/robots.txt/route.ts` handler (`export const GET = ...`). */
|
|
156
|
+
declare function builderRobotsResponse(site: SeoSite, options?: SeoSiteOptions): Response;
|
|
157
|
+
|
|
158
|
+
/** JSON-LD builders (spec §11.4). Each answers a plain object with the schema.org required properties. */
|
|
159
|
+
type JsonLd = Record<string, unknown>;
|
|
160
|
+
declare function organizationJsonLd(input: {
|
|
161
|
+
name: string;
|
|
162
|
+
url: string;
|
|
163
|
+
logo?: string | undefined;
|
|
164
|
+
sameAs?: readonly string[] | undefined;
|
|
165
|
+
}): {
|
|
166
|
+
sameAs?: string[] | undefined;
|
|
167
|
+
logo?: string | undefined;
|
|
168
|
+
'@context': "https://schema.org";
|
|
169
|
+
'@type': "Organization";
|
|
170
|
+
name: string;
|
|
171
|
+
url: string;
|
|
172
|
+
};
|
|
173
|
+
/** `WebSite` with a `SearchAction` that targets the store's search route (`/search?q=` by default). */
|
|
174
|
+
declare function webSiteJsonLd(input: {
|
|
175
|
+
name: string;
|
|
176
|
+
url: string;
|
|
177
|
+
searchPath?: string | undefined;
|
|
178
|
+
}): {
|
|
179
|
+
'@context': "https://schema.org";
|
|
180
|
+
'@type': "WebSite";
|
|
181
|
+
name: string;
|
|
182
|
+
url: string;
|
|
183
|
+
potentialAction: {
|
|
184
|
+
'@type': "SearchAction";
|
|
185
|
+
target: {
|
|
186
|
+
'@type': "EntryPoint";
|
|
187
|
+
urlTemplate: string;
|
|
188
|
+
};
|
|
189
|
+
'query-input': string;
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
declare function breadcrumbJsonLd(items: readonly {
|
|
193
|
+
name: string;
|
|
194
|
+
url: string;
|
|
195
|
+
}[]): {
|
|
196
|
+
'@context': "https://schema.org";
|
|
197
|
+
'@type': "BreadcrumbList";
|
|
198
|
+
itemListElement: {
|
|
199
|
+
'@type': "ListItem";
|
|
200
|
+
position: number;
|
|
201
|
+
name: string;
|
|
202
|
+
item: string;
|
|
203
|
+
}[];
|
|
204
|
+
};
|
|
205
|
+
declare function faqJsonLd(items: readonly {
|
|
206
|
+
question: string;
|
|
207
|
+
answer: string;
|
|
208
|
+
}[]): {
|
|
209
|
+
'@context': "https://schema.org";
|
|
210
|
+
'@type': "FAQPage";
|
|
211
|
+
mainEntity: {
|
|
212
|
+
'@type': "Question";
|
|
213
|
+
name: string;
|
|
214
|
+
acceptedAnswer: {
|
|
215
|
+
'@type': "Answer";
|
|
216
|
+
text: string;
|
|
217
|
+
};
|
|
218
|
+
}[];
|
|
219
|
+
};
|
|
220
|
+
/** `LocalBusiness` (or `Store`): name and address are the required properties. */
|
|
221
|
+
declare function localBusinessJsonLd(input: {
|
|
222
|
+
name: string;
|
|
223
|
+
url: string;
|
|
224
|
+
address: string;
|
|
225
|
+
phone?: string | undefined;
|
|
226
|
+
openingHours?: readonly string[] | undefined;
|
|
227
|
+
type?: 'LocalBusiness' | 'Store' | undefined;
|
|
228
|
+
}): {
|
|
229
|
+
openingHours?: string[] | undefined;
|
|
230
|
+
telephone?: string | undefined;
|
|
231
|
+
'@context': "https://schema.org";
|
|
232
|
+
'@type': "LocalBusiness" | "Store";
|
|
233
|
+
name: string;
|
|
234
|
+
url: string;
|
|
235
|
+
address: string;
|
|
236
|
+
};
|
|
237
|
+
/** The text for `<script type="application/ld+json">`: `<` is escaped so a value cannot close the element. */
|
|
238
|
+
declare function jsonLdString(value: unknown): string;
|
|
75
239
|
|
|
76
240
|
type BuilderStaticParamsOptions = ClientOptions & {
|
|
77
241
|
/** The dynamic segment of the route, as in `createBuilderPage({ fromParams })`. Default `handle`. */
|
|
@@ -92,4 +256,4 @@ type BuilderStaticParamsOptions = ClientOptions & {
|
|
|
92
256
|
*/
|
|
93
257
|
declare function builderStaticParams(options: BuilderStaticParamsOptions): Promise<Record<string, string>[]>;
|
|
94
258
|
|
|
95
|
-
export { type BuilderSitemapOptions, type BuilderStaticParamsOptions, type LoadBuilderPageOptions, type LoadSiteOptions, LoadedPage, LoadedRedirect, LoadedSite, builderSitemap, builderStaticParams, loadBuilderPage, loadSite };
|
|
259
|
+
export { type BuilderSitemapExtras, type BuilderSitemapOptions, type BuilderStaticParamsOptions, DEFAULT_ROBOTS_DISALLOW, type JsonLd, type LoadBuilderPageOptions, type LoadBuilderTemplateOptions, type LoadSiteOptions, LoadedPage, LoadedRedirect, LoadedSite, SITEMAP_MAX_URLS, type SeoSite, type SeoSiteOptions, type SitemapContributor, type SitemapEntry, breadcrumbJsonLd, builderRobots, builderRobotsResponse, builderSitemap, builderSitemapParts, builderStaticParams, faqJsonLd, isOwnPath, jsonLdString, loadBuilderPage, loadBuilderPageByPath, loadBuilderTemplate, loadOwnPagePaths, loadSite, localBusinessJsonLd, organizationJsonLd, siteOriginOf, webSiteJsonLd };
|
package/dist/server.js
CHANGED
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
|
+
breadcrumbJsonLd,
|
|
2
3
|
clientOf,
|
|
3
4
|
createRendererRegistry,
|
|
5
|
+
faqJsonLd,
|
|
4
6
|
getBundle,
|
|
7
|
+
isOwnPath,
|
|
5
8
|
isRedirect,
|
|
9
|
+
jsonLdString,
|
|
6
10
|
loadBuilderPage,
|
|
11
|
+
loadBuilderPageByPath,
|
|
12
|
+
loadBuilderTemplate,
|
|
13
|
+
loadOwnPagePaths,
|
|
14
|
+
localBusinessJsonLd,
|
|
7
15
|
localized,
|
|
16
|
+
organizationJsonLd,
|
|
8
17
|
originOf,
|
|
9
18
|
pagePathOf,
|
|
10
19
|
pageSeoOf,
|
|
11
20
|
partOf,
|
|
12
21
|
siteLocales,
|
|
13
22
|
staticDataFor,
|
|
14
|
-
warnOnce
|
|
15
|
-
|
|
23
|
+
warnOnce,
|
|
24
|
+
webSiteJsonLd
|
|
25
|
+
} from "./chunk-G6I4RIXU.js";
|
|
16
26
|
|
|
17
27
|
// src/server/load-site.ts
|
|
18
28
|
import { BuilderUnavailableError } from "@usethrottle/builder";
|
|
29
|
+
function siteThemeOf(site) {
|
|
30
|
+
const theme = site.theme;
|
|
31
|
+
return typeof theme?.customCssHref === "string" ? { theme: { customCssHref: theme.customCssHref } } : {};
|
|
32
|
+
}
|
|
19
33
|
async function loadSite(options) {
|
|
20
34
|
const { locale, slots = [], packs = [], page, mediaOrigin = "", currency } = options;
|
|
21
35
|
const client = clientOf(options);
|
|
@@ -40,8 +54,10 @@ async function loadSite(options) {
|
|
|
40
54
|
locale,
|
|
41
55
|
generation: bundle.generation,
|
|
42
56
|
siteVersion: bundle.site.siteVersion,
|
|
57
|
+
loadedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
43
58
|
mediaOrigin,
|
|
44
59
|
settings: bundle.site.settings,
|
|
60
|
+
...siteThemeOf(bundle.site),
|
|
45
61
|
header: partOf(bundle.header, data, bundle),
|
|
46
62
|
footer: partOf(bundle.footer, data, bundle),
|
|
47
63
|
slots: Object.fromEntries(names.map((name) => [name, partOf(bundle.slots[name], data, bundle)]))
|
|
@@ -50,13 +66,77 @@ async function loadSite(options) {
|
|
|
50
66
|
|
|
51
67
|
// src/server/sitemap.ts
|
|
52
68
|
import { BuilderNotFoundError, BuilderUnavailableError as BuilderUnavailableError2 } from "@usethrottle/builder";
|
|
53
|
-
|
|
69
|
+
var SITEMAP_MAX_URLS = 5e4;
|
|
70
|
+
var isRec = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
71
|
+
function sitemapRulesOf(settings) {
|
|
72
|
+
const seo = isRec(settings.seo) ? settings.seo : {};
|
|
73
|
+
const rules = isRec(seo.sitemap) ? seo.sitemap : {};
|
|
74
|
+
return { pages: rules.pages !== false, exclude: Array.isArray(rules.exclude) ? rules.exclude.filter((x) => typeof x === "string") : [] };
|
|
75
|
+
}
|
|
76
|
+
function excluded(rules, pathname, slug) {
|
|
77
|
+
return rules.some((rule) => {
|
|
78
|
+
if (rule.startsWith("/")) return rule.endsWith("*") ? pathname.startsWith(rule.slice(0, -1)) : pathname === rule || pathname === `${rule}/`;
|
|
79
|
+
return slug !== void 0 && rule === slug;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
var xmlEscape = (text) => text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
83
|
+
function safeLoc(loc, origin) {
|
|
84
|
+
try {
|
|
85
|
+
const parsed = new URL(loc);
|
|
86
|
+
return parsed.origin === origin ? xmlEscape(parsed.href) : null;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
var pathnameOf = (url) => {
|
|
92
|
+
try {
|
|
93
|
+
return new URL(url).pathname;
|
|
94
|
+
} catch {
|
|
95
|
+
return url;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
async function builderSitemapParts(options, extras = {}) {
|
|
99
|
+
const origin = originOf(options.storeUrl);
|
|
100
|
+
const entries = await pageEntries(options, origin);
|
|
101
|
+
if (origin === void 0) return { parts: [] };
|
|
102
|
+
const rules = sitemapRulesOf(await settingsOf(options));
|
|
103
|
+
const seen = new Set(entries.map((entry) => entry.url));
|
|
104
|
+
for (const contributor of extras.contributors ?? []) {
|
|
105
|
+
try {
|
|
106
|
+
for await (const item of contributor()) {
|
|
107
|
+
const loc = typeof item.loc === "string" ? safeLoc(item.loc, origin) : null;
|
|
108
|
+
if (loc === null || seen.has(loc)) continue;
|
|
109
|
+
if (excluded(rules.exclude, pathnameOf(loc))) continue;
|
|
110
|
+
seen.add(loc);
|
|
111
|
+
const when = item.lastmod === void 0 ? void 0 : new Date(item.lastmod);
|
|
112
|
+
entries.push({ url: loc, ...when === void 0 || Number.isNaN(when.getTime()) ? {} : { lastModified: when } });
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
warnOnce("sitemap-contributor", `A sitemap contributor failed (${error instanceof Error ? error.message : "unknown error"}); the sitemap leaves out its URLs`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const parts = [];
|
|
119
|
+
for (let from = 0; from < entries.length; from += SITEMAP_MAX_URLS) parts.push(entries.slice(from, from + SITEMAP_MAX_URLS));
|
|
120
|
+
if (parts.length < 2) return { parts };
|
|
121
|
+
const items = parts.map((_, index) => `<sitemap><loc>${xmlEscape(origin)}/sitemap/${String(index)}.xml</loc></sitemap>`).join("");
|
|
122
|
+
return { parts, indexXml: `<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${items}</sitemapindex>` };
|
|
123
|
+
}
|
|
124
|
+
async function builderSitemap(options, extras = {}) {
|
|
125
|
+
return (await builderSitemapParts(options, extras)).parts.flat();
|
|
126
|
+
}
|
|
127
|
+
async function settingsOf(options) {
|
|
128
|
+
try {
|
|
129
|
+
return (await clientOf(options).site({ locale: options.locale ?? "en" })).settings;
|
|
130
|
+
} catch {
|
|
131
|
+
return {};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function pageEntries(options, origin) {
|
|
54
135
|
if (options.client === void 0 && (options.builderKey === void 0 || options.builderKey === "")) {
|
|
55
136
|
warnOnce("sitemap-no-key", "builderSitemap has no builderKey (is THROTTLE_BUILDER_KEY set?); the sitemap leaves out the Builder pages");
|
|
56
137
|
return [];
|
|
57
138
|
}
|
|
58
139
|
const client = clientOf(options);
|
|
59
|
-
const origin = originOf(options.storeUrl);
|
|
60
140
|
if (origin === void 0) {
|
|
61
141
|
warnOnce("sitemap-origin", "builderSitemap needs a storeUrl (https://shop.example.com) that is an http(s) origin. The Builder does not publish the store URL.");
|
|
62
142
|
return [];
|
|
@@ -65,13 +145,18 @@ async function builderSitemap(options) {
|
|
|
65
145
|
try {
|
|
66
146
|
const pages = await client.pages.list();
|
|
67
147
|
const { settings } = await client.site({ locale });
|
|
148
|
+
const rules = sitemapRulesOf(settings);
|
|
149
|
+
if (!rules.pages) return [];
|
|
68
150
|
const indexable = await withoutNoindex(client, pages, locale);
|
|
69
151
|
const { list } = siteLocales(settings);
|
|
70
152
|
const prefixes = options.localeRoute !== true ? [void 0] : list.length > 0 ? list : [locale];
|
|
71
153
|
return indexable.flatMap((page) => {
|
|
72
154
|
const path = pagePathOf(settings, page, options.pagePath);
|
|
73
|
-
if (path === null) return [];
|
|
74
|
-
return prefixes.
|
|
155
|
+
if (path === null || excluded(rules.exclude, path, page.slug)) return [];
|
|
156
|
+
return prefixes.flatMap((prefix) => {
|
|
157
|
+
const url = safeLoc(`${origin}${localized(path, prefix)}`, origin);
|
|
158
|
+
return url === null ? [] : [{ url, lastModified: new Date(page.updatedAt) }];
|
|
159
|
+
});
|
|
75
160
|
});
|
|
76
161
|
} catch (error) {
|
|
77
162
|
if (!(error instanceof BuilderUnavailableError2) || client.mode === "build") throw error;
|
|
@@ -102,6 +187,72 @@ async function withoutNoindex(client, pages, locale) {
|
|
|
102
187
|
return pages.filter((page) => !skip.has(page.slug));
|
|
103
188
|
}
|
|
104
189
|
|
|
190
|
+
// src/server/robots.ts
|
|
191
|
+
var isRec2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
192
|
+
var DEFAULT_ROBOTS_DISALLOW = [
|
|
193
|
+
"/cart",
|
|
194
|
+
"/account",
|
|
195
|
+
"/sign-in",
|
|
196
|
+
"/sign-up",
|
|
197
|
+
"/order/",
|
|
198
|
+
"/search"
|
|
199
|
+
];
|
|
200
|
+
var MAX_EXTRA_LINES = 50;
|
|
201
|
+
var MAX_LINE = 200;
|
|
202
|
+
var CONTROL = new RegExp(`[\\x00-\\x1F\\x7F\\x85${String.fromCharCode(8232, 8233)}]`, "u");
|
|
203
|
+
var DIRECTIVE = /^(?:(?:User-agent|Allow|Disallow|Crawl-delay|Sitemap)\s*:|#)/iu;
|
|
204
|
+
var BLOCKS_ALL = /^Disallow\s*:\s*\/\*?\s*(?:#.*)?$/iu;
|
|
205
|
+
var USER_AGENT = /^User-agent\s*:\s*([^#]*?)\s*(?:#.*)?$/iu;
|
|
206
|
+
var validLine = (value) => typeof value === "string" && value.trim() !== "" && value.length <= MAX_LINE && !CONTROL.test(value);
|
|
207
|
+
function validExtras(values) {
|
|
208
|
+
const kept = [];
|
|
209
|
+
let agents = ["*"];
|
|
210
|
+
let started = false;
|
|
211
|
+
let inRules = false;
|
|
212
|
+
for (const value of values) {
|
|
213
|
+
if (!validLine(value)) continue;
|
|
214
|
+
const line = value.trim();
|
|
215
|
+
if (!DIRECTIVE.test(line)) continue;
|
|
216
|
+
const agent = USER_AGENT.exec(line);
|
|
217
|
+
if (agent !== null) {
|
|
218
|
+
agents = !started || inRules ? [agent[1] ?? ""] : [...agents, agent[1] ?? ""];
|
|
219
|
+
started = true;
|
|
220
|
+
inRules = false;
|
|
221
|
+
} else if (/^(?:Allow|Disallow|Crawl-delay)\s*:/iu.test(line)) {
|
|
222
|
+
if (BLOCKS_ALL.test(line) && agents.includes("*")) continue;
|
|
223
|
+
inRules = true;
|
|
224
|
+
}
|
|
225
|
+
kept.push(line);
|
|
226
|
+
}
|
|
227
|
+
return kept;
|
|
228
|
+
}
|
|
229
|
+
var validDisallow = (value) => validLine(value) && value.trim() !== "/";
|
|
230
|
+
function siteOriginOf(site, options = {}) {
|
|
231
|
+
const settings = site.settings ?? {};
|
|
232
|
+
const seo = isRec2(settings.seo) ? settings.seo : {};
|
|
233
|
+
return originOf(typeof seo.canonicalBase === "string" ? seo.canonicalBase : void 0) ?? originOf(options.storeUrl) ?? originOf(typeof settings.storeUrl === "string" ? settings.storeUrl : void 0);
|
|
234
|
+
}
|
|
235
|
+
function builderRobots(site, options = {}) {
|
|
236
|
+
const settings = site.settings ?? {};
|
|
237
|
+
const seo = isRec2(settings.seo) ? settings.seo : {};
|
|
238
|
+
const robots = isRec2(seo.robots) ? seo.robots : {};
|
|
239
|
+
const disallow = Array.isArray(robots.disallow) ? robots.disallow.filter(validDisallow) : [...DEFAULT_ROBOTS_DISALLOW];
|
|
240
|
+
const extra = Array.isArray(robots.extra) ? validExtras(robots.extra).slice(0, MAX_EXTRA_LINES) : [];
|
|
241
|
+
const origin = siteOriginOf(site, options);
|
|
242
|
+
return [
|
|
243
|
+
"User-agent: *",
|
|
244
|
+
...disallow.map((path) => `Disallow: ${path}`),
|
|
245
|
+
...origin === void 0 ? [] : [`Sitemap: ${origin}/sitemap.xml`],
|
|
246
|
+
...extra,
|
|
247
|
+
""
|
|
248
|
+
].join("\n");
|
|
249
|
+
}
|
|
250
|
+
function builderRobotsResponse(site, options = {}) {
|
|
251
|
+
return new Response(builderRobots(site, options), {
|
|
252
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
105
256
|
// src/server/static-params.ts
|
|
106
257
|
async function builderStaticParams(options) {
|
|
107
258
|
const client = clientOf(options);
|
|
@@ -118,9 +269,25 @@ import { BuilderNotFoundError as BuilderNotFoundError2, BuilderUnavailableError
|
|
|
118
269
|
export {
|
|
119
270
|
BuilderNotFoundError2 as BuilderNotFoundError,
|
|
120
271
|
BuilderUnavailableError3 as BuilderUnavailableError,
|
|
272
|
+
DEFAULT_ROBOTS_DISALLOW,
|
|
273
|
+
SITEMAP_MAX_URLS,
|
|
274
|
+
breadcrumbJsonLd,
|
|
275
|
+
builderRobots,
|
|
276
|
+
builderRobotsResponse,
|
|
121
277
|
builderSitemap,
|
|
278
|
+
builderSitemapParts,
|
|
122
279
|
builderStaticParams,
|
|
280
|
+
faqJsonLd,
|
|
123
281
|
getBundle,
|
|
282
|
+
isOwnPath,
|
|
283
|
+
jsonLdString,
|
|
124
284
|
loadBuilderPage,
|
|
125
|
-
|
|
285
|
+
loadBuilderPageByPath,
|
|
286
|
+
loadBuilderTemplate,
|
|
287
|
+
loadOwnPagePaths,
|
|
288
|
+
loadSite,
|
|
289
|
+
localBusinessJsonLd,
|
|
290
|
+
organizationJsonLd,
|
|
291
|
+
siteOriginOf,
|
|
292
|
+
webSiteJsonLd
|
|
126
293
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/builder-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Renders a published Throttle Builder page document as React in a merchant's store: responsive CSS, header, footer, slots and the site design provider.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"nextjs"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@usethrottle/builder-schema": "^0.
|
|
61
|
-
"@usethrottle/ui": "^0.1.
|
|
62
|
-
"@usethrottle/builder": "^0.
|
|
60
|
+
"@usethrottle/builder-schema": "^0.4.0",
|
|
61
|
+
"@usethrottle/ui": "^0.1.3",
|
|
62
|
+
"@usethrottle/builder": "^0.6.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"next": ">=15",
|