@usethrottle/builder-react 0.1.0 → 0.2.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 +50 -0
- package/dist/{chunk-DRQNR5GN.js → chunk-NUE2KNT2.js} +121 -24
- package/dist/{chunk-RWDLDDSF.cjs → chunk-S2XR224A.cjs} +121 -24
- package/dist/index.cjs +3 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +3 -1
- package/dist/next.cjs +15 -17
- package/dist/next.d.cts +12 -1
- package/dist/next.d.ts +12 -1
- package/dist/next.js +14 -16
- package/dist/{bundle-x5Vxd-xE.d.cts → seo-Dz439Jlk.d.cts} +15 -2
- package/dist/{bundle-x5Vxd-xE.d.ts → seo-Dz439Jlk.d.ts} +15 -2
- package/dist/server.cjs +70 -26
- package/dist/server.d.cts +35 -6
- package/dist/server.d.ts +35 -6
- package/dist/server.js +61 -17
- package/package.json +6 -5
package/CLAUDE.md
CHANGED
|
@@ -140,6 +140,39 @@ client module. `site` is plain data (what `loadSite` returned).
|
|
|
140
140
|
external: at most 35 KB (`pnpm --filter @usethrottle/builder-react size`, the
|
|
141
141
|
limit is in `size-limit.json`).
|
|
142
142
|
|
|
143
|
+
## SEO (`src/next/seo.ts`)
|
|
144
|
+
|
|
145
|
+
`createBuilderPage().generateMetadata` is `metadataOf(page, ...)`: the page's own `seo` over the
|
|
146
|
+
site's defaults. The read API (and a build-mode release) answers `page.seo` as
|
|
147
|
+
`{ title?, description?, shareImage: FrozenAsset | null, noindex }`, already in the requested
|
|
148
|
+
locale; the site's `seo` is `{ titleTemplate, defaultDescription, shareImage }`. Never read
|
|
149
|
+
`page.description` (it does not exist).
|
|
150
|
+
|
|
151
|
+
- Title is `seo.title ?? page.title` through `titleTemplate` (`{page}`, `{store}`), with replacer
|
|
152
|
+
functions so a `$&` in a title is text.
|
|
153
|
+
- Share image: the page's, else the site's, through `safeUrl(url, 'src', { mediaOrigin })`
|
|
154
|
+
(`createBuilderPage({ mediaOrigin })`, the same value as `loadSite`). Off-origin, http or no
|
|
155
|
+
origin means no image, never a guessed one.
|
|
156
|
+
- Canonical needs an origin: `createBuilderPage({ storeUrl })`, an explicit app option checked against
|
|
157
|
+
`http(s)://host` (`originOf`, shared with the sitemap). The Builder deliberately strips `storeUrl` from
|
|
158
|
+
published settings (`resolve.ts`), so there is no settings fallback; without a valid one a page has no
|
|
159
|
+
canonical and the sitemap is empty, each with one warning.
|
|
160
|
+
- Page path (`pagePathOf`, shared by canonical and sitemap): the store's `pagePath(page)` answer when it
|
|
161
|
+
is a valid site path, else `routes.page` + slug, else the Builder's default `/pages/{handle}`; never the
|
|
162
|
+
answered `page.path`, so home is `/pages/home` (the Builder says `/`; a store may serve the shop there)
|
|
163
|
+
even when a read failed. A store that serves home at `/` passes `pagePath` to both
|
|
164
|
+
`createBuilderPage` and `builderSitemap`.
|
|
165
|
+
- A route with a `[locale]` segment (and no `locale` option) prefixes `/<locale>` in the canonical and
|
|
166
|
+
gets `alternates.languages` for every site locale plus `x-default`. `builderSitemap({ localeRoute: true })`
|
|
167
|
+
lists each page once per site locale under the same prefix (`localized`). Any other URL scheme for
|
|
168
|
+
locales is not known to this package.
|
|
169
|
+
- `builderSitemap({ storeUrl, locale?, localeRoute?, pagePath? })` takes noindex from the page list
|
|
170
|
+
(`BuilderPageSummary.noindex`, sent by the Builder's `/v1/pages`) and reads no page. Only a list entry
|
|
171
|
+
with no boolean there (an older Builder, a release) is read, with `pages.get(slug, { locale })`, 8 at a
|
|
172
|
+
time; a failed read keeps the page, a missing page, a redirect and a noindex page are skipped. The page
|
|
173
|
+
route and locales come from one `site({ locale })` read.
|
|
174
|
+
- No structured data: the spec has no JSON-LD setting. It is the merchant's own choice.
|
|
175
|
+
|
|
143
176
|
## Shared files (Task 12 owns them; Tasks 13 and 14 edit marked sections only)
|
|
144
177
|
|
|
145
178
|
- `src/index.ts`: `// <task-13>` ... `// </task-13>`, `// <task-14>` ... `// </task-14>`.
|
|
@@ -176,3 +209,20 @@ cannot replace a `basic.*` type. Definitions are never re-declared here.
|
|
|
176
209
|
`layout.test.ts` launch Chromium through `playwright`
|
|
177
210
|
(`pnpm exec playwright install chromium`). Tests stand in for a request with
|
|
178
211
|
`__tests__/request-cache.ts` (a `react.cache` that memoizes per `newRequest()`).
|
|
212
|
+
|
|
213
|
+
## Build mode (Task 18c)
|
|
214
|
+
|
|
215
|
+
A client made with `createBuilderClient({ mode: 'build' })` makes the loaders (`loadSite`, `createBuilderPage`,
|
|
216
|
+
`builderSitemap`) render from the frozen release with zero network. In build mode an unreadable release throws (the
|
|
217
|
+
R8 "render nothing" fallbacks are for live clients only: `client.mode !== 'build'`). `builderStaticParams` (server
|
|
218
|
+
entry) lists every release page for `generateStaticParams` and refuses a live client: a live store keeps its pages
|
|
219
|
+
dynamic (cost rule), a build store generates them all on purpose. `src/budget.ts` exports `Budget`, the structural
|
|
220
|
+
type renderers take, so the two server entries' copies of `RenderBudget` stay interchangeable.
|
|
221
|
+
|
|
222
|
+
## RSC build check
|
|
223
|
+
|
|
224
|
+
`pnpm --filter @usethrottle/builder-react test:rsc` (CI job "builder-react in a Next App Router build") runs a real
|
|
225
|
+
`next build` of a minimal App Router app that imports `./next` and `./server` from the built dist, installed as copies under
|
|
226
|
+
`node_modules` the way an app has them. Vitest never uses the `react-server` condition, so only this catches a server entry
|
|
227
|
+
that evaluates something React's `react-server` build lacks (`PartBoundary extends Component` crashed 0.1.0). Build the
|
|
228
|
+
package first. Do not point it at a link into the workspace: Next only skips its client-hook check for code under node_modules.
|
|
@@ -644,7 +644,7 @@ function parseRichText(source, mediaOrigin) {
|
|
|
644
644
|
const stack = [root];
|
|
645
645
|
const top = () => stack[stack.length - 1];
|
|
646
646
|
let nodes = 0;
|
|
647
|
-
const
|
|
647
|
+
const text2 = (value) => {
|
|
648
648
|
if (value === "" || nodes > MAX_NODES) return;
|
|
649
649
|
nodes += 1;
|
|
650
650
|
const parent = top();
|
|
@@ -660,10 +660,10 @@ function parseRichText(source, mediaOrigin) {
|
|
|
660
660
|
while (i < html.length && nodes <= MAX_NODES) {
|
|
661
661
|
const lt = html.indexOf("<", i);
|
|
662
662
|
if (lt === -1) {
|
|
663
|
-
|
|
663
|
+
text2(decode(html.slice(i)));
|
|
664
664
|
break;
|
|
665
665
|
}
|
|
666
|
-
|
|
666
|
+
text2(decode(html.slice(i, lt)));
|
|
667
667
|
i = lt;
|
|
668
668
|
if (html.startsWith("<!--", i)) {
|
|
669
669
|
const close = html.indexOf("-->", i + 4);
|
|
@@ -679,7 +679,7 @@ function parseRichText(source, mediaOrigin) {
|
|
|
679
679
|
const close = html.indexOf(">", i);
|
|
680
680
|
i = close === -1 ? html.length : close + 1;
|
|
681
681
|
} else {
|
|
682
|
-
|
|
682
|
+
text2("<");
|
|
683
683
|
i += 1;
|
|
684
684
|
}
|
|
685
685
|
continue;
|
|
@@ -1204,10 +1204,10 @@ var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
|
1204
1204
|
function pickLocale(value, locale) {
|
|
1205
1205
|
const lang = locale.split("-")[0] ?? locale;
|
|
1206
1206
|
for (const key of [locale, lang, "en"]) {
|
|
1207
|
-
const
|
|
1208
|
-
if (typeof
|
|
1207
|
+
const text2 = Object.hasOwn(value, key) ? value[key] : void 0;
|
|
1208
|
+
if (typeof text2 === "string" && text2 !== "") return text2;
|
|
1209
1209
|
}
|
|
1210
|
-
for (const
|
|
1210
|
+
for (const text2 of Object.values(value)) if (typeof text2 === "string" && text2 !== "") return text2;
|
|
1211
1211
|
return "";
|
|
1212
1212
|
}
|
|
1213
1213
|
function onOrigin(asset, mediaOrigin) {
|
|
@@ -1354,7 +1354,9 @@ function BuilderRenderer(props) {
|
|
|
1354
1354
|
|
|
1355
1355
|
// src/part-view.tsx
|
|
1356
1356
|
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
1357
|
-
var
|
|
1357
|
+
var BoundaryBase = Component ?? class {
|
|
1358
|
+
};
|
|
1359
|
+
var PartBoundary = class extends BoundaryBase {
|
|
1358
1360
|
constructor() {
|
|
1359
1361
|
super(...arguments);
|
|
1360
1362
|
__publicField(this, "state", { failed: false });
|
|
@@ -1446,26 +1448,26 @@ function asText(value) {
|
|
|
1446
1448
|
return "";
|
|
1447
1449
|
}
|
|
1448
1450
|
function filtered(value, filters) {
|
|
1449
|
-
let
|
|
1451
|
+
let text2 = asText(value);
|
|
1450
1452
|
for (const filter of filters) {
|
|
1451
1453
|
switch (filter.name) {
|
|
1452
1454
|
case "upper":
|
|
1453
|
-
|
|
1455
|
+
text2 = text2.toUpperCase();
|
|
1454
1456
|
break;
|
|
1455
1457
|
case "lower":
|
|
1456
|
-
|
|
1458
|
+
text2 = text2.toLowerCase();
|
|
1457
1459
|
break;
|
|
1458
1460
|
case "truncate": {
|
|
1459
|
-
const chars = Array.from(
|
|
1460
|
-
if (chars.length > filter.n)
|
|
1461
|
+
const chars = Array.from(text2);
|
|
1462
|
+
if (chars.length > filter.n) text2 = `${chars.slice(0, filter.n).join("")}\u2026`;
|
|
1461
1463
|
break;
|
|
1462
1464
|
}
|
|
1463
1465
|
case "default":
|
|
1464
|
-
if (
|
|
1466
|
+
if (text2 === "") text2 = filter.text;
|
|
1465
1467
|
break;
|
|
1466
1468
|
}
|
|
1467
1469
|
}
|
|
1468
|
-
return
|
|
1470
|
+
return text2;
|
|
1469
1471
|
}
|
|
1470
1472
|
function spend(env, count) {
|
|
1471
1473
|
if (count > env.charsLeft) {
|
|
@@ -1504,17 +1506,17 @@ function attrProp(tag, attr, env, scope) {
|
|
|
1504
1506
|
const safe = safeUrl10(urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
|
|
1505
1507
|
return safe === null || !spend(env, safe.length) ? null : [name, safe];
|
|
1506
1508
|
}
|
|
1507
|
-
const
|
|
1508
|
-
if (
|
|
1509
|
-
let value =
|
|
1509
|
+
const text2 = attrText(attr, env, scope);
|
|
1510
|
+
if (text2 === "" || text2.length > MAX_ATTR_CHARS) return null;
|
|
1511
|
+
let value = text2;
|
|
1510
1512
|
if (name === "class") {
|
|
1511
|
-
const tokens =
|
|
1513
|
+
const tokens = text2.split(/\s+/).filter((token) => CLASS_TOKEN_RE.test(token) && !isReservedClass(token));
|
|
1512
1514
|
if (tokens.length === 0) return null;
|
|
1513
1515
|
value = tokens.join(" ");
|
|
1514
1516
|
} else if (name === "role") {
|
|
1515
|
-
if (!ROLES.has(
|
|
1517
|
+
if (!ROLES.has(text2)) return null;
|
|
1516
1518
|
} else if (name === "aria-hidden") {
|
|
1517
|
-
if (
|
|
1519
|
+
if (text2 !== "true" && text2 !== "false") return null;
|
|
1518
1520
|
}
|
|
1519
1521
|
if (!spend(env, value.length)) return null;
|
|
1520
1522
|
return [name === "class" ? "className" : name, value];
|
|
@@ -1544,8 +1546,8 @@ function renderNodes(nodes, env, scope, depth) {
|
|
|
1544
1546
|
if (spend(env, node.value.length)) out.push(node.value);
|
|
1545
1547
|
break;
|
|
1546
1548
|
case "output": {
|
|
1547
|
-
const
|
|
1548
|
-
if (
|
|
1549
|
+
const text2 = filtered(lookup(node.path, env, scope), node.filters);
|
|
1550
|
+
if (text2 !== "" && spend(env, text2.length)) out.push(text2);
|
|
1549
1551
|
break;
|
|
1550
1552
|
}
|
|
1551
1553
|
case "if": {
|
|
@@ -1917,6 +1919,95 @@ async function loadBuilderPage(options) {
|
|
|
1917
1919
|
return pageOf(found, data);
|
|
1918
1920
|
}
|
|
1919
1921
|
|
|
1922
|
+
// src/next/seo.ts
|
|
1923
|
+
import { safeUrl as safeUrl11 } from "@usethrottle/builder-schema";
|
|
1924
|
+
var isRec = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1925
|
+
var text = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
1926
|
+
var ORIGIN_RE = /^https?:\/\/[^\s/\\]+$/iu;
|
|
1927
|
+
var DEFAULT_PAGE_ROUTE = "/pages/{handle}";
|
|
1928
|
+
var LOCALE_SEGMENT_RE = /^[A-Za-z0-9-]+$/u;
|
|
1929
|
+
function pageSeoOf(page) {
|
|
1930
|
+
const seo = isRec(page.seo) ? page.seo : {};
|
|
1931
|
+
const title = text(seo.title);
|
|
1932
|
+
const description = text(seo.description);
|
|
1933
|
+
return {
|
|
1934
|
+
...title === void 0 ? {} : { title },
|
|
1935
|
+
...description === void 0 ? {} : { description },
|
|
1936
|
+
shareImage: seo.shareImage,
|
|
1937
|
+
noindex: seo.noindex === true
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
function imageOf(value, mediaOrigin) {
|
|
1941
|
+
const raw = isRec(value) ? value.url : value;
|
|
1942
|
+
const url = safeUrl11(raw, "src", { mediaOrigin });
|
|
1943
|
+
if (url === null) return void 0;
|
|
1944
|
+
const frozen = isRec(value) ? value : {};
|
|
1945
|
+
return {
|
|
1946
|
+
url,
|
|
1947
|
+
...typeof frozen.width === "number" ? { width: frozen.width } : {},
|
|
1948
|
+
...typeof frozen.height === "number" ? { height: frozen.height } : {}
|
|
1949
|
+
};
|
|
1950
|
+
}
|
|
1951
|
+
function pagePathOf(settings, page, resolve) {
|
|
1952
|
+
const routes = isRec(settings.routes) ? settings.routes : {};
|
|
1953
|
+
const pattern = text(routes.page) ?? DEFAULT_PAGE_ROUTE;
|
|
1954
|
+
const path = safeUrl11(pattern.replaceAll("{handle}", () => page.slug), "href", { mediaOrigin: "" });
|
|
1955
|
+
if (path === null || resolve === void 0) return path;
|
|
1956
|
+
return safeUrl11(resolve({ ...page, path }), "href", { mediaOrigin: "" }) ?? path;
|
|
1957
|
+
}
|
|
1958
|
+
function originOf(storeUrl) {
|
|
1959
|
+
const origin = storeUrl?.replace(/\/+$/u, "");
|
|
1960
|
+
return origin !== void 0 && ORIGIN_RE.test(origin) ? origin : void 0;
|
|
1961
|
+
}
|
|
1962
|
+
function siteLocales(settings) {
|
|
1963
|
+
const locales = isRec(settings.locales) ? settings.locales : {};
|
|
1964
|
+
const list = Array.isArray(locales.list) ? locales.list.filter((locale) => typeof locale === "string" && LOCALE_SEGMENT_RE.test(locale)) : [];
|
|
1965
|
+
return { list, fallback: typeof locales.default === "string" && list.includes(locales.default) ? locales.default : void 0 };
|
|
1966
|
+
}
|
|
1967
|
+
var localized = (path, locale) => locale === void 0 ? path : path === "/" ? `/${locale}` : `/${locale}${path}`;
|
|
1968
|
+
function metadataOf(page, context) {
|
|
1969
|
+
const { settings, mediaOrigin, routeLocale } = context;
|
|
1970
|
+
const site = isRec(settings.seo) ? settings.seo : {};
|
|
1971
|
+
const brand = isRec(settings.brand) ? settings.brand : {};
|
|
1972
|
+
const own = pageSeoOf(page);
|
|
1973
|
+
const template = text(site.titleTemplate) ?? "{page}";
|
|
1974
|
+
const store = text(brand.storeName) ?? "";
|
|
1975
|
+
const title = template.replaceAll("{page}", () => own.title ?? page.title).replaceAll("{store}", () => store);
|
|
1976
|
+
const description = own.description ?? text(site.defaultDescription);
|
|
1977
|
+
const image = imageOf(own.shareImage, mediaOrigin) ?? imageOf(site.shareImage, mediaOrigin);
|
|
1978
|
+
if (image === void 0 && mediaOrigin === "" && (isRec(own.shareImage) || isRec(site.shareImage)))
|
|
1979
|
+
warnOnce("share-image-origin", "A share image is set but createBuilderPage has no mediaOrigin, so the page has no og:image: pass the same mediaOrigin as loadSite");
|
|
1980
|
+
const origin = originOf(context.storeUrl);
|
|
1981
|
+
if (origin === void 0)
|
|
1982
|
+
warnOnce("canonical-origin", "No canonical link: pass storeUrl (https://shop.example.com) to createBuilderPage. The Builder does not publish the store URL.");
|
|
1983
|
+
const path = pagePathOf(settings, { slug: page.slug, pageType: page.pageType }, context.pagePath);
|
|
1984
|
+
const canonical = origin === void 0 || path === null ? void 0 : `${origin}${localized(path, routeLocale)}`;
|
|
1985
|
+
const { list, fallback } = siteLocales(settings);
|
|
1986
|
+
const languages = origin !== void 0 && path !== null && routeLocale !== void 0 && list.length > 1 ? {
|
|
1987
|
+
...Object.fromEntries(list.map((locale) => [locale, `${origin}${localized(path, locale)}`])),
|
|
1988
|
+
...fallback === void 0 ? {} : { "x-default": `${origin}${localized(path, fallback)}` }
|
|
1989
|
+
} : void 0;
|
|
1990
|
+
return {
|
|
1991
|
+
title,
|
|
1992
|
+
...description === void 0 ? {} : { description },
|
|
1993
|
+
...own.noindex ? { robots: { index: false } } : {},
|
|
1994
|
+
...canonical === void 0 ? {} : { alternates: { canonical, ...languages === void 0 ? {} : { languages } } },
|
|
1995
|
+
openGraph: {
|
|
1996
|
+
type: "website",
|
|
1997
|
+
title,
|
|
1998
|
+
...description === void 0 ? {} : { description },
|
|
1999
|
+
...canonical === void 0 ? {} : { url: canonical },
|
|
2000
|
+
...image === void 0 ? {} : { images: [image] }
|
|
2001
|
+
},
|
|
2002
|
+
twitter: {
|
|
2003
|
+
card: image === void 0 ? "summary" : "summary_large_image",
|
|
2004
|
+
title,
|
|
2005
|
+
...description === void 0 ? {} : { description },
|
|
2006
|
+
...image === void 0 ? {} : { images: [image.url] }
|
|
2007
|
+
}
|
|
2008
|
+
};
|
|
2009
|
+
}
|
|
2010
|
+
|
|
1920
2011
|
export {
|
|
1921
2012
|
warnOnce,
|
|
1922
2013
|
createRendererRegistry,
|
|
@@ -1925,5 +2016,11 @@ export {
|
|
|
1925
2016
|
isRedirect,
|
|
1926
2017
|
getBundle,
|
|
1927
2018
|
clientOf,
|
|
1928
|
-
loadBuilderPage
|
|
2019
|
+
loadBuilderPage,
|
|
2020
|
+
pageSeoOf,
|
|
2021
|
+
pagePathOf,
|
|
2022
|
+
originOf,
|
|
2023
|
+
siteLocales,
|
|
2024
|
+
localized,
|
|
2025
|
+
metadataOf
|
|
1929
2026
|
};
|
|
@@ -644,7 +644,7 @@ function parseRichText(source, mediaOrigin) {
|
|
|
644
644
|
const stack = [root];
|
|
645
645
|
const top = () => stack[stack.length - 1];
|
|
646
646
|
let nodes = 0;
|
|
647
|
-
const
|
|
647
|
+
const text2 = (value) => {
|
|
648
648
|
if (value === "" || nodes > MAX_NODES) return;
|
|
649
649
|
nodes += 1;
|
|
650
650
|
const parent = top();
|
|
@@ -660,10 +660,10 @@ function parseRichText(source, mediaOrigin) {
|
|
|
660
660
|
while (i < html.length && nodes <= MAX_NODES) {
|
|
661
661
|
const lt = html.indexOf("<", i);
|
|
662
662
|
if (lt === -1) {
|
|
663
|
-
|
|
663
|
+
text2(decode(html.slice(i)));
|
|
664
664
|
break;
|
|
665
665
|
}
|
|
666
|
-
|
|
666
|
+
text2(decode(html.slice(i, lt)));
|
|
667
667
|
i = lt;
|
|
668
668
|
if (html.startsWith("<!--", i)) {
|
|
669
669
|
const close = html.indexOf("-->", i + 4);
|
|
@@ -679,7 +679,7 @@ function parseRichText(source, mediaOrigin) {
|
|
|
679
679
|
const close = html.indexOf(">", i);
|
|
680
680
|
i = close === -1 ? html.length : close + 1;
|
|
681
681
|
} else {
|
|
682
|
-
|
|
682
|
+
text2("<");
|
|
683
683
|
i += 1;
|
|
684
684
|
}
|
|
685
685
|
continue;
|
|
@@ -1204,10 +1204,10 @@ var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
|
1204
1204
|
function pickLocale(value, locale) {
|
|
1205
1205
|
const lang = _nullishCoalesce(locale.split("-")[0], () => ( locale));
|
|
1206
1206
|
for (const key of [locale, lang, "en"]) {
|
|
1207
|
-
const
|
|
1208
|
-
if (typeof
|
|
1207
|
+
const text2 = Object.hasOwn(value, key) ? value[key] : void 0;
|
|
1208
|
+
if (typeof text2 === "string" && text2 !== "") return text2;
|
|
1209
1209
|
}
|
|
1210
|
-
for (const
|
|
1210
|
+
for (const text2 of Object.values(value)) if (typeof text2 === "string" && text2 !== "") return text2;
|
|
1211
1211
|
return "";
|
|
1212
1212
|
}
|
|
1213
1213
|
function onOrigin(asset, mediaOrigin) {
|
|
@@ -1354,7 +1354,9 @@ function BuilderRenderer(props) {
|
|
|
1354
1354
|
|
|
1355
1355
|
// src/part-view.tsx
|
|
1356
1356
|
|
|
1357
|
-
var
|
|
1357
|
+
var BoundaryBase = _nullishCoalesce(_react.Component, () => ( class {
|
|
1358
|
+
}));
|
|
1359
|
+
var PartBoundary = class extends BoundaryBase {
|
|
1358
1360
|
constructor() {
|
|
1359
1361
|
super(...arguments);
|
|
1360
1362
|
__publicField(this, "state", { failed: false });
|
|
@@ -1446,26 +1448,26 @@ function asText(value) {
|
|
|
1446
1448
|
return "";
|
|
1447
1449
|
}
|
|
1448
1450
|
function filtered(value, filters) {
|
|
1449
|
-
let
|
|
1451
|
+
let text2 = asText(value);
|
|
1450
1452
|
for (const filter of filters) {
|
|
1451
1453
|
switch (filter.name) {
|
|
1452
1454
|
case "upper":
|
|
1453
|
-
|
|
1455
|
+
text2 = text2.toUpperCase();
|
|
1454
1456
|
break;
|
|
1455
1457
|
case "lower":
|
|
1456
|
-
|
|
1458
|
+
text2 = text2.toLowerCase();
|
|
1457
1459
|
break;
|
|
1458
1460
|
case "truncate": {
|
|
1459
|
-
const chars = Array.from(
|
|
1460
|
-
if (chars.length > filter.n)
|
|
1461
|
+
const chars = Array.from(text2);
|
|
1462
|
+
if (chars.length > filter.n) text2 = `${chars.slice(0, filter.n).join("")}\u2026`;
|
|
1461
1463
|
break;
|
|
1462
1464
|
}
|
|
1463
1465
|
case "default":
|
|
1464
|
-
if (
|
|
1466
|
+
if (text2 === "") text2 = filter.text;
|
|
1465
1467
|
break;
|
|
1466
1468
|
}
|
|
1467
1469
|
}
|
|
1468
|
-
return
|
|
1470
|
+
return text2;
|
|
1469
1471
|
}
|
|
1470
1472
|
function spend(env, count) {
|
|
1471
1473
|
if (count > env.charsLeft) {
|
|
@@ -1504,17 +1506,17 @@ function attrProp(tag, attr, env, scope) {
|
|
|
1504
1506
|
const safe = _builderschema.safeUrl.call(void 0, urlSource(attr, env, scope), name, { mediaOrigin: env.mediaOrigin });
|
|
1505
1507
|
return safe === null || !spend(env, safe.length) ? null : [name, safe];
|
|
1506
1508
|
}
|
|
1507
|
-
const
|
|
1508
|
-
if (
|
|
1509
|
-
let value =
|
|
1509
|
+
const text2 = attrText(attr, env, scope);
|
|
1510
|
+
if (text2 === "" || text2.length > MAX_ATTR_CHARS) return null;
|
|
1511
|
+
let value = text2;
|
|
1510
1512
|
if (name === "class") {
|
|
1511
|
-
const tokens =
|
|
1513
|
+
const tokens = text2.split(/\s+/).filter((token) => _builderschema.CLASS_TOKEN_RE.test(token) && !_builderschema.isReservedClass.call(void 0, token));
|
|
1512
1514
|
if (tokens.length === 0) return null;
|
|
1513
1515
|
value = tokens.join(" ");
|
|
1514
1516
|
} else if (name === "role") {
|
|
1515
|
-
if (!ROLES.has(
|
|
1517
|
+
if (!ROLES.has(text2)) return null;
|
|
1516
1518
|
} else if (name === "aria-hidden") {
|
|
1517
|
-
if (
|
|
1519
|
+
if (text2 !== "true" && text2 !== "false") return null;
|
|
1518
1520
|
}
|
|
1519
1521
|
if (!spend(env, value.length)) return null;
|
|
1520
1522
|
return [name === "class" ? "className" : name, value];
|
|
@@ -1544,8 +1546,8 @@ function renderNodes(nodes, env, scope, depth) {
|
|
|
1544
1546
|
if (spend(env, node.value.length)) out.push(node.value);
|
|
1545
1547
|
break;
|
|
1546
1548
|
case "output": {
|
|
1547
|
-
const
|
|
1548
|
-
if (
|
|
1549
|
+
const text2 = filtered(lookup(node.path, env, scope), node.filters);
|
|
1550
|
+
if (text2 !== "" && spend(env, text2.length)) out.push(text2);
|
|
1549
1551
|
break;
|
|
1550
1552
|
}
|
|
1551
1553
|
case "if": {
|
|
@@ -1917,6 +1919,101 @@ async function loadBuilderPage(options) {
|
|
|
1917
1919
|
return pageOf(found, data);
|
|
1918
1920
|
}
|
|
1919
1921
|
|
|
1922
|
+
// src/next/seo.ts
|
|
1923
|
+
|
|
1924
|
+
var isRec = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1925
|
+
var text = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
1926
|
+
var ORIGIN_RE = /^https?:\/\/[^\s/\\]+$/iu;
|
|
1927
|
+
var DEFAULT_PAGE_ROUTE = "/pages/{handle}";
|
|
1928
|
+
var LOCALE_SEGMENT_RE = /^[A-Za-z0-9-]+$/u;
|
|
1929
|
+
function pageSeoOf(page) {
|
|
1930
|
+
const seo = isRec(page.seo) ? page.seo : {};
|
|
1931
|
+
const title = text(seo.title);
|
|
1932
|
+
const description = text(seo.description);
|
|
1933
|
+
return {
|
|
1934
|
+
...title === void 0 ? {} : { title },
|
|
1935
|
+
...description === void 0 ? {} : { description },
|
|
1936
|
+
shareImage: seo.shareImage,
|
|
1937
|
+
noindex: seo.noindex === true
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
function imageOf(value, mediaOrigin) {
|
|
1941
|
+
const raw = isRec(value) ? value.url : value;
|
|
1942
|
+
const url = _builderschema.safeUrl.call(void 0, raw, "src", { mediaOrigin });
|
|
1943
|
+
if (url === null) return void 0;
|
|
1944
|
+
const frozen = isRec(value) ? value : {};
|
|
1945
|
+
return {
|
|
1946
|
+
url,
|
|
1947
|
+
...typeof frozen.width === "number" ? { width: frozen.width } : {},
|
|
1948
|
+
...typeof frozen.height === "number" ? { height: frozen.height } : {}
|
|
1949
|
+
};
|
|
1950
|
+
}
|
|
1951
|
+
function pagePathOf(settings, page, resolve) {
|
|
1952
|
+
const routes = isRec(settings.routes) ? settings.routes : {};
|
|
1953
|
+
const pattern = _nullishCoalesce(text(routes.page), () => ( DEFAULT_PAGE_ROUTE));
|
|
1954
|
+
const path = _builderschema.safeUrl.call(void 0, pattern.replaceAll("{handle}", () => page.slug), "href", { mediaOrigin: "" });
|
|
1955
|
+
if (path === null || resolve === void 0) return path;
|
|
1956
|
+
return _nullishCoalesce(_builderschema.safeUrl.call(void 0, resolve({ ...page, path }), "href", { mediaOrigin: "" }), () => ( path));
|
|
1957
|
+
}
|
|
1958
|
+
function originOf(storeUrl) {
|
|
1959
|
+
const origin = _optionalChain([storeUrl, 'optionalAccess', _84 => _84.replace, 'call', _85 => _85(/\/+$/u, "")]);
|
|
1960
|
+
return origin !== void 0 && ORIGIN_RE.test(origin) ? origin : void 0;
|
|
1961
|
+
}
|
|
1962
|
+
function siteLocales(settings) {
|
|
1963
|
+
const locales = isRec(settings.locales) ? settings.locales : {};
|
|
1964
|
+
const list = Array.isArray(locales.list) ? locales.list.filter((locale) => typeof locale === "string" && LOCALE_SEGMENT_RE.test(locale)) : [];
|
|
1965
|
+
return { list, fallback: typeof locales.default === "string" && list.includes(locales.default) ? locales.default : void 0 };
|
|
1966
|
+
}
|
|
1967
|
+
var localized = (path, locale) => locale === void 0 ? path : path === "/" ? `/${locale}` : `/${locale}${path}`;
|
|
1968
|
+
function metadataOf(page, context) {
|
|
1969
|
+
const { settings, mediaOrigin, routeLocale } = context;
|
|
1970
|
+
const site = isRec(settings.seo) ? settings.seo : {};
|
|
1971
|
+
const brand = isRec(settings.brand) ? settings.brand : {};
|
|
1972
|
+
const own = pageSeoOf(page);
|
|
1973
|
+
const template = _nullishCoalesce(text(site.titleTemplate), () => ( "{page}"));
|
|
1974
|
+
const store = _nullishCoalesce(text(brand.storeName), () => ( ""));
|
|
1975
|
+
const title = template.replaceAll("{page}", () => _nullishCoalesce(own.title, () => ( page.title))).replaceAll("{store}", () => store);
|
|
1976
|
+
const description = _nullishCoalesce(own.description, () => ( text(site.defaultDescription)));
|
|
1977
|
+
const image = _nullishCoalesce(imageOf(own.shareImage, mediaOrigin), () => ( imageOf(site.shareImage, mediaOrigin)));
|
|
1978
|
+
if (image === void 0 && mediaOrigin === "" && (isRec(own.shareImage) || isRec(site.shareImage)))
|
|
1979
|
+
warnOnce("share-image-origin", "A share image is set but createBuilderPage has no mediaOrigin, so the page has no og:image: pass the same mediaOrigin as loadSite");
|
|
1980
|
+
const origin = originOf(context.storeUrl);
|
|
1981
|
+
if (origin === void 0)
|
|
1982
|
+
warnOnce("canonical-origin", "No canonical link: pass storeUrl (https://shop.example.com) to createBuilderPage. The Builder does not publish the store URL.");
|
|
1983
|
+
const path = pagePathOf(settings, { slug: page.slug, pageType: page.pageType }, context.pagePath);
|
|
1984
|
+
const canonical = origin === void 0 || path === null ? void 0 : `${origin}${localized(path, routeLocale)}`;
|
|
1985
|
+
const { list, fallback } = siteLocales(settings);
|
|
1986
|
+
const languages = origin !== void 0 && path !== null && routeLocale !== void 0 && list.length > 1 ? {
|
|
1987
|
+
...Object.fromEntries(list.map((locale) => [locale, `${origin}${localized(path, locale)}`])),
|
|
1988
|
+
...fallback === void 0 ? {} : { "x-default": `${origin}${localized(path, fallback)}` }
|
|
1989
|
+
} : void 0;
|
|
1990
|
+
return {
|
|
1991
|
+
title,
|
|
1992
|
+
...description === void 0 ? {} : { description },
|
|
1993
|
+
...own.noindex ? { robots: { index: false } } : {},
|
|
1994
|
+
...canonical === void 0 ? {} : { alternates: { canonical, ...languages === void 0 ? {} : { languages } } },
|
|
1995
|
+
openGraph: {
|
|
1996
|
+
type: "website",
|
|
1997
|
+
title,
|
|
1998
|
+
...description === void 0 ? {} : { description },
|
|
1999
|
+
...canonical === void 0 ? {} : { url: canonical },
|
|
2000
|
+
...image === void 0 ? {} : { images: [image] }
|
|
2001
|
+
},
|
|
2002
|
+
twitter: {
|
|
2003
|
+
card: image === void 0 ? "summary" : "summary_large_image",
|
|
2004
|
+
title,
|
|
2005
|
+
...description === void 0 ? {} : { description },
|
|
2006
|
+
...image === void 0 ? {} : { images: [image.url] }
|
|
2007
|
+
}
|
|
2008
|
+
};
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
|
|
2012
|
+
|
|
2013
|
+
|
|
2014
|
+
|
|
2015
|
+
|
|
2016
|
+
|
|
1920
2017
|
|
|
1921
2018
|
|
|
1922
2019
|
|
|
@@ -1926,4 +2023,4 @@ async function loadBuilderPage(options) {
|
|
|
1926
2023
|
|
|
1927
2024
|
|
|
1928
2025
|
|
|
1929
|
-
exports.warnOnce = warnOnce; exports.createRendererRegistry = createRendererRegistry; exports.staticDataFor = staticDataFor; exports.partOf = partOf; exports.isRedirect = isRedirect; exports.getBundle = getBundle; exports.clientOf = clientOf; exports.loadBuilderPage = loadBuilderPage;
|
|
2026
|
+
exports.warnOnce = warnOnce; exports.createRendererRegistry = createRendererRegistry; exports.staticDataFor = staticDataFor; exports.partOf = partOf; exports.isRedirect = isRedirect; exports.getBundle = getBundle; exports.clientOf = clientOf; exports.loadBuilderPage = loadBuilderPage; exports.pageSeoOf = pageSeoOf; exports.pagePathOf = pagePathOf; exports.originOf = originOf; exports.siteLocales = siteLocales; exports.localized = localized; exports.metadataOf = metadataOf;
|
package/dist/index.cjs
CHANGED
|
@@ -817,7 +817,9 @@ function Redirect({ to }) {
|
|
|
817
817
|
// src/part-view.tsx
|
|
818
818
|
var import_react5 = require("react");
|
|
819
819
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
820
|
-
var
|
|
820
|
+
var BoundaryBase = import_react5.Component ?? class {
|
|
821
|
+
};
|
|
822
|
+
var PartBoundary = class extends BoundaryBase {
|
|
821
823
|
constructor() {
|
|
822
824
|
super(...arguments);
|
|
823
825
|
__publicField(this, "state", { failed: false });
|
package/dist/index.d.cts
CHANGED
|
@@ -21,6 +21,12 @@ declare class RenderBudget {
|
|
|
21
21
|
get used(): number;
|
|
22
22
|
get exhausted(): boolean;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* What a renderer needs of a budget: the public members of `RenderBudget`, not the class. The server entries' type
|
|
26
|
+
* files carry their own copy of the class, and its private field would make a pack made against one copy unusable
|
|
27
|
+
* with the other (`loadSite({ packs })`).
|
|
28
|
+
*/
|
|
29
|
+
type Budget = Pick<RenderBudget, 'limit' | 'used' | 'exhausted' | 'take'>;
|
|
24
30
|
/** True when a template's worst case fits the budget; the interpreter refuses the template otherwise. */
|
|
25
31
|
declare const fitsBudget: (ast: TemplateAst, limit?: number) => boolean;
|
|
26
32
|
|
|
@@ -44,7 +50,7 @@ type WidgetRenderProps = {
|
|
|
44
50
|
[key: string]: unknown;
|
|
45
51
|
}) => string | null) | undefined;
|
|
46
52
|
/** Custom widgets only: the node budget of this render (`MAX_RENDERED_NODES`). */
|
|
47
|
-
budget?:
|
|
53
|
+
budget?: Budget | undefined;
|
|
48
54
|
};
|
|
49
55
|
type EditModeHooks = {
|
|
50
56
|
onSelect(id: string): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,12 @@ declare class RenderBudget {
|
|
|
21
21
|
get used(): number;
|
|
22
22
|
get exhausted(): boolean;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* What a renderer needs of a budget: the public members of `RenderBudget`, not the class. The server entries' type
|
|
26
|
+
* files carry their own copy of the class, and its private field would make a pack made against one copy unusable
|
|
27
|
+
* with the other (`loadSite({ packs })`).
|
|
28
|
+
*/
|
|
29
|
+
type Budget = Pick<RenderBudget, 'limit' | 'used' | 'exhausted' | 'take'>;
|
|
24
30
|
/** True when a template's worst case fits the budget; the interpreter refuses the template otherwise. */
|
|
25
31
|
declare const fitsBudget: (ast: TemplateAst, limit?: number) => boolean;
|
|
26
32
|
|
|
@@ -44,7 +50,7 @@ type WidgetRenderProps = {
|
|
|
44
50
|
[key: string]: unknown;
|
|
45
51
|
}) => string | null) | undefined;
|
|
46
52
|
/** Custom widgets only: the node budget of this render (`MAX_RENDERED_NODES`). */
|
|
47
|
-
budget?:
|
|
53
|
+
budget?: Budget | undefined;
|
|
48
54
|
};
|
|
49
55
|
type EditModeHooks = {
|
|
50
56
|
onSelect(id: string): void;
|
package/dist/index.js
CHANGED
|
@@ -769,7 +769,9 @@ function Redirect({ to }) {
|
|
|
769
769
|
// src/part-view.tsx
|
|
770
770
|
import { Component } from "react";
|
|
771
771
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
772
|
-
var
|
|
772
|
+
var BoundaryBase = Component ?? class {
|
|
773
|
+
};
|
|
774
|
+
var PartBoundary = class extends BoundaryBase {
|
|
773
775
|
constructor() {
|
|
774
776
|
super(...arguments);
|
|
775
777
|
__publicField(this, "state", { failed: false });
|
package/dist/next.cjs
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
var _chunkS2XR224Acjs = require('./chunk-S2XR224A.cjs');
|
|
7
8
|
|
|
8
9
|
// src/next/index.ts
|
|
9
10
|
var _react = require('react');
|
|
@@ -48,7 +49,7 @@ function createBuilderPage(options) {
|
|
|
48
49
|
async function Page(props) {
|
|
49
50
|
const params = await props.params;
|
|
50
51
|
const slug = slugOf(options, params);
|
|
51
|
-
const loaded = await
|
|
52
|
+
const loaded = await _chunkS2XR224Acjs.loadBuilderPage.call(void 0, {
|
|
52
53
|
...options,
|
|
53
54
|
slug,
|
|
54
55
|
locale: await localeOf(options, params)
|
|
@@ -67,24 +68,21 @@ function createBuilderPage(options) {
|
|
|
67
68
|
const params = await props.params;
|
|
68
69
|
const slug = slugOf(options, params);
|
|
69
70
|
const locale = await localeOf(options, params);
|
|
71
|
+
const client = _chunkS2XR224Acjs.clientOf.call(void 0, options);
|
|
70
72
|
try {
|
|
71
|
-
const bundle = await
|
|
73
|
+
const bundle = await _chunkS2XR224Acjs.getBundle.call(void 0, { client, locale, page: slug, slots: options.slots });
|
|
72
74
|
const page = bundle.page;
|
|
73
|
-
if (page === void 0 ||
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const description = _nullishCoalesce(own, () => ( fallback));
|
|
82
|
-
return {
|
|
83
|
-
title: template.replace("{page}", page.title).replace("{store}", store),
|
|
84
|
-
...description === void 0 || description === "" ? {} : { description }
|
|
85
|
-
};
|
|
75
|
+
if (page === void 0 || _chunkS2XR224Acjs.isRedirect.call(void 0, page)) return {};
|
|
76
|
+
return _chunkS2XR224Acjs.metadataOf.call(void 0, page, {
|
|
77
|
+
settings: bundle.site.settings,
|
|
78
|
+
mediaOrigin: _nullishCoalesce(options.mediaOrigin, () => ( "")),
|
|
79
|
+
storeUrl: options.storeUrl,
|
|
80
|
+
pagePath: options.pagePath,
|
|
81
|
+
routeLocale: options.locale === void 0 && typeof params.locale === "string" ? params.locale : void 0
|
|
82
|
+
});
|
|
86
83
|
} catch (error) {
|
|
87
|
-
if (error instanceof _builder.BuilderNotFoundError
|
|
84
|
+
if (error instanceof _builder.BuilderNotFoundError) return {};
|
|
85
|
+
if (error instanceof _builder.BuilderUnavailableError && client.mode !== "build") return {};
|
|
88
86
|
throw error;
|
|
89
87
|
}
|
|
90
88
|
}
|
package/dist/next.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { Metadata } from 'next';
|
|
3
|
-
import { C as ClientOptions, W as WidgetPack } from './
|
|
3
|
+
import { C as ClientOptions, W as WidgetPack, P as PagePathResolver } from './seo-Dz439Jlk.cjs';
|
|
4
4
|
import '@usethrottle/builder-schema';
|
|
5
5
|
import '@usethrottle/builder';
|
|
6
6
|
|
|
@@ -15,6 +15,17 @@ type CreateBuilderPageOptions = ({
|
|
|
15
15
|
locale?: string | ((params: Params) => string | Promise<string>);
|
|
16
16
|
/** The slots the layout reads, so the page read can share the layout's. */
|
|
17
17
|
slots?: readonly string[];
|
|
18
|
+
/** The store's origin (`https://shop.example.com`), for the canonical link. The Builder does not publish it, so without it a page has no canonical. */
|
|
19
|
+
storeUrl?: string;
|
|
20
|
+
/** The origin of the store's media, as for `loadSite({ mediaOrigin })`. A share image on any other origin is left out. */
|
|
21
|
+
mediaOrigin?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Where your store serves a page, for the canonical link. By default the site's page route with the slug
|
|
24
|
+
* (`/pages/home` for the home page). A store that serves its home page at `/` says so:
|
|
25
|
+
* `pagePath: (page) => (page.pageType === 'home' ? '/' : page.path)`. `path` is the default. An invalid
|
|
26
|
+
* answer (not a path on this site) is ignored. Pass the same function to `builderSitemap`.
|
|
27
|
+
*/
|
|
28
|
+
pagePath?: PagePathResolver;
|
|
18
29
|
};
|
|
19
30
|
type PageProps = {
|
|
20
31
|
params: Promise<Params> | Params;
|
package/dist/next.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { Metadata } from 'next';
|
|
3
|
-
import { C as ClientOptions, W as WidgetPack } from './
|
|
3
|
+
import { C as ClientOptions, W as WidgetPack, P as PagePathResolver } from './seo-Dz439Jlk.js';
|
|
4
4
|
import '@usethrottle/builder-schema';
|
|
5
5
|
import '@usethrottle/builder';
|
|
6
6
|
|
|
@@ -15,6 +15,17 @@ type CreateBuilderPageOptions = ({
|
|
|
15
15
|
locale?: string | ((params: Params) => string | Promise<string>);
|
|
16
16
|
/** The slots the layout reads, so the page read can share the layout's. */
|
|
17
17
|
slots?: readonly string[];
|
|
18
|
+
/** The store's origin (`https://shop.example.com`), for the canonical link. The Builder does not publish it, so without it a page has no canonical. */
|
|
19
|
+
storeUrl?: string;
|
|
20
|
+
/** The origin of the store's media, as for `loadSite({ mediaOrigin })`. A share image on any other origin is left out. */
|
|
21
|
+
mediaOrigin?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Where your store serves a page, for the canonical link. By default the site's page route with the slug
|
|
24
|
+
* (`/pages/home` for the home page). A store that serves its home page at `/` says so:
|
|
25
|
+
* `pagePath: (page) => (page.pageType === 'home' ? '/' : page.path)`. `path` is the default. An invalid
|
|
26
|
+
* answer (not a path on this site) is ignored. Pass the same function to `builderSitemap`.
|
|
27
|
+
*/
|
|
28
|
+
pagePath?: PagePathResolver;
|
|
18
29
|
};
|
|
19
30
|
type PageProps = {
|
|
20
31
|
params: Promise<Params> | Params;
|
package/dist/next.js
CHANGED
|
@@ -2,8 +2,9 @@ import {
|
|
|
2
2
|
clientOf,
|
|
3
3
|
getBundle,
|
|
4
4
|
isRedirect,
|
|
5
|
-
loadBuilderPage
|
|
6
|
-
|
|
5
|
+
loadBuilderPage,
|
|
6
|
+
metadataOf
|
|
7
|
+
} from "./chunk-NUE2KNT2.js";
|
|
7
8
|
|
|
8
9
|
// src/next/index.ts
|
|
9
10
|
import { createElement } from "react";
|
|
@@ -67,24 +68,21 @@ function createBuilderPage(options) {
|
|
|
67
68
|
const params = await props.params;
|
|
68
69
|
const slug = slugOf(options, params);
|
|
69
70
|
const locale = await localeOf(options, params);
|
|
71
|
+
const client = clientOf(options);
|
|
70
72
|
try {
|
|
71
|
-
const bundle = await getBundle({ client
|
|
73
|
+
const bundle = await getBundle({ client, locale, page: slug, slots: options.slots });
|
|
72
74
|
const page = bundle.page;
|
|
73
75
|
if (page === void 0 || isRedirect(page)) return {};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const description = own ?? fallback;
|
|
82
|
-
return {
|
|
83
|
-
title: template.replace("{page}", page.title).replace("{store}", store),
|
|
84
|
-
...description === void 0 || description === "" ? {} : { description }
|
|
85
|
-
};
|
|
76
|
+
return metadataOf(page, {
|
|
77
|
+
settings: bundle.site.settings,
|
|
78
|
+
mediaOrigin: options.mediaOrigin ?? "",
|
|
79
|
+
storeUrl: options.storeUrl,
|
|
80
|
+
pagePath: options.pagePath,
|
|
81
|
+
routeLocale: options.locale === void 0 && typeof params.locale === "string" ? params.locale : void 0
|
|
82
|
+
});
|
|
86
83
|
} catch (error) {
|
|
87
|
-
if (error instanceof BuilderNotFoundError
|
|
84
|
+
if (error instanceof BuilderNotFoundError) return {};
|
|
85
|
+
if (error instanceof BuilderUnavailableError && client.mode !== "build") return {};
|
|
88
86
|
throw error;
|
|
89
87
|
}
|
|
90
88
|
}
|
|
@@ -12,6 +12,12 @@ declare class RenderBudget {
|
|
|
12
12
|
get used(): number;
|
|
13
13
|
get exhausted(): boolean;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* What a renderer needs of a budget: the public members of `RenderBudget`, not the class. The server entries' type
|
|
17
|
+
* files carry their own copy of the class, and its private field would make a pack made against one copy unusable
|
|
18
|
+
* with the other (`loadSite({ packs })`).
|
|
19
|
+
*/
|
|
20
|
+
type Budget = Pick<RenderBudget, 'limit' | 'used' | 'exhausted' | 'take'>;
|
|
15
21
|
|
|
16
22
|
/** Resolved data by binding key (`bindingKey`), plus `context.*` entries a slot supplies. */
|
|
17
23
|
type DataMap = Record<string, unknown>;
|
|
@@ -33,7 +39,7 @@ type WidgetRenderProps = {
|
|
|
33
39
|
[key: string]: unknown;
|
|
34
40
|
}) => string | null) | undefined;
|
|
35
41
|
/** Custom widgets only: the node budget of this render (`MAX_RENDERED_NODES`). */
|
|
36
|
-
budget?:
|
|
42
|
+
budget?: Budget | undefined;
|
|
37
43
|
};
|
|
38
44
|
type ResolveContext = {
|
|
39
45
|
locale: string;
|
|
@@ -133,4 +139,11 @@ type ClientOptions = {
|
|
|
133
139
|
builderKey?: string | undefined;
|
|
134
140
|
};
|
|
135
141
|
|
|
136
|
-
|
|
142
|
+
/** A store's own answer for where a page lives: it gets the default and returns a site path (or null for the default). */
|
|
143
|
+
type PagePathResolver = (page: {
|
|
144
|
+
slug: string;
|
|
145
|
+
pageType: string;
|
|
146
|
+
path: string;
|
|
147
|
+
}) => string | null | undefined;
|
|
148
|
+
|
|
149
|
+
export { type BundleAsk as B, type ClientOptions as C, type LoadedPage as L, type PagePathResolver as P, type WidgetPack as W, type LoadedRedirect as a, type LoadedSite as b, getBundle as g };
|
|
@@ -12,6 +12,12 @@ declare class RenderBudget {
|
|
|
12
12
|
get used(): number;
|
|
13
13
|
get exhausted(): boolean;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* What a renderer needs of a budget: the public members of `RenderBudget`, not the class. The server entries' type
|
|
17
|
+
* files carry their own copy of the class, and its private field would make a pack made against one copy unusable
|
|
18
|
+
* with the other (`loadSite({ packs })`).
|
|
19
|
+
*/
|
|
20
|
+
type Budget = Pick<RenderBudget, 'limit' | 'used' | 'exhausted' | 'take'>;
|
|
15
21
|
|
|
16
22
|
/** Resolved data by binding key (`bindingKey`), plus `context.*` entries a slot supplies. */
|
|
17
23
|
type DataMap = Record<string, unknown>;
|
|
@@ -33,7 +39,7 @@ type WidgetRenderProps = {
|
|
|
33
39
|
[key: string]: unknown;
|
|
34
40
|
}) => string | null) | undefined;
|
|
35
41
|
/** Custom widgets only: the node budget of this render (`MAX_RENDERED_NODES`). */
|
|
36
|
-
budget?:
|
|
42
|
+
budget?: Budget | undefined;
|
|
37
43
|
};
|
|
38
44
|
type ResolveContext = {
|
|
39
45
|
locale: string;
|
|
@@ -133,4 +139,11 @@ type ClientOptions = {
|
|
|
133
139
|
builderKey?: string | undefined;
|
|
134
140
|
};
|
|
135
141
|
|
|
136
|
-
|
|
142
|
+
/** A store's own answer for where a page lives: it gets the default and returns a site path (or null for the default). */
|
|
143
|
+
type PagePathResolver = (page: {
|
|
144
|
+
slug: string;
|
|
145
|
+
pageType: string;
|
|
146
|
+
path: string;
|
|
147
|
+
}) => string | null | undefined;
|
|
148
|
+
|
|
149
|
+
export { type BundleAsk as B, type ClientOptions as C, type LoadedPage as L, type PagePathResolver as P, type WidgetPack as W, type LoadedRedirect as a, type LoadedSite as b, getBundle as g };
|
package/dist/server.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -6,25 +6,31 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkS2XR224Acjs = require('./chunk-S2XR224A.cjs');
|
|
10
16
|
|
|
11
17
|
// src/server/load-site.ts
|
|
12
18
|
var _builder = require('@usethrottle/builder');
|
|
13
19
|
async function loadSite(options) {
|
|
14
20
|
const { locale, slots = [], packs = [], page, mediaOrigin = "" } = options;
|
|
15
|
-
const client =
|
|
21
|
+
const client = _chunkS2XR224Acjs.clientOf.call(void 0, options);
|
|
16
22
|
let bundle;
|
|
17
23
|
try {
|
|
18
|
-
bundle = await
|
|
24
|
+
bundle = await _chunkS2XR224Acjs.getBundle.call(void 0, { client, locale, slots, page });
|
|
19
25
|
} catch (error) {
|
|
20
|
-
if (!(error instanceof _builder.BuilderUnavailableError)) throw error;
|
|
21
|
-
|
|
26
|
+
if (!(error instanceof _builder.BuilderUnavailableError) || client.mode === "build") throw error;
|
|
27
|
+
_chunkS2XR224Acjs.warnOnce.call(void 0, "site-unavailable", `The Builder could not be read (${error.reason}); the store renders without its Builder header, footer and slots`);
|
|
22
28
|
return { status: "unavailable", locale };
|
|
23
29
|
}
|
|
24
|
-
const registry =
|
|
30
|
+
const registry = _chunkS2XR224Acjs.createRendererRegistry.call(void 0, packs);
|
|
25
31
|
const names = Object.keys(bundle.slots);
|
|
26
32
|
const documents = [bundle.header.document, bundle.footer.document, ...names.map((n) => bundle.slots[n].document)];
|
|
27
|
-
const data = await
|
|
33
|
+
const data = await _chunkS2XR224Acjs.staticDataFor.call(void 0, documents, registry, locale);
|
|
28
34
|
return {
|
|
29
35
|
status: "ok",
|
|
30
36
|
locale,
|
|
@@ -32,35 +38,72 @@ async function loadSite(options) {
|
|
|
32
38
|
siteVersion: bundle.site.siteVersion,
|
|
33
39
|
mediaOrigin,
|
|
34
40
|
settings: bundle.site.settings,
|
|
35
|
-
header:
|
|
36
|
-
footer:
|
|
37
|
-
slots: Object.fromEntries(names.map((name) => [name,
|
|
41
|
+
header: _chunkS2XR224Acjs.partOf.call(void 0, bundle.header, data),
|
|
42
|
+
footer: _chunkS2XR224Acjs.partOf.call(void 0, bundle.footer, data),
|
|
43
|
+
slots: Object.fromEntries(names.map((name) => [name, _chunkS2XR224Acjs.partOf.call(void 0, bundle.slots[name], data)]))
|
|
38
44
|
};
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
// src/server/sitemap.ts
|
|
42
48
|
|
|
43
49
|
async function builderSitemap(options) {
|
|
44
|
-
const client =
|
|
50
|
+
const client = _chunkS2XR224Acjs.clientOf.call(void 0, options);
|
|
51
|
+
const origin = _chunkS2XR224Acjs.originOf.call(void 0, options.storeUrl);
|
|
52
|
+
if (origin === void 0) {
|
|
53
|
+
_chunkS2XR224Acjs.warnOnce.call(void 0, "sitemap-origin", "builderSitemap needs a storeUrl (https://shop.example.com) that is an http(s) origin. The Builder does not publish the store URL.");
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
const locale = _nullishCoalesce(options.locale, () => ( "en"));
|
|
45
57
|
try {
|
|
46
58
|
const pages = await client.pages.list();
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
const base = origin.replace(/\/+$/u, "");
|
|
57
|
-
return pages.map((page) => ({ url: `${base}${page.path}`, lastModified: new Date(page.updatedAt) }));
|
|
59
|
+
const { settings } = await client.site({ locale });
|
|
60
|
+
const indexable = await withoutNoindex(client, pages, locale);
|
|
61
|
+
const { list } = _chunkS2XR224Acjs.siteLocales.call(void 0, settings);
|
|
62
|
+
const prefixes = options.localeRoute !== true ? [void 0] : list.length > 0 ? list : [locale];
|
|
63
|
+
return indexable.flatMap((page) => {
|
|
64
|
+
const path = _chunkS2XR224Acjs.pagePathOf.call(void 0, settings, page, options.pagePath);
|
|
65
|
+
if (path === null) return [];
|
|
66
|
+
return prefixes.map((prefix) => ({ url: `${origin}${_chunkS2XR224Acjs.localized.call(void 0, path, prefix)}`, lastModified: new Date(page.updatedAt) }));
|
|
67
|
+
});
|
|
58
68
|
} catch (error) {
|
|
59
|
-
if (!(error instanceof _builder.BuilderUnavailableError)) throw error;
|
|
60
|
-
|
|
69
|
+
if (!(error instanceof _builder.BuilderUnavailableError) || client.mode === "build") throw error;
|
|
70
|
+
_chunkS2XR224Acjs.warnOnce.call(void 0, "sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
|
|
61
71
|
return [];
|
|
62
72
|
}
|
|
63
73
|
}
|
|
74
|
+
var READ_AT_ONCE = 8;
|
|
75
|
+
async function withoutNoindex(client, pages, locale) {
|
|
76
|
+
const unknown = pages.filter((page) => typeof page.noindex !== "boolean");
|
|
77
|
+
const skip = new Set(pages.filter((page) => page.noindex === true).map((page) => page.slug));
|
|
78
|
+
for (let from = 0; from < unknown.length; from += READ_AT_ONCE) {
|
|
79
|
+
const slice = unknown.slice(from, from + READ_AT_ONCE);
|
|
80
|
+
const answers = await Promise.all(
|
|
81
|
+
slice.map(
|
|
82
|
+
(page) => client.pages.get(page.slug, { locale }).catch((error) => {
|
|
83
|
+
if (error instanceof _builder.BuilderNotFoundError) return "gone";
|
|
84
|
+
_chunkS2XR224Acjs.warnOnce.call(void 0, "sitemap-page-read", `A page could not be read for the sitemap (${error instanceof Error ? error.message : "unknown error"}); it stays listed`);
|
|
85
|
+
return void 0;
|
|
86
|
+
})
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
slice.forEach((page, index) => {
|
|
90
|
+
const answer = answers[index];
|
|
91
|
+
if (answer === "gone" || answer !== void 0 && (_chunkS2XR224Acjs.isRedirect.call(void 0, answer) || _chunkS2XR224Acjs.pageSeoOf.call(void 0, answer).noindex)) skip.add(page.slug);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return pages.filter((page) => !skip.has(page.slug));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/server/static-params.ts
|
|
98
|
+
async function builderStaticParams(options) {
|
|
99
|
+
const client = _chunkS2XR224Acjs.clientOf.call(void 0, options);
|
|
100
|
+
if (client.mode !== "build")
|
|
101
|
+
throw new TypeError(
|
|
102
|
+
'builderStaticParams generates every page of a frozen release: give it a client made with createBuilderClient({ mode: "build" }). A live store keeps its pages dynamic.'
|
|
103
|
+
);
|
|
104
|
+
const pages = await client.pages.list();
|
|
105
|
+
return pages.map((page) => ({ [_nullishCoalesce(options.param, () => ( "handle"))]: page.slug }));
|
|
106
|
+
}
|
|
64
107
|
|
|
65
108
|
// src/server/index.ts
|
|
66
109
|
|
|
@@ -71,4 +114,5 @@ async function builderSitemap(options) {
|
|
|
71
114
|
|
|
72
115
|
|
|
73
116
|
|
|
74
|
-
|
|
117
|
+
|
|
118
|
+
exports.BuilderNotFoundError = _builder.BuilderNotFoundError; exports.BuilderUnavailableError = _builder.BuilderUnavailableError; exports.builderSitemap = builderSitemap; exports.builderStaticParams = builderStaticParams; exports.getBundle = _chunkS2XR224Acjs.getBundle; exports.loadBuilderPage = _chunkS2XR224Acjs.loadBuilderPage; exports.loadSite = loadSite;
|
package/dist/server.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ClientOptions, W as WidgetPack, b as LoadedSite, L as LoadedPage, a as LoadedRedirect } from './
|
|
2
|
-
export { B as BundleAsk, g as getBundle } from './
|
|
1
|
+
import { C as ClientOptions, W as WidgetPack, b as LoadedSite, L as LoadedPage, a as LoadedRedirect, P as PagePathResolver } from './seo-Dz439Jlk.cjs';
|
|
2
|
+
export { B as BundleAsk, g as getBundle } from './seo-Dz439Jlk.cjs';
|
|
3
3
|
export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
|
|
4
4
|
import 'react';
|
|
5
5
|
import '@usethrottle/builder-schema';
|
|
@@ -24,7 +24,8 @@ type LoadSiteOptions = ClientOptions & {
|
|
|
24
24
|
* When the Builder cannot answer and there is no last good answer it returns
|
|
25
25
|
* `{ status: 'unavailable' }` and logs once per process: the store's header,
|
|
26
26
|
* footer and slots then render nothing and the catalog pages keep working
|
|
27
|
-
* (ruling R8). Any other error (a bad key, a programming error) is thrown
|
|
27
|
+
* (ruling R8). Any other error (a bad key, a programming error) is thrown, and
|
|
28
|
+
* so is every error of a build-mode client (`createBuilderClient({ mode: 'build' })`).
|
|
28
29
|
*/
|
|
29
30
|
declare function loadSite(options: LoadSiteOptions): Promise<LoadedSite>;
|
|
30
31
|
|
|
@@ -47,13 +48,41 @@ type LoadBuilderPageOptions = ClientOptions & {
|
|
|
47
48
|
declare function loadBuilderPage(options: LoadBuilderPageOptions): Promise<LoadedPage | LoadedRedirect>;
|
|
48
49
|
|
|
49
50
|
type BuilderSitemapOptions = ClientOptions & {
|
|
50
|
-
/** The store's origin (`https://shop.example.com`).
|
|
51
|
+
/** 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. */
|
|
51
52
|
storeUrl?: string;
|
|
53
|
+
/** The locale the site settings (and, for an older Builder, the pages) are read in, as for `createBuilderPage` (`en` by default). */
|
|
54
|
+
locale?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Your routes have a `[locale]` segment (`app/[locale]/pages/[handle]`), as the canonical links assume when the
|
|
57
|
+
* locale comes from the route. Each page is then listed once per site locale, under `/<locale>`.
|
|
58
|
+
*/
|
|
59
|
+
localeRoute?: boolean;
|
|
60
|
+
/** Where your store serves a page, as for `createBuilderPage`. Pass the same function. */
|
|
61
|
+
pagePath?: PagePathResolver;
|
|
52
62
|
};
|
|
53
|
-
/** The published pages as sitemap entries. An unavailable Builder gives an empty list, never a failed sitemap. */
|
|
63
|
+
/** The published pages as sitemap entries. An unavailable Builder gives an empty list, never a failed sitemap (a build-mode client fails the build instead). */
|
|
54
64
|
declare function builderSitemap(options: BuilderSitemapOptions): Promise<{
|
|
55
65
|
url: string;
|
|
56
66
|
lastModified: Date;
|
|
57
67
|
}[]>;
|
|
58
68
|
|
|
59
|
-
|
|
69
|
+
type BuilderStaticParamsOptions = ClientOptions & {
|
|
70
|
+
/** The dynamic segment of the route, as in `createBuilderPage({ fromParams })`. Default `handle`. */
|
|
71
|
+
param?: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* `generateStaticParams` for a build-time store: one entry per page of the frozen
|
|
75
|
+
* release, so every page is generated at build and nothing is rendered or
|
|
76
|
+
* regenerated afterwards (pair it with `export const dynamicParams = false`).
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* export const generateStaticParams = () => builderStaticParams({ client: builder });
|
|
80
|
+
* export const dynamicParams = false;
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* It only takes a build-mode client. A live store must not prerender its pages
|
|
84
|
+
* (every one is an ISR write on each deploy), so there it throws.
|
|
85
|
+
*/
|
|
86
|
+
declare function builderStaticParams(options: BuilderStaticParamsOptions): Promise<Record<string, string>[]>;
|
|
87
|
+
|
|
88
|
+
export { type BuilderSitemapOptions, type BuilderStaticParamsOptions, type LoadBuilderPageOptions, type LoadSiteOptions, LoadedPage, LoadedRedirect, LoadedSite, builderSitemap, builderStaticParams, loadBuilderPage, loadSite };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ClientOptions, W as WidgetPack, b as LoadedSite, L as LoadedPage, a as LoadedRedirect } from './
|
|
2
|
-
export { B as BundleAsk, g as getBundle } from './
|
|
1
|
+
import { C as ClientOptions, W as WidgetPack, b as LoadedSite, L as LoadedPage, a as LoadedRedirect, P as PagePathResolver } from './seo-Dz439Jlk.js';
|
|
2
|
+
export { B as BundleAsk, g as getBundle } from './seo-Dz439Jlk.js';
|
|
3
3
|
export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
|
|
4
4
|
import 'react';
|
|
5
5
|
import '@usethrottle/builder-schema';
|
|
@@ -24,7 +24,8 @@ type LoadSiteOptions = ClientOptions & {
|
|
|
24
24
|
* When the Builder cannot answer and there is no last good answer it returns
|
|
25
25
|
* `{ status: 'unavailable' }` and logs once per process: the store's header,
|
|
26
26
|
* footer and slots then render nothing and the catalog pages keep working
|
|
27
|
-
* (ruling R8). Any other error (a bad key, a programming error) is thrown
|
|
27
|
+
* (ruling R8). Any other error (a bad key, a programming error) is thrown, and
|
|
28
|
+
* so is every error of a build-mode client (`createBuilderClient({ mode: 'build' })`).
|
|
28
29
|
*/
|
|
29
30
|
declare function loadSite(options: LoadSiteOptions): Promise<LoadedSite>;
|
|
30
31
|
|
|
@@ -47,13 +48,41 @@ type LoadBuilderPageOptions = ClientOptions & {
|
|
|
47
48
|
declare function loadBuilderPage(options: LoadBuilderPageOptions): Promise<LoadedPage | LoadedRedirect>;
|
|
48
49
|
|
|
49
50
|
type BuilderSitemapOptions = ClientOptions & {
|
|
50
|
-
/** The store's origin (`https://shop.example.com`).
|
|
51
|
+
/** 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. */
|
|
51
52
|
storeUrl?: string;
|
|
53
|
+
/** The locale the site settings (and, for an older Builder, the pages) are read in, as for `createBuilderPage` (`en` by default). */
|
|
54
|
+
locale?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Your routes have a `[locale]` segment (`app/[locale]/pages/[handle]`), as the canonical links assume when the
|
|
57
|
+
* locale comes from the route. Each page is then listed once per site locale, under `/<locale>`.
|
|
58
|
+
*/
|
|
59
|
+
localeRoute?: boolean;
|
|
60
|
+
/** Where your store serves a page, as for `createBuilderPage`. Pass the same function. */
|
|
61
|
+
pagePath?: PagePathResolver;
|
|
52
62
|
};
|
|
53
|
-
/** The published pages as sitemap entries. An unavailable Builder gives an empty list, never a failed sitemap. */
|
|
63
|
+
/** The published pages as sitemap entries. An unavailable Builder gives an empty list, never a failed sitemap (a build-mode client fails the build instead). */
|
|
54
64
|
declare function builderSitemap(options: BuilderSitemapOptions): Promise<{
|
|
55
65
|
url: string;
|
|
56
66
|
lastModified: Date;
|
|
57
67
|
}[]>;
|
|
58
68
|
|
|
59
|
-
|
|
69
|
+
type BuilderStaticParamsOptions = ClientOptions & {
|
|
70
|
+
/** The dynamic segment of the route, as in `createBuilderPage({ fromParams })`. Default `handle`. */
|
|
71
|
+
param?: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* `generateStaticParams` for a build-time store: one entry per page of the frozen
|
|
75
|
+
* release, so every page is generated at build and nothing is rendered or
|
|
76
|
+
* regenerated afterwards (pair it with `export const dynamicParams = false`).
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* export const generateStaticParams = () => builderStaticParams({ client: builder });
|
|
80
|
+
* export const dynamicParams = false;
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* It only takes a build-mode client. A live store must not prerender its pages
|
|
84
|
+
* (every one is an ISR write on each deploy), so there it throws.
|
|
85
|
+
*/
|
|
86
|
+
declare function builderStaticParams(options: BuilderStaticParamsOptions): Promise<Record<string, string>[]>;
|
|
87
|
+
|
|
88
|
+
export { type BuilderSitemapOptions, type BuilderStaticParamsOptions, type LoadBuilderPageOptions, type LoadSiteOptions, LoadedPage, LoadedRedirect, LoadedSite, builderSitemap, builderStaticParams, loadBuilderPage, loadSite };
|
package/dist/server.js
CHANGED
|
@@ -2,11 +2,17 @@ import {
|
|
|
2
2
|
clientOf,
|
|
3
3
|
createRendererRegistry,
|
|
4
4
|
getBundle,
|
|
5
|
+
isRedirect,
|
|
5
6
|
loadBuilderPage,
|
|
7
|
+
localized,
|
|
8
|
+
originOf,
|
|
9
|
+
pagePathOf,
|
|
10
|
+
pageSeoOf,
|
|
6
11
|
partOf,
|
|
12
|
+
siteLocales,
|
|
7
13
|
staticDataFor,
|
|
8
14
|
warnOnce
|
|
9
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-NUE2KNT2.js";
|
|
10
16
|
|
|
11
17
|
// src/server/load-site.ts
|
|
12
18
|
import { BuilderUnavailableError } from "@usethrottle/builder";
|
|
@@ -17,7 +23,7 @@ async function loadSite(options) {
|
|
|
17
23
|
try {
|
|
18
24
|
bundle = await getBundle({ client, locale, slots, page });
|
|
19
25
|
} catch (error) {
|
|
20
|
-
if (!(error instanceof BuilderUnavailableError)) throw error;
|
|
26
|
+
if (!(error instanceof BuilderUnavailableError) || client.mode === "build") throw error;
|
|
21
27
|
warnOnce("site-unavailable", `The Builder could not be read (${error.reason}); the store renders without its Builder header, footer and slots`);
|
|
22
28
|
return { status: "unavailable", locale };
|
|
23
29
|
}
|
|
@@ -39,35 +45,73 @@ async function loadSite(options) {
|
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
// src/server/sitemap.ts
|
|
42
|
-
import { BuilderUnavailableError as BuilderUnavailableError2 } from "@usethrottle/builder";
|
|
48
|
+
import { BuilderNotFoundError, BuilderUnavailableError as BuilderUnavailableError2 } from "@usethrottle/builder";
|
|
43
49
|
async function builderSitemap(options) {
|
|
44
50
|
const client = clientOf(options);
|
|
51
|
+
const origin = originOf(options.storeUrl);
|
|
52
|
+
if (origin === void 0) {
|
|
53
|
+
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.");
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
const locale = options.locale ?? "en";
|
|
45
57
|
try {
|
|
46
58
|
const pages = await client.pages.list();
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
const base = origin.replace(/\/+$/u, "");
|
|
57
|
-
return pages.map((page) => ({ url: `${base}${page.path}`, lastModified: new Date(page.updatedAt) }));
|
|
59
|
+
const { settings } = await client.site({ locale });
|
|
60
|
+
const indexable = await withoutNoindex(client, pages, locale);
|
|
61
|
+
const { list } = siteLocales(settings);
|
|
62
|
+
const prefixes = options.localeRoute !== true ? [void 0] : list.length > 0 ? list : [locale];
|
|
63
|
+
return indexable.flatMap((page) => {
|
|
64
|
+
const path = pagePathOf(settings, page, options.pagePath);
|
|
65
|
+
if (path === null) return [];
|
|
66
|
+
return prefixes.map((prefix) => ({ url: `${origin}${localized(path, prefix)}`, lastModified: new Date(page.updatedAt) }));
|
|
67
|
+
});
|
|
58
68
|
} catch (error) {
|
|
59
|
-
if (!(error instanceof BuilderUnavailableError2)) throw error;
|
|
69
|
+
if (!(error instanceof BuilderUnavailableError2) || client.mode === "build") throw error;
|
|
60
70
|
warnOnce("sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
|
|
61
71
|
return [];
|
|
62
72
|
}
|
|
63
73
|
}
|
|
74
|
+
var READ_AT_ONCE = 8;
|
|
75
|
+
async function withoutNoindex(client, pages, locale) {
|
|
76
|
+
const unknown = pages.filter((page) => typeof page.noindex !== "boolean");
|
|
77
|
+
const skip = new Set(pages.filter((page) => page.noindex === true).map((page) => page.slug));
|
|
78
|
+
for (let from = 0; from < unknown.length; from += READ_AT_ONCE) {
|
|
79
|
+
const slice = unknown.slice(from, from + READ_AT_ONCE);
|
|
80
|
+
const answers = await Promise.all(
|
|
81
|
+
slice.map(
|
|
82
|
+
(page) => client.pages.get(page.slug, { locale }).catch((error) => {
|
|
83
|
+
if (error instanceof BuilderNotFoundError) return "gone";
|
|
84
|
+
warnOnce("sitemap-page-read", `A page could not be read for the sitemap (${error instanceof Error ? error.message : "unknown error"}); it stays listed`);
|
|
85
|
+
return void 0;
|
|
86
|
+
})
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
slice.forEach((page, index) => {
|
|
90
|
+
const answer = answers[index];
|
|
91
|
+
if (answer === "gone" || answer !== void 0 && (isRedirect(answer) || pageSeoOf(answer).noindex)) skip.add(page.slug);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return pages.filter((page) => !skip.has(page.slug));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/server/static-params.ts
|
|
98
|
+
async function builderStaticParams(options) {
|
|
99
|
+
const client = clientOf(options);
|
|
100
|
+
if (client.mode !== "build")
|
|
101
|
+
throw new TypeError(
|
|
102
|
+
'builderStaticParams generates every page of a frozen release: give it a client made with createBuilderClient({ mode: "build" }). A live store keeps its pages dynamic.'
|
|
103
|
+
);
|
|
104
|
+
const pages = await client.pages.list();
|
|
105
|
+
return pages.map((page) => ({ [options.param ?? "handle"]: page.slug }));
|
|
106
|
+
}
|
|
64
107
|
|
|
65
108
|
// src/server/index.ts
|
|
66
|
-
import { BuilderNotFoundError, BuilderUnavailableError as BuilderUnavailableError3 } from "@usethrottle/builder";
|
|
109
|
+
import { BuilderNotFoundError as BuilderNotFoundError2, BuilderUnavailableError as BuilderUnavailableError3 } from "@usethrottle/builder";
|
|
67
110
|
export {
|
|
68
|
-
BuilderNotFoundError,
|
|
111
|
+
BuilderNotFoundError2 as BuilderNotFoundError,
|
|
69
112
|
BuilderUnavailableError3 as BuilderUnavailableError,
|
|
70
113
|
builderSitemap,
|
|
114
|
+
builderStaticParams,
|
|
71
115
|
getBundle,
|
|
72
116
|
loadBuilderPage,
|
|
73
117
|
loadSite
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/builder-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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": "^0.
|
|
61
|
-
"@usethrottle/builder-schema": "^0.1.
|
|
62
|
-
"@usethrottle/ui": "^0.1.
|
|
60
|
+
"@usethrottle/builder": "^0.2.0",
|
|
61
|
+
"@usethrottle/builder-schema": "^0.1.2",
|
|
62
|
+
"@usethrottle/ui": "^0.1.2"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"next": ">=15",
|
|
@@ -93,6 +93,7 @@
|
|
|
93
93
|
"dev": "node scripts/playground.mjs",
|
|
94
94
|
"test": "vitest run",
|
|
95
95
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
96
|
-
"size": "node scripts/size.mjs"
|
|
96
|
+
"size": "node scripts/size.mjs",
|
|
97
|
+
"test:rsc": "node scripts/rsc-build.mjs"
|
|
97
98
|
}
|
|
98
99
|
}
|