@botlr/next 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/CHANGELOG.md +16 -0
- package/README.md +72 -20
- package/dist/index.cjs +570 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +326 -3
- package/dist/index.d.ts +326 -3
- package/dist/index.js +551 -3
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @botlr/next
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Page helpers extracted from the satellite apps.
|
|
8
|
+
|
|
9
|
+
`@botlr/sdk`: `PageResponse` gains optional `full_slug`, `breadcrumbs` and `alternate_translations` (new `AlternateTranslation` type, also used by `ResolveResponse`). New asset helpers `getAssetUrl`, `createAssetUrl`, `getAssetId`, `getAssetFilename` and `isAssetData` take the media server URL explicitly instead of reading `NEXT_PUBLIC_MEDIA_URL`.
|
|
10
|
+
|
|
11
|
+
`@botlr/next`: `resolvePage` and `createPageResolver`, `buildPageMetadata`, `renderCmsPage` with `themeSettingsToCss`, `serveStaticTextFile` and `defaultRobotsContent`, `createLocalePage` and `createLocaleAliasPage`, `rateLimit` and `getClientIp`, plus `scopeFromEnv` and `environmentFromEnv`. Every helper takes its client and component registry as arguments. `html-react-parser` is a new dependency.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
- @botlr/sdk@0.2.0
|
|
17
|
+
- @botlr/react@0.1.1
|
|
18
|
+
|
|
3
19
|
## 0.1.0
|
|
4
20
|
|
|
5
21
|
- First release. `getBotlrForRoute` moves here from the publisher's
|
package/README.md
CHANGED
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
# @botlr/next
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Next.js helpers on top of `@botlr/sdk` and `@botlr/react`. Everything from
|
|
4
|
+
both packages is re-exported, so a server file can import from `@botlr/next`
|
|
5
|
+
alone. The package imports `next/headers` and `next/navigation`, so client
|
|
6
|
+
components should import runtime values from `@botlr/sdk` or `@botlr/react`
|
|
7
|
+
instead; type imports from `@botlr/next` are fine anywhere.
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
// app/[[...slug]]/page.tsx
|
|
9
|
-
import { getBotlrForRoute, SectionRenderer } from "@botlr/next";
|
|
10
|
-
|
|
11
|
-
export default async function Page({ params, searchParams }) {
|
|
12
|
-
const botlr = await getBotlrForRoute({
|
|
13
|
-
appId: process.env.BOTLR_APP_ID!,
|
|
14
|
-
preview: (await searchParams).preview === "true",
|
|
15
|
-
});
|
|
16
|
-
const resolved = await botlr.resolveUrl((await params).slug?.join("/") ?? "");
|
|
17
|
-
// ...render resolved.data.layout with SectionRenderer
|
|
18
|
-
}
|
|
19
|
-
```
|
|
9
|
+
## Clients
|
|
20
10
|
|
|
21
11
|
- `getBotlrForRoute(params)` builds a client for the current request. The
|
|
22
12
|
locale comes from `Accept-Language` unless given; `baseUrl`, `apiKey` and
|
|
@@ -25,8 +15,70 @@ export default async function Page({ params, searchParams }) {
|
|
|
25
15
|
browser through a `NEXT_PUBLIC_` name.
|
|
26
16
|
- `getCachedBotlr` is the same, memoised per request with React `cache`.
|
|
27
17
|
- `createBotlrFromEnv(overrides)` needs no request context (scripts,
|
|
28
|
-
`generateStaticParams
|
|
29
|
-
- `
|
|
30
|
-
|
|
18
|
+
`generateStaticParams`, the page helpers below).
|
|
19
|
+
- `configFromEnv`, `scopeFromEnv({ locale })` (from `BOTLR_ORG_SLUG`,
|
|
20
|
+
`BOTLR_PROJECT_SLUG`, `BOTLR_APP_INSTANCE_SLUG`, `BOTLR_APP_ID`),
|
|
21
|
+
`environmentFromEnv()` (`BOTLR_ENVIRONMENT`, `ENVIRONMENT`, `NODE_ENV`) and
|
|
22
|
+
`localeFromAcceptLanguage` are the building blocks.
|
|
23
|
+
|
|
24
|
+
## A static locale route in one call
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
// lib/botlr.ts
|
|
28
|
+
import { createBotlrFromEnv } from "@botlr/next";
|
|
29
|
+
export const botlr = createBotlrFromEnv();
|
|
30
|
+
|
|
31
|
+
// app/(root)/[[...slug]]/page.tsx
|
|
32
|
+
import { createLocalePage } from "@botlr/next";
|
|
33
|
+
import { botlr } from "@/lib/botlr";
|
|
34
|
+
import { publisherSectionRegistry } from "@/components/sections/publisher-section-registry";
|
|
35
|
+
|
|
36
|
+
// Segment config must stay as literals here so Next can read it statically.
|
|
37
|
+
export const revalidate = false;
|
|
38
|
+
export const dynamicParams = false;
|
|
39
|
+
|
|
40
|
+
const page = createLocalePage({
|
|
41
|
+
locale: "da",
|
|
42
|
+
folder: "",
|
|
43
|
+
client: botlr,
|
|
44
|
+
componentRegistry: publisherSectionRegistry,
|
|
45
|
+
siteUrl: process.env.NEXT_PUBLIC_APP_URL,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export const generateStaticParams = page.generateStaticParams;
|
|
49
|
+
export const generateMetadata = page.generateMetadata;
|
|
50
|
+
export default page.Page;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`createLocalePage` lists slugs with `getPageSlugList`, resolves each request
|
|
54
|
+
once for metadata and page through `createPageResolver`, calls `notFound()`
|
|
55
|
+
for missing and unpublished pages, follows CMS redirects with
|
|
56
|
+
`permanentRedirect` (or `redirect` with `redirect: "temporary"`) prefixed by
|
|
57
|
+
`folder`, and renders with `renderCmsPage`. `createLocaleAliasPage("/sv")`
|
|
58
|
+
makes a folder that only redirects to another one.
|
|
59
|
+
|
|
60
|
+
## The pieces
|
|
61
|
+
|
|
62
|
+
- `resolvePage(client, slug, locale, options)` folds `/api/resolve` into
|
|
63
|
+
`{ kind: "page" | "redirect" | "404" | "error" }` and prepends non-page
|
|
64
|
+
content (articles by default; see `contentSections`) to the `main` region as
|
|
65
|
+
an inline section. `createPageResolver(client, options)` binds the client
|
|
66
|
+
and memoises per request.
|
|
67
|
+
- `buildPageMetadata(pageData, { siteUrl, folder })` turns `seo_meta` into
|
|
68
|
+
Next `Metadata`: title, description, keywords, Open Graph, Twitter, robots,
|
|
69
|
+
canonical and hreflang alternates. Without `siteUrl` only an explicit
|
|
70
|
+
`seo_meta.canonical` is emitted.
|
|
71
|
+
- `renderCmsPage({ pageData, scope, componentRegistry, client })` picks the
|
|
72
|
+
page template, then the theme's, then a built-in one; merges template and
|
|
73
|
+
page layouts; applies visibility rules for `environment`; fetches shared
|
|
74
|
+
sections through `client` or `fetchSharedSection`; and mounts a
|
|
75
|
+
`SectionRenderer` at every `{{{REGION}}}` marker. `themeSettingsToCss`
|
|
76
|
+
emits the theme's custom properties.
|
|
77
|
+
- `serveStaticTextFile(client, slug, defaultContent)` serves a CMS page's
|
|
78
|
+
text sections as `text/plain`, for `robots.txt`, `humans.txt` and
|
|
79
|
+
`llms.txt` routes. `defaultRobotsContent()` allows everything in production
|
|
80
|
+
and disallows elsewhere.
|
|
81
|
+
- `rateLimit(key, { limit, window })` and `getClientIp(request)` for form and
|
|
82
|
+
forum route handlers. In-memory, per server instance.
|
|
31
83
|
|
|
32
|
-
`next` and `react` are peer dependencies.
|
|
84
|
+
`next` and `react` are peer dependencies; `html-react-parser` is a dependency.
|