barakopress 0.3.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1133 -28
- package/dist/assets.d.ts +40 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +188 -0
- package/dist/assets.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +9 -0
- package/dist/bin.js.map +1 -0
- package/dist/blocks/bind.d.ts +39 -0
- package/dist/blocks/bind.d.ts.map +1 -0
- package/dist/blocks/bind.js +305 -0
- package/dist/blocks/bind.js.map +1 -0
- package/dist/blocks/bindings.d.ts +92 -0
- package/dist/blocks/bindings.d.ts.map +1 -0
- package/dist/blocks/bindings.js +281 -0
- package/dist/blocks/bindings.js.map +1 -0
- package/dist/blocks/built-in.d.ts +34 -0
- package/dist/blocks/built-in.d.ts.map +1 -0
- package/dist/blocks/built-in.js +208 -0
- package/dist/blocks/built-in.js.map +1 -0
- package/dist/blocks/data.d.ts +20 -0
- package/dist/blocks/data.d.ts.map +1 -0
- package/dist/blocks/data.js +131 -0
- package/dist/blocks/data.js.map +1 -0
- package/dist/blocks/library.d.ts +7 -0
- package/dist/blocks/library.d.ts.map +1 -0
- package/dist/blocks/library.js +679 -0
- package/dist/blocks/library.js.map +1 -0
- package/dist/blocks/motion.d.ts +18 -0
- package/dist/blocks/motion.d.ts.map +1 -0
- package/dist/blocks/motion.js +0 -0
- package/dist/blocks/motion.js.map +1 -0
- package/dist/blocks/presets.d.ts +74 -0
- package/dist/blocks/presets.d.ts.map +1 -0
- package/dist/blocks/presets.js +240 -0
- package/dist/blocks/presets.js.map +1 -0
- package/dist/blocks/primitives.d.ts +23 -0
- package/dist/blocks/primitives.d.ts.map +1 -0
- package/dist/blocks/primitives.js +1087 -0
- package/dist/blocks/primitives.js.map +1 -0
- package/dist/blocks/registry.d.ts +23 -0
- package/dist/blocks/registry.d.ts.map +1 -0
- package/dist/blocks/registry.js +57 -0
- package/dist/blocks/registry.js.map +1 -0
- package/dist/blocks/render.d.ts +8 -0
- package/dist/blocks/render.d.ts.map +1 -0
- package/dist/blocks/render.js +33 -0
- package/dist/blocks/render.js.map +1 -0
- package/dist/blocks/schema.d.ts +136 -0
- package/dist/blocks/schema.d.ts.map +1 -0
- package/dist/blocks/schema.js +250 -0
- package/dist/blocks/schema.js.map +1 -0
- package/dist/blocks/search-keys.d.ts +6 -0
- package/dist/blocks/search-keys.d.ts.map +1 -0
- package/dist/blocks/search-keys.js +75 -0
- package/dist/blocks/search-keys.js.map +1 -0
- package/dist/blocks/tokens.d.ts +31 -0
- package/dist/blocks/tokens.d.ts.map +1 -0
- package/dist/blocks/tokens.js +143 -0
- package/dist/blocks/tokens.js.map +1 -0
- package/dist/blocks/tree-blocks.d.ts +4 -0
- package/dist/blocks/tree-blocks.d.ts.map +1 -0
- package/dist/blocks/tree-blocks.js +102 -0
- package/dist/blocks/tree-blocks.js.map +1 -0
- package/dist/cms.d.ts +115 -1
- package/dist/cms.d.ts.map +1 -1
- package/dist/cms.js +264 -68
- package/dist/cms.js.map +1 -1
- package/dist/collections.d.ts +112 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +320 -0
- package/dist/collections.js.map +1 -0
- package/dist/config.d.ts +486 -10
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +266 -13
- package/dist/config.js.map +1 -1
- package/dist/delivery.d.ts +113 -1
- package/dist/delivery.d.ts.map +1 -1
- package/dist/delivery.js +490 -17
- package/dist/delivery.js.map +1 -1
- package/dist/env.d.ts +37 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +44 -0
- package/dist/env.js.map +1 -0
- package/dist/fonts.d.ts +53 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +170 -0
- package/dist/fonts.js.map +1 -0
- package/dist/index.d.ts +59 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -6
- package/dist/index.js.map +1 -1
- package/dist/markdown.d.ts +7 -1
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +22 -5
- package/dist/markdown.js.map +1 -1
- package/dist/proxy.d.ts +18 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +83 -0
- package/dist/proxy.js.map +1 -0
- package/dist/related.d.ts +29 -2
- package/dist/related.d.ts.map +1 -1
- package/dist/related.js +54 -14
- package/dist/related.js.map +1 -1
- package/dist/revalidate-key.d.ts +14 -0
- package/dist/revalidate-key.d.ts.map +1 -0
- package/dist/revalidate-key.js +51 -0
- package/dist/revalidate-key.js.map +1 -0
- package/dist/routes/binding-report.d.ts +37 -0
- package/dist/routes/binding-report.d.ts.map +1 -0
- package/dist/routes/binding-report.js +141 -0
- package/dist/routes/binding-report.js.map +1 -0
- package/dist/routes/block-schema.d.ts +11 -0
- package/dist/routes/block-schema.d.ts.map +1 -0
- package/dist/routes/block-schema.js +54 -0
- package/dist/routes/block-schema.js.map +1 -0
- package/dist/routes/feed.d.ts +6 -2
- package/dist/routes/feed.d.ts.map +1 -1
- package/dist/routes/feed.js +38 -27
- package/dist/routes/feed.js.map +1 -1
- package/dist/routes/revalidate.d.ts +7 -1
- package/dist/routes/revalidate.d.ts.map +1 -1
- package/dist/routes/revalidate.js +141 -27
- package/dist/routes/revalidate.js.map +1 -1
- package/dist/routes/robots.d.ts +1 -1
- package/dist/routes/robots.d.ts.map +1 -1
- package/dist/routes/robots.js +11 -3
- package/dist/routes/robots.js.map +1 -1
- package/dist/routes/share.d.ts +10 -0
- package/dist/routes/share.d.ts.map +1 -0
- package/dist/routes/share.js +188 -0
- package/dist/routes/share.js.map +1 -0
- package/dist/routes/sitemap.d.ts +6 -2
- package/dist/routes/sitemap.d.ts.map +1 -1
- package/dist/routes/sitemap.js +102 -22
- package/dist/routes/sitemap.js.map +1 -1
- package/dist/screens/archive.d.ts +11 -5
- package/dist/screens/archive.d.ts.map +1 -1
- package/dist/screens/archive.js +14 -38
- package/dist/screens/archive.js.map +1 -1
- package/dist/screens/article-view.d.ts +29 -0
- package/dist/screens/article-view.d.ts.map +1 -0
- package/dist/screens/article-view.js +214 -0
- package/dist/screens/article-view.js.map +1 -0
- package/dist/screens/blog-index.d.ts +8 -8
- package/dist/screens/blog-index.d.ts.map +1 -1
- package/dist/screens/blog-index.js +9 -32
- package/dist/screens/blog-index.js.map +1 -1
- package/dist/screens/blog-post.d.ts +20 -11
- package/dist/screens/blog-post.d.ts.map +1 -1
- package/dist/screens/blog-post.js +28 -83
- package/dist/screens/blog-post.js.map +1 -1
- package/dist/screens/collection.d.ts +109 -0
- package/dist/screens/collection.d.ts.map +1 -0
- package/dist/screens/collection.js +303 -0
- package/dist/screens/collection.js.map +1 -0
- package/dist/screens/navigation.d.ts +16 -0
- package/dist/screens/navigation.d.ts.map +1 -0
- package/dist/screens/navigation.js +40 -0
- package/dist/screens/navigation.js.map +1 -0
- package/dist/screens/page.d.ts +62 -0
- package/dist/screens/page.d.ts.map +1 -0
- package/dist/screens/page.js +347 -0
- package/dist/screens/page.js.map +1 -0
- package/dist/screens/post-view.d.ts +7 -3
- package/dist/screens/post-view.d.ts.map +1 -1
- package/dist/screens/post-view.js +18 -183
- package/dist/screens/post-view.js.map +1 -1
- package/dist/screens/site-layout.d.ts +20 -0
- package/dist/screens/site-layout.d.ts.map +1 -0
- package/dist/screens/site-layout.js +228 -0
- package/dist/screens/site-layout.js.map +1 -0
- package/dist/screens/tree.d.ts +78 -0
- package/dist/screens/tree.d.ts.map +1 -0
- package/dist/screens/tree.js +185 -0
- package/dist/screens/tree.js.map +1 -0
- package/dist/secret.d.ts +25 -0
- package/dist/secret.d.ts.map +1 -0
- package/dist/secret.js +38 -0
- package/dist/secret.js.map +1 -0
- package/dist/site-route.d.ts +28 -0
- package/dist/site-route.d.ts.map +1 -0
- package/dist/site-route.js +104 -0
- package/dist/site-route.js.map +1 -0
- package/dist/site.d.ts +72 -0
- package/dist/site.d.ts.map +1 -0
- package/dist/site.js +907 -0
- package/dist/site.js.map +1 -0
- package/dist/store.d.ts +36 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +98 -0
- package/dist/store.js.map +1 -0
- package/dist/theme.d.ts +87 -3
- package/dist/theme.d.ts.map +1 -1
- package/dist/theme.js +110 -3
- package/dist/theme.js.map +1 -1
- package/dist/tree.d.ts +56 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +196 -0
- package/dist/tree.js.map +1 -0
- package/package.json +17 -1
- package/src/assets.tsx +233 -0
- package/src/bin.ts +7 -0
- package/src/blocks/bind.ts +407 -0
- package/src/blocks/bindings.ts +352 -0
- package/src/blocks/built-in.tsx +335 -0
- package/src/blocks/data.tsx +179 -0
- package/src/blocks/library.ts +758 -0
- package/src/blocks/motion.ts +0 -0
- package/src/blocks/presets.ts +324 -0
- package/src/blocks/primitives.tsx +1560 -0
- package/src/blocks/registry.ts +65 -0
- package/src/blocks/render.tsx +51 -0
- package/src/blocks/schema.ts +413 -0
- package/src/blocks/search-keys.tsx +74 -0
- package/src/blocks/tokens.ts +168 -0
- package/src/blocks/tree-blocks.tsx +120 -0
- package/src/cms.ts +329 -70
- package/src/collections.ts +420 -0
- package/src/config.ts +754 -18
- package/src/delivery.ts +578 -18
- package/src/env.ts +68 -0
- package/src/fonts.ts +189 -0
- package/src/index.ts +245 -6
- package/src/markdown.ts +28 -5
- package/src/proxy.ts +93 -0
- package/src/related.ts +79 -15
- package/src/revalidate-key.ts +60 -0
- package/src/routes/binding-report.ts +210 -0
- package/src/routes/block-schema.ts +71 -0
- package/src/routes/feed.ts +47 -22
- package/src/routes/revalidate.ts +149 -27
- package/src/routes/robots.ts +9 -3
- package/src/routes/share.ts +198 -0
- package/src/routes/sitemap.ts +108 -23
- package/src/screens/archive.tsx +18 -69
- package/src/screens/article-view.tsx +478 -0
- package/src/screens/blog-index.tsx +9 -114
- package/src/screens/blog-post.tsx +34 -89
- package/src/screens/collection.tsx +577 -0
- package/src/screens/navigation.tsx +101 -0
- package/src/screens/page.tsx +472 -0
- package/src/screens/post-view.tsx +34 -383
- package/src/screens/site-layout.tsx +451 -0
- package/src/screens/tree.tsx +389 -0
- package/src/secret.ts +50 -0
- package/src/site-route.ts +116 -0
- package/src/site.ts +1012 -0
- package/src/store.ts +117 -0
- package/src/theme.ts +198 -6
- package/src/tree.ts +250 -0
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ decision, not the engine's.
|
|
|
83
83
|
|
|
84
84
|
| Create | Export | From |
|
|
85
85
|
| --- | --- | --- |
|
|
86
|
-
| `app/page.tsx` | `default` | `
|
|
86
|
+
| `app/page.tsx` | `default`, `generateMetadata` | `createHome(config, blocks)`, `createHomeMetadata(config)` |
|
|
87
87
|
| `app/blog/[slug]/page.tsx` | `default`, `generateMetadata` | `createBlogPost(config)`, `createPostMetadata(config)` |
|
|
88
88
|
| `app/authors/[slug]/page.tsx` | `default` | `createArchive(config, "author")` |
|
|
89
89
|
| `app/categories/[slug]/page.tsx` | `default` | `createArchive(config, "category")` |
|
|
@@ -91,6 +91,18 @@ decision, not the engine's.
|
|
|
91
91
|
| `app/sitemap.ts` | `default` | `createSitemap(config)` |
|
|
92
92
|
| `app/robots.ts` | `default` | `createRobots(config)` |
|
|
93
93
|
| `app/api/revalidate/route.ts` | `POST`, `GET` | `createRevalidateRoute(config)` |
|
|
94
|
+
| `app/[...path]/page.tsx` | `default`, `generateMetadata` | `createPage(config, blocks)`, `createPageMetadata(config)` |
|
|
95
|
+
| `app/doctors/page.tsx` | `default` | `createCollectionIndex(config, "doctors")` |
|
|
96
|
+
| `app/doctors/[slug]/page.tsx` | `default`, `generateMetadata`, `generateStaticParams` | `createCollectionDetail(config, "doctors")`, `createCollectionMetadata(config, "doctors")`, `createCollectionStaticParams(config, "doctors")` |
|
|
97
|
+
| `app/api/blocks/route.ts` | `GET`, `OPTIONS` | `createBlockSchemaRoute(blocks)`, `createBlockSchemaPreflight()` |
|
|
98
|
+
| `app/api/blocks/bindings/route.ts` | `GET`, `OPTIONS` | `createBindingReportRoute(config, blocks)`, `createBindingReportPreflight()` |
|
|
99
|
+
| `app/layout.tsx` | `default`, `generateMetadata` | `createSiteLayout(config, { blocks })`, `createSiteMetadata(config)` |
|
|
100
|
+
| `app/%5Fshare/route.ts` | `GET` | `createSharePage(config)` |
|
|
101
|
+
| `app/api/share/redeem/route.ts` | `POST` | `createShareRedeemRoute(config)` |
|
|
102
|
+
|
|
103
|
+
`createHome` serves whatever the tenant picked for `/`: the page at `HomePath`, the index of
|
|
104
|
+
`HomeCollection`, or the post index when it picked neither, which is what `createBlogIndex` did and
|
|
105
|
+
still does for a site that mounts that instead.
|
|
94
106
|
|
|
95
107
|
Mount only what you want. Nothing requires anything else. The paths only have to agree with the
|
|
96
108
|
`routes` in your config, which is what every generated link is built from.
|
|
@@ -100,8 +112,501 @@ It reads `searchParams`, which forces the route dynamic, so a site using `output
|
|
|
100
112
|
`createBlogPost` and gives up preview. `createPostStaticParams` and `createArchiveStaticParams` exist
|
|
101
113
|
for that static case.
|
|
102
114
|
|
|
115
|
+
The binding report says why a binding on a page did not resolve, so an editor fixes it in barakoBrew
|
|
116
|
+
instead of asking whoever can read the server log. Ask for one page at a time, by `?slug=` or
|
|
117
|
+
`?path=`, and each problem names the binding as typed, the reason (`unknown scope`, `unbound scope`
|
|
118
|
+
or `no value`), and the block and field it came from. It reports the page as rendered, not as
|
|
119
|
+
stored, so a `{{item.X}}` outside a repeat is reported as an unbound scope. Give it the same `query`
|
|
120
|
+
option the page route has: off, which is the default, a `{{query.X}}` is an unbound scope for every
|
|
121
|
+
visitor and the report says so, and a report that resolved one anyway would tell an editor a field
|
|
122
|
+
works where it does not. It is never anonymous:
|
|
123
|
+
the caller presents the tenant's key as `Authorization: Bearer`, derived from `PRESS_SECRET` and
|
|
124
|
+
printed by `barakopress bindings-key <tenant>`. Answers are never cached.
|
|
125
|
+
|
|
103
126
|
`Card` and `PostView` are exported too, for a site that wants its own page but the engine's markup.
|
|
104
127
|
|
|
128
|
+
### Collections: any content type as a list and a detail page
|
|
129
|
+
|
|
130
|
+
A hospital has departments and doctors, a law firm practice areas and people. Each is a collection: a
|
|
131
|
+
content type with a route, a field map, references to other collections, a sort, and whether it has a
|
|
132
|
+
feed. The blog is three collections that `defineConfig` derives from `types`, `fields` and `routes`
|
|
133
|
+
(`post`, `author` and `category`), and `createBlogIndex`, `createBlogPost` and `createArchive` are thin
|
|
134
|
+
wrappers over the collection screens. A site configured the old way changes nothing:
|
|
135
|
+
`src/blog-wrappers.test.tsx` renders every blog factory, the feed, the sitemap and the metadata, and
|
|
136
|
+
compares them and the requests they make with `test/blog-wrappers.golden.json`, which was written
|
|
137
|
+
before collections existed.
|
|
138
|
+
|
|
139
|
+
On a request-time site the map is the tenant's, from a json field `Collections` on its site settings,
|
|
140
|
+
merged over the configured collections by key. A build-time site passes `collections` to
|
|
141
|
+
`defineConfig` in the same shape:
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"departments": {
|
|
146
|
+
"type": "department", "route": "/departments",
|
|
147
|
+
"fields": { "title": "Name", "body": "About" },
|
|
148
|
+
"noun": ["department", "departments"]
|
|
149
|
+
},
|
|
150
|
+
"doctors": {
|
|
151
|
+
"type": "doctor", "route": "/doctors", "sort": "Name",
|
|
152
|
+
"fields": { "title": "Name", "summary": "Specialty", "image": "Photo" },
|
|
153
|
+
"references": { "Department": { "collection": "departments", "label": "in" } },
|
|
154
|
+
"noun": ["doctor", "doctors"]
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
| Key | What |
|
|
160
|
+
| --- | --- |
|
|
161
|
+
| `type` | The content type. Required |
|
|
162
|
+
| `route` | The index is served at the route and an item at `route/slug`. Absent, items are listed and never linked |
|
|
163
|
+
| `fields` | `title` (required), `slug`, `summary`, `body` (markdown), `date`, `image`, `imageAlt`, `featured`, `tags`, `url`, `photo`, `progress`. Each is a field name or a list tried in order; `@createdAt` and `@updatedAt` read the entry itself. `photo` is a portrait drawn above the title, `image` the wide one, and `progress` is a number from 0 to 100 that `progressList` draws |
|
|
164
|
+
| `references` | Reference fields, each naming the collection it points into and the word a card puts before the link. Resolved in the same request |
|
|
165
|
+
| `sort` | Sent to the API, for example `-PublishedAt` |
|
|
166
|
+
| `feed` | Whether `createFeed(config, key)` serves it |
|
|
167
|
+
| `sitemap` | On unless `false`. A collection is paged to `pageSizes.sitemap` entries; the file stops at the standard's 50,000 URLs and says so in the log |
|
|
168
|
+
| `index` | Whether the root catch-all serves an index at the route. On unless `false`; the derived `author` and `category` have it off, so `/authors` stays a 404 unless a route file mounts it |
|
|
169
|
+
| `pageSize`, `label`, `noun` | Items on the index, its heading, and how a count reads |
|
|
170
|
+
| `colorBy` | A choice field whose option colours the item. See below |
|
|
171
|
+
| `related` | What an item page lists under the item: `"semantic"` for the items of this collection closest to it by meaning, `false` for none. Unset, the first collection that references this one |
|
|
172
|
+
| `readingTime` | Whether an item page shows a read time worked out from its body. Off unless `true` |
|
|
173
|
+
| `layout` | How an item page is drawn: `"list"`, the shell markup every collection has had, or `"article"`, the reading column the blog's posts are drawn in. See below |
|
|
174
|
+
| `tree` | Set when the collection is a manual rather than a flat list: sections, an order, nesting, products. See below |
|
|
175
|
+
|
|
176
|
+
A settings entry that does not read as a collection is left out whole: a type or field that is not a
|
|
177
|
+
plain identifier, a route that is not a plain site path, or no title field. `post`, `author` and
|
|
178
|
+
`category` are replaceable by key like any other collection, since every read goes through the
|
|
179
|
+
collection's own field map. A build-time collection mounted at `/` throws in `defineConfig`. When two
|
|
180
|
+
routes match, the longer one wins.
|
|
181
|
+
|
|
182
|
+
A request-time site cannot add a route file per tenant, so the root catch-all from the pages section
|
|
183
|
+
also serves every collection with a route: its index at the route, and an item one segment below. A
|
|
184
|
+
route file wins where there is one. A collection's first segment is reserved from pages at the root.
|
|
185
|
+
|
|
186
|
+
A detail page lists the items of the first collection that references it, so `/departments/cardiology`
|
|
187
|
+
lists its doctors, the way an author's archive lists their posts. `listRelated(config, "doctors",
|
|
188
|
+
department, { via: "Department" })` returns the same list; `listRelated(config, post)` still returns
|
|
189
|
+
related posts by semantic search.
|
|
190
|
+
|
|
191
|
+
With `related: "semantic"` it lists the items of its own collection nearest it by meaning instead, so
|
|
192
|
+
an agency's case study gets the band a post has. That needs the CMS AI module: without it the search
|
|
193
|
+
answers nothing and the page draws no band at all, which is the same way the post page degrades.
|
|
194
|
+
`listRelatedItems(config, key, item)` returns that list on its own.
|
|
195
|
+
|
|
196
|
+
**Filtering.** `listCollection(config, "doctors", { filter: { Department: "cardiology" } })` takes a
|
|
197
|
+
reference field by the target's slug and any other field by the value it holds, a choice field by its
|
|
198
|
+
option. The API takes five filters. `createCollectionIndex(config, key, { filter })` takes the same,
|
|
199
|
+
and the `collection` block has `filterField` and `filterValue`.
|
|
200
|
+
|
|
201
|
+
**A style per option.** With `colorBy: "AreaOfFocus"` on a `project` collection, the site settings
|
|
202
|
+
`OptionStyles` entry says how each option of that field is shown:
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"OptionStyles": {
|
|
207
|
+
"project.AreaOfFocus": {
|
|
208
|
+
"Providing clean water": { "tone": "sky", "icon": "location", "label": "Water" }
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
`tone` names a colour from `Colors`, a theme slot, or a colour written out, and each card, item page
|
|
215
|
+
and collection block item carries it as a left border. `icon` is one of the engine's icon names, and
|
|
216
|
+
`label` is the word a visitor reads in place of the option's own value; the value stays on the element
|
|
217
|
+
as `data-option`, where a site's own CSS can still find it. A tone that does not resolve to something
|
|
218
|
+
readable as a colour is dropped, a label past 40 characters is dropped, and an icon name nothing
|
|
219
|
+
draws draws nothing, each on its own rather than losing the whole entry.
|
|
220
|
+
|
|
221
|
+
`OptionColors` is the same thing said shorter, `{ "project.AreaOfFocus": { "Providing clean water":
|
|
222
|
+
"sky" } }`, an option whose style is a tone and nothing else. A tenant that saved colours keeps them,
|
|
223
|
+
and a style for the same option wins field by field. A build-time site passes `optionStyles`, or
|
|
224
|
+
`optionColors`, in the same shapes.
|
|
225
|
+
|
|
226
|
+
`Card` and `ItemView` are exported for a site that wants its own page, and `Card` still takes a `post`.
|
|
227
|
+
`getItem`, `listCollection` and `getGlobals(config)`, the tenant's settings entry as stored, are
|
|
228
|
+
exported too.
|
|
229
|
+
|
|
230
|
+
**A long-form layout.** `layout: "article"` draws an item as a reading column: a back link, the title
|
|
231
|
+
and standfirst, a byline from the collection's first reference, the date, a read time worked out from
|
|
232
|
+
the body, the other references, the tags, the cover image, the prose and a band of neighbours under
|
|
233
|
+
it. That is the page the blog's posts have always had, and it is a collection setting rather than a
|
|
234
|
+
blog screen, so a law firm's briefings or a newsroom's features get it by asking. Styled inline from
|
|
235
|
+
the theme, so it looks right whether or not the consumer imports `barakopress/styles.css`.
|
|
236
|
+
`PostView` is a wrapper over the same layout and is `@deprecated` for 1.0.0.
|
|
237
|
+
|
|
238
|
+
**Docs: a collection as a tree.** A manual is a collection plus four fields saying where each page
|
|
239
|
+
sits. `tree` names them, and the settings beside them say what the sidebar and the switcher show:
|
|
240
|
+
|
|
241
|
+
```json
|
|
242
|
+
{
|
|
243
|
+
"docs": {
|
|
244
|
+
"type": "doc", "route": "/docs", "label": "Documentation", "layout": "article",
|
|
245
|
+
"fields": { "title": "Title", "slug": "Slug", "body": "Body" },
|
|
246
|
+
"tree": {
|
|
247
|
+
"section": "Section", "order": "Order", "parent": "Parent", "product": "Product",
|
|
248
|
+
"sections": ["Getting started", "Guides", "Reference"],
|
|
249
|
+
"searchPath": "/docs",
|
|
250
|
+
"editPath": "Source",
|
|
251
|
+
"editBase": "https://github.com/owner/repo/edit/master/",
|
|
252
|
+
"products": [
|
|
253
|
+
{ "key": "cms", "label": "barakoCMS", "href": "/docs" },
|
|
254
|
+
{ "key": "press", "label": "barakoPress", "href": "/docs/press" }
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
| Key | What |
|
|
262
|
+
| --- | --- |
|
|
263
|
+
| `section` | The field holding the heading a page is grouped under |
|
|
264
|
+
| `order` | The field holding its position in that section. A page with none comes after those with one |
|
|
265
|
+
| `parent` | The field holding the slug of the page it hangs under, or a reference to it. A parent nobody has leaves the page at the top of its section rather than dropping it |
|
|
266
|
+
| `product` | The field naming the product it documents, matched against a product's `key`. One field name and not a list, since this one goes into an API filter |
|
|
267
|
+
| `sections` | The sections in the order the sidebar shows them. One not named here follows those that are. Named rather than worked out, because no ordering of the pages says which section comes first |
|
|
268
|
+
| `products` | What the switcher offers: a key, the word a reader sees, and where it goes. A destination that is not a site path or an http URL is dropped |
|
|
269
|
+
| `searchPath` | Where the search box submits, and whether one is drawn at all. Unset, no box, because only the site knows which of its routes reads the query |
|
|
270
|
+
| `editPath` | The field holding the page's path in whatever repository it is written in. Its slug when unset |
|
|
271
|
+
| `editBase` | Where "edit this page" points, with that path appended. Unset, no such link is drawn |
|
|
272
|
+
| `limit` | The most pages read to build the tree. 500 unless set, and 500 is the ceiling as well as the default |
|
|
273
|
+
|
|
274
|
+
An item page in such a collection draws the sidebar with the page being read marked, the switcher,
|
|
275
|
+
a search box, previous and next from the tree's reading order, and the edit link. The sidebar is a
|
|
276
|
+
`details` element, so it collapses on a phone with no script. `collectionTree(config, key, { product })`
|
|
277
|
+
and `treeNeighbours(order, slug)` return the same tree and the same neighbours for a site's own page.
|
|
278
|
+
|
|
279
|
+
**Search.** `searchCollection(config, key, query)` goes through barakoCMS's `/api/public/{type}/search`,
|
|
280
|
+
which matches only over the fields a type publishes, so a draft or a field held back from public
|
|
281
|
+
delivery can never come back. `createCollectionIndex(config, key, { search: true })` answers `?q=` with
|
|
282
|
+
what matched instead of the index; that reads the query, so the route is dynamic and `output: "export"`
|
|
283
|
+
refuses it, which is why it is off unless asked for. The box is a `form`, the results are links, and
|
|
284
|
+
the keyboard handling on top ("/" to focus, the arrow keys to walk the results, escape to clear) is the
|
|
285
|
+
one client component in the package. The root catch-all answers `?q=` on a collection index too, but
|
|
286
|
+
only where the route may be dynamic: a request-time site rewrites to a kept route, and a kept route
|
|
287
|
+
asking for the query fails rather than bailing out, so there the index lists and a page of blocks
|
|
288
|
+
holding the `search` block is where a reader searches.
|
|
289
|
+
|
|
290
|
+
Which is why `searchPath` exists rather than the box pointing at the collection's own route. Only the
|
|
291
|
+
site knows which of its routes reads the query, and a box submitting somewhere that ignores `q` sends
|
|
292
|
+
a reader to an unfiltered index that looks like a search which matched everything. Name the route that
|
|
293
|
+
answers, or name nothing and get no box.
|
|
294
|
+
|
|
295
|
+
**As blocks.** `docsSidebar`, `docsSwitcher` and `search` draw the same three on a page of blocks, each
|
|
296
|
+
taking a collection key. `search` takes a bindable `query`, so a landing page binds `{{query.q}}` and
|
|
297
|
+
the route file passes the query with `createPage(config, blocks, { query: true })`.
|
|
298
|
+
|
|
299
|
+
### Pages and navigation from the Pages module
|
|
300
|
+
|
|
301
|
+
With `BarakoCMS.Pages` installed, the CMS owns the page tree: which pages are in the menu, their
|
|
302
|
+
order, their nesting and each page's path. Mount it with `pages`:
|
|
303
|
+
|
|
304
|
+
```ts
|
|
305
|
+
export const config = defineConfig({ sites: {}, pages: "" });
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
`""` is the site root. `"/docs"` serves the CMS page at `/about` on `/docs/about`. Leaving `pages` out
|
|
309
|
+
means the site has no page tree, and nothing below asks for one. Then one catch-all route,
|
|
310
|
+
`app/[[...path]]/page.tsx`, or `app/[...path]/page.tsx` when `app/page.tsx` keeps `/`:
|
|
311
|
+
|
|
312
|
+
```tsx
|
|
313
|
+
import { createPage, createPageMetadata } from "barakopress";
|
|
314
|
+
import { blocks, config } from "@/press.config";
|
|
315
|
+
|
|
316
|
+
export default createPage(config, blocks);
|
|
317
|
+
export const generateMetadata = createPageMetadata(config);
|
|
318
|
+
export const revalidate = 300;
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
- `createPage` reads `GET /api/public/pages/resolve?path=` and renders the page's blocks, or its
|
|
322
|
+
body, with breadcrumbs above the title when the page has a parent. Mounted on a `[slug]` route
|
|
323
|
+
instead, it reads the page type by slug as before.
|
|
324
|
+
- `createSiteLayout` draws `GET /api/public/pages/navigation` in the header. `Navigation` draws the
|
|
325
|
+
items in the order it received them and links to the paths it was given, under the mount. It does
|
|
326
|
+
not sort, nest, filter or derive a path. A menu that cannot be read is no menu, not a broken page,
|
|
327
|
+
and while holding the holding page is left out of it.
|
|
328
|
+
- A miss asks `GET /api/public/redirects/resolve?path=` before it is a 404, because a catch-all is
|
|
329
|
+
where a rebuilt site's old URLs land. A 301 answers as a permanent redirect and anything else as a
|
|
330
|
+
temporary one. A destination that is not a site path or an http or https URL is ignored.
|
|
331
|
+
- **Reserved slugs.** Next answers a static route before a catch-all, so a root page slugged `blog`
|
|
332
|
+
or `feed.xml` would silently never render. At the root mount, a path whose first segment is
|
|
333
|
+
reserved is a 404 and is never asked for, and it is left out of the sitemap and static params with
|
|
334
|
+
a warning. The list is the first segment of each configured route plus `api`, `feed.xml`,
|
|
335
|
+
`sitemap.xml`, `robots.txt`, `_next`, `_share` and `favicon.ico`; `reservedSlugs` adds to it. Give
|
|
336
|
+
barakoCMS the same list as `Modules:Pages:ReservedSlugs` and an editor is refused the slug on save.
|
|
337
|
+
- **Contract.** Both bodies carry `contract`, and this renderer reads the range in `PAGES_CONTRACT`
|
|
338
|
+
(1 to 1). A body outside it logs a warning and reads as absent: no menu, no page. A public site does
|
|
339
|
+
not stop rendering because a menu shape moved.
|
|
340
|
+
- The sitemap lists the pages in the menu, and `createPageStaticParams` returns their path segments on
|
|
341
|
+
a build-time site, because the module publishes no other public list of paths. A page outside the
|
|
342
|
+
menu renders on request.
|
|
343
|
+
|
|
344
|
+
`Navigation`, `Breadcrumbs`, `getNavigation(config)`, `getPageByPath(config, path)`,
|
|
345
|
+
`getRedirect(config, path)` and `pageHref(config, path)` are exported for a site that draws its own
|
|
346
|
+
layout. Every read goes through the same tagged, cached, per tenant read as the rest of the site.
|
|
347
|
+
|
|
348
|
+
### Pages built from blocks
|
|
349
|
+
|
|
350
|
+
A page can hold an ordered list of blocks in a json field, each `{ "type": ..., "props": { ... } }`.
|
|
351
|
+
The blueprint's `page` type has no such field, so add one:
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
curl -X POST "$CMS_URL/api/content-types/page/fields" -H "authorization: Bearer $TOKEN" \
|
|
355
|
+
-H 'content-type: application/json' -d '{"fieldName":"Blocks","displayName":"Blocks","type":"json"}'
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
A page with a non-empty list renders its blocks. A page without one renders its `Body` as before.
|
|
359
|
+
Field names come from `pageFields` in the config, and the type from `types.page`.
|
|
360
|
+
|
|
361
|
+
```json
|
|
362
|
+
[
|
|
363
|
+
{ "type": "richText", "props": { "markdown": "## Hello" } },
|
|
364
|
+
{ "type": "columns", "props": { "columns": [
|
|
365
|
+
[{ "type": "image", "props": { "src": "https://example.com/a.png", "alt": "A" } }],
|
|
366
|
+
[{ "type": "callToAction", "props": { "heading": "Talk to us", "label": "Contact", "href": "/contact" } }]
|
|
367
|
+
] } },
|
|
368
|
+
{ "type": "collection", "props": { "collection": "post", "limit": 3, "heading": "Latest" } }
|
|
369
|
+
]
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
Blocks come in four layers.
|
|
373
|
+
|
|
374
|
+
**Layout primitives** hold blocks and no content: `section` (a tone, a width and a padding step),
|
|
375
|
+
`stack`, `row` (side by side, wrapping on a phone), `grid`, `flow`, `panel` (a card with a tone and
|
|
376
|
+
a frame), `stickyBar` (a band that stays put while the page moves under it, at the top or the
|
|
377
|
+
bottom), `spacer` and `divider`.
|
|
378
|
+
|
|
379
|
+
`row` and `grid` take one list per cell, which suits a designer placing each one. `flow` takes a
|
|
380
|
+
single list and lays out whatever is in it, which is what a `repeat` and a preset's `slot` produce:
|
|
381
|
+
a card per row that came back, however many that is. Its column count is a choice and not a number,
|
|
382
|
+
because only a string field takes a binding, and a preset has to pass its own `columns` through.
|
|
383
|
+
|
|
384
|
+
**Content primitives** hold content and no layout: `text` (a variant from the theme's type scale),
|
|
385
|
+
`richText` (markdown), `image`, `video`, `embed` (an iframe, only for a host in `embedHosts`),
|
|
386
|
+
`icon`, `button`, `link`, `list`, `disclosure` (a labelled section that opens; give several the
|
|
387
|
+
same `group` and only one is open at a time), `comparisonTable` (rows typed as lines with `|`
|
|
388
|
+
between the cells, drawn as a real table with a heading on every column and every row) and
|
|
389
|
+
`progressBar` (how far along one thing is, as `role="progressbar"` so it is read and not only seen).
|
|
390
|
+
|
|
391
|
+
A comparison's first line is the column headings and the first cell of every line after it is that
|
|
392
|
+
row's heading. What goes in a cell is whatever the tenant types, ticks and dashes included: a mark
|
|
393
|
+
chosen inside the engine would be one more piece of English in the markup.
|
|
394
|
+
|
|
395
|
+
**Motion primitives** are drawn finished and animate only away from that: `reveal` (a wrapper whose
|
|
396
|
+
content lifts and fades in as it scrolls into view), `rotatingText` (a comma separated list of words,
|
|
397
|
+
one shown at a time), `typingTerminal` (lines typed in sequence, held, then started again) and
|
|
398
|
+
`codeSample` (a snippet with its language and one click to select the whole of it). `text` takes a
|
|
399
|
+
`motion` of `countUp`, which counts a plain number up to the figure already written in the markup,
|
|
400
|
+
and `flow` takes a `hueRotate` of `subtle` or `wide`, which turns each cell's hue through the
|
|
401
|
+
theme's own colours in a cycle of three.
|
|
402
|
+
|
|
403
|
+
All of it is CSS. There is no script, so a page with JavaScript off renders the terminal typed out,
|
|
404
|
+
the figure at its number and the first word of the rotation standing, and every animation sits inside
|
|
405
|
+
`prefers-reduced-motion: no-preference`, so a visitor who asked for less motion gets exactly the same
|
|
406
|
+
finished page. "When it comes into view" is `animation-timeline: view()`, and a browser without it
|
|
407
|
+
shows the finished state too. `src/blocks/motion.test.tsx` strips the guards out of every stylesheet
|
|
408
|
+
these emit and fails if anything left animates or hides anything.
|
|
409
|
+
|
|
410
|
+
Every primitive takes theme tokens and never a colour or a pixel value. Tones are `page`, `surface`,
|
|
411
|
+
`accent`, `inverse` and `gradient` (the inverse band with the theme's three dark roles spread across
|
|
412
|
+
it); spacing is `none` to `xxl` from `theme.space`; type is a role from
|
|
413
|
+
`theme.text`; corners are `none`, `control`, `panel` or `pill`. A tenant that changes the scale
|
|
414
|
+
changes every page built from primitives, and nobody can put one client's blue into a block.
|
|
415
|
+
|
|
416
|
+
A tone belongs to the band and everything in it: a `section` or a `panel` publishes its ink, its
|
|
417
|
+
accent and its hairline, and the blocks inside read those rather than the page's. That is what makes
|
|
418
|
+
an inverse band readable, and it is why a block dropped anywhere still looks like it belongs.
|
|
419
|
+
|
|
420
|
+
**Presets** are named arrangements of primitives, stored as data: the shipped library below, plus
|
|
421
|
+
whatever a tenant saves of its own.
|
|
422
|
+
|
|
423
|
+
**Data blocks** load and choose rather than draw: `source`, `repeat`, `showIf`, `pager` and `slot`.
|
|
424
|
+
See bindings below.
|
|
425
|
+
|
|
426
|
+
Also built in, from before the layers: `columns` (up to four lists of blocks), `callToAction` and
|
|
427
|
+
`collection` (the newest posts, or authors or categories when the site has those routes). Pages
|
|
428
|
+
already hold these and they render unchanged.
|
|
429
|
+
|
|
430
|
+
A site adds its own blocks, or replaces a built-in, by registering a definition. The fields are the
|
|
431
|
+
only description of the props: the renderer reads props through them, and `app/api/blocks` publishes
|
|
432
|
+
them for an editor, so the two cannot drift.
|
|
433
|
+
|
|
434
|
+
```tsx
|
|
435
|
+
import { createBlockRegistry, defineBlock } from "barakopress";
|
|
436
|
+
|
|
437
|
+
const pricing = defineBlock<{ plan: string; price?: number }>({
|
|
438
|
+
type: "pricing",
|
|
439
|
+
label: "Pricing",
|
|
440
|
+
fields: [
|
|
441
|
+
{ name: "plan", kind: "text", required: true },
|
|
442
|
+
{ name: "price", kind: "number", min: 0 },
|
|
443
|
+
],
|
|
444
|
+
component: ({ props, theme }) => <p style={{ color: theme.colors.ink }}>{props.plan}: {props.price}</p>,
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
export const blocks = createBlockRegistry(config, [pricing]);
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
**Reading the schema from barakoBrew.** The console usually runs on another origin than the site, so
|
|
451
|
+
a browser only lets its block editor read `app/api/blocks` when the site names that origin. Set
|
|
452
|
+
`PRESS_CONSOLE_ORIGINS` to a comma separated list, for example
|
|
453
|
+
`PRESS_CONSOLE_ORIGINS=https://brew.example.com`. It is read per request. Unset, no origin is
|
|
454
|
+
allowed. A listed origin gets `Access-Control-Allow-Origin` echoed back on `GET` and on the `OPTIONS`
|
|
455
|
+
preflight, never `*` and never credentials, and every answer carries `Vary: Origin`. Pass
|
|
456
|
+
`{ consoleOrigins: [...] }` to both factories to set the list in code instead.
|
|
457
|
+
|
|
458
|
+
Field kinds are `text`, `markdown`, `url`, `number`, `boolean`, `select` (with `options`) and `slots`
|
|
459
|
+
(lists of nested blocks, handed to the component already rendered). The list is editor input, so a
|
|
460
|
+
block renders only when its type is registered and every prop passes its field. A present but wrong
|
|
461
|
+
value fails the whole block, a `url` must pass the same check markdown links do, and a component
|
|
462
|
+
never receives a prop its fields did not declare. A page reads at most 400 blocks in total, nested
|
|
463
|
+
ones included, and ten levels deep. The count is spent on every block the binder walks through as
|
|
464
|
+
well as every one that comes out, so a band from the library costs eight or ten of it, and a page
|
|
465
|
+
that goes over loses its tail with nothing said.
|
|
466
|
+
|
|
467
|
+
`defineBlock<Props, SlotNames>` checks the fields against the props at compile time: every field
|
|
468
|
+
names a prop, its kind suits the prop's type, and a prop that is not optional must be `required`.
|
|
469
|
+
|
|
470
|
+
A component gets `props`, `slots` and `theme`, not the config, because a client component's props
|
|
471
|
+
are serialised into the page and the config holds the CMS address. A server block that needs the
|
|
472
|
+
config closes over it.
|
|
473
|
+
|
|
474
|
+
A block that shows something depending on who is looking sets `perViewer: true`. `createPage` leaves
|
|
475
|
+
such blocks out, because its output is cached and shared. `createViewerPage` renders them and calls
|
|
476
|
+
`connection()` first, so that route is always dynamic. Signing a viewer in, and gating a block by
|
|
477
|
+
role, is issue #7.
|
|
478
|
+
|
|
479
|
+
### Bindings
|
|
480
|
+
|
|
481
|
+
Any string prop can hold a placeholder, which is barakoCMS's workflow template syntax with an
|
|
482
|
+
optional format and fallback:
|
|
483
|
+
|
|
484
|
+
```json
|
|
485
|
+
{ "type": "text", "props": { "value": "Welcome to {{site.Name}}", "variant": "display" } }
|
|
486
|
+
{ "type": "text", "props": { "value": "{{item.Fee | money ?? Free}}" } }
|
|
487
|
+
{ "type": "text", "props": { "value": "{{page.PublishedAt | date}}" } }
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
Scopes are `site` (the tenant's settings and resolved identity), `page` (the entry the page
|
|
491
|
+
renders), `item` (the row inside a `source` or a `repeat`) and `query` (URL parameters). `viewer`
|
|
492
|
+
arrives with #7. Formats are `text`, `date`, `datetime`, `time`, `money`, `number`, `upper` and
|
|
493
|
+
`lower`; `money` uses the tenant's `Currency` setting, or a plain amount when it has none.
|
|
494
|
+
|
|
495
|
+
Paths, formats and fallbacks only. There are no expressions and no JavaScript. Everything resolves
|
|
496
|
+
on the server as the request's tenant, before a component is called, so a binding never makes the
|
|
497
|
+
browser call the API. A placeholder that finds no value renders its fallback and is reported in the
|
|
498
|
+
server log, never a crash. What a binding resolves to is checked against the field again, so a link
|
|
499
|
+
whose stored field holds `javascript:` drops the block; and a resolved value is never rescanned, so
|
|
500
|
+
one field cannot reach another through its own contents.
|
|
501
|
+
|
|
502
|
+
`source` loads one entry or a page of them and puts it in scope. `repeat` renders its content once
|
|
503
|
+
per row. `pager` draws prev and next links for the `source` it sits in, paged by the API. `showIf`
|
|
504
|
+
keeps its content only when a bound value has something, or equals what it names.
|
|
505
|
+
|
|
506
|
+
```json
|
|
507
|
+
{ "type": "source", "props": {
|
|
508
|
+
"collection": "enrolments", "mode": "list", "pageSize": 20, "pageParam": "p",
|
|
509
|
+
"filterField": "Class", "filterValue": "{{query.class}}",
|
|
510
|
+
"content": [[
|
|
511
|
+
{ "type": "repeat", "props": { "empty": "No one yet.", "content": [[
|
|
512
|
+
{ "type": "text", "props": { "value": "{{item.Title}}" } }
|
|
513
|
+
]] } },
|
|
514
|
+
{ "type": "pager", "props": {} }
|
|
515
|
+
]]
|
|
516
|
+
} }
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
A filter narrows what the API already lets the reader see. It is never access control: who may read
|
|
520
|
+
which rows is decided in barakoCMS. A page reads at most eight sources, and a `source` at most fifty
|
|
521
|
+
rows a page.
|
|
522
|
+
|
|
523
|
+
### Presets
|
|
524
|
+
|
|
525
|
+
A preset is a named block saved as data, not code: a few props and an arrangement of primitives that
|
|
526
|
+
reads them through the `props` scope. A designer saves one in barakoBrew and every site on the
|
|
527
|
+
published image can use it, with no barakoPress release.
|
|
528
|
+
|
|
529
|
+
```json
|
|
530
|
+
{
|
|
531
|
+
"type": "band",
|
|
532
|
+
"label": "Band",
|
|
533
|
+
"fields": [
|
|
534
|
+
{ "name": "heading", "kind": "text", "required": true },
|
|
535
|
+
{ "name": "tone", "kind": "select", "options": ["page", "accent"] },
|
|
536
|
+
{ "name": "content", "kind": "slots" }
|
|
537
|
+
],
|
|
538
|
+
"blocks": [
|
|
539
|
+
{ "type": "section", "props": { "tone": "{{props.tone}}", "content": [[
|
|
540
|
+
{ "type": "text", "props": { "value": "{{props.heading}}", "variant": "title" } },
|
|
541
|
+
{ "type": "slot", "props": { "name": "content" } }
|
|
542
|
+
]] } }
|
|
543
|
+
]
|
|
544
|
+
}
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
A request-time site reads its tenant's presets from the `Presets` site setting. A build-time site
|
|
548
|
+
passes them as `presets` in the config. A preset never replaces a block that is code. It does
|
|
549
|
+
replace a preset, which is how a tenant adjusts one of the shipped blocks below without waiting for
|
|
550
|
+
a release. A preset body may not use another preset saved in the same pass, so a cycle cannot form;
|
|
551
|
+
it may use one compiled earlier, which is how a tenant's own block builds on a shipped one. `slot` marks where the content an editor dropped into the preset
|
|
552
|
+
goes, and that content binds in the page's scope rather than the preset's.
|
|
553
|
+
|
|
554
|
+
A preset that is not used says why, once, in the server log, with one line per reason rather than one
|
|
555
|
+
catchall: an entry that is not a preset, a type that is not a name, a type an earlier preset already
|
|
556
|
+
uses, a field list that is not a list, fields inside it that are not fields, a name a registered
|
|
557
|
+
block already has, and the presets past the point where a tenant's bodies hold more than 400 blocks
|
|
558
|
+
between them. A setting that quietly does nothing reads as done, which is worse than one that is
|
|
559
|
+
missing. A bad paste is spelled out five times and then counted.
|
|
560
|
+
|
|
561
|
+
### The block library
|
|
562
|
+
|
|
563
|
+
Every site gets these, compiled in from the primitives. None of them is code, so a site that wants
|
|
564
|
+
one to look different saves its own under the same name and that one wins.
|
|
565
|
+
|
|
566
|
+
| Block | What it is | Props |
|
|
567
|
+
| --- | --- | --- |
|
|
568
|
+
| `hero` | The band at the head of a page | heading, body, image, imageAlt, primaryLabel, primaryHref, secondaryLabel, secondaryHref, tone, columns, align, padding |
|
|
569
|
+
| `band` | Copy with one call to action | tone, heading, body, label, href, align, padding, width |
|
|
570
|
+
| `statBand` | A row of figures | heading, tone, columns, padding, items |
|
|
571
|
+
| `cardGrid` | Cards from a collection | heading, collection, filterField, filterValue, empty, tone, columns, padding, hueRotate, option |
|
|
572
|
+
| `peopleGrid` | People from a collection, typed in place, or both | heading, collection, filterField, filterValue, role, tone, columns, padding, items |
|
|
573
|
+
| `timeline` | Dated entries | heading, tone, padding, width, items |
|
|
574
|
+
| `steps` | Numbered entries | heading, tone, padding, width, items |
|
|
575
|
+
| `tiers` | Giving or pricing tiers | heading, tone, columns, padding, items |
|
|
576
|
+
| `keyValueTable` | A panel of facts | heading, tone, padding, radius, rows |
|
|
577
|
+
| `tabs` | Sections that open | heading, tone, padding, width, items |
|
|
578
|
+
| `announcement` | The one line above everything, and it stays there | message, label, href, tone, edge, align |
|
|
579
|
+
| `codeTabs` | A snippet to run, with the other ways behind it | heading, body, code, language, selectLabel, tone, padding, width, items |
|
|
580
|
+
| `progressList` | How far along each entry of a collection is | heading, collection, filterField, filterValue, empty, tone, padding, width |
|
|
581
|
+
| `changelogList` | Release entries, with the word for the kind of release | heading, collection, filterField, filterValue, empty, tone, padding, width |
|
|
582
|
+
| `faq` | Questions, all openable at once | heading, body, tone, padding, width, items |
|
|
583
|
+
| `map` | An embedded map, held to `embedHosts` | src, title, heading, aspect, tone, padding |
|
|
584
|
+
| `stat` | One figure and its label | value, label, align, motion |
|
|
585
|
+
| `timelineEntry` | One dated entry | date, title, body |
|
|
586
|
+
| `step` | One numbered step | number, title, body |
|
|
587
|
+
| `tier` | One tier | name, amount, body, label, href, tone |
|
|
588
|
+
| `person` | One person | name, role, photo, href, linkLabel, align |
|
|
589
|
+
| `keyValueRow` | One fact | label, value |
|
|
590
|
+
| `codeTab` | One more way to run it | label, code, language, selectLabel, group |
|
|
591
|
+
| `faqItem` | One question and its answer | question, answer, tone |
|
|
592
|
+
|
|
593
|
+
The blocks in the second half go in the first half's slots: stats in a `statBand`, entries in a
|
|
594
|
+
`timeline`, `disclosure` blocks in `tabs`, `codeTab` blocks in `codeTabs`, `faqItem` blocks in
|
|
595
|
+
`faq`. A card grid reads its entries through `{{item.Title}}`, `{{item.Summary}}`,
|
|
596
|
+
`{{item.Date | date}}` and `{{item.Href}}`, so it works against whatever the tenant calls those
|
|
597
|
+
fields, and it takes the collection as a prop rather than knowing any name.
|
|
598
|
+
|
|
599
|
+
Set a card grid's `option` to `show` and each card carries the glyph and the word the site declared
|
|
600
|
+
for that entry's option, read through `{{item.Icon}}` and `{{item.Word}}`. With `filterField` and
|
|
601
|
+
`filterValue` picking the category, that is a module grid: one band per category, each card marked
|
|
602
|
+
with its own. It is off by default, so a grid that did not ask for it draws what it always drew.
|
|
603
|
+
|
|
604
|
+
`progressList` reads its figure through `{{item.Progress}}`, which is the collection's `progress`
|
|
605
|
+
field role: the tenant says which of its own fields holds a number from 0 to 100. `changelogList`
|
|
606
|
+
does not group by itself, because grouping means knowing which field holds the kind and that is the
|
|
607
|
+
tenant's field name. One band per kind with `filterField` and `filterValue` is the grouping, and the
|
|
608
|
+
chip on each entry is the option's own word.
|
|
609
|
+
|
|
105
610
|
## Configuring it
|
|
106
611
|
|
|
107
612
|
`press.config.ts` is the one file a site owns, and the seam the whole package turns on.
|
|
@@ -125,25 +630,396 @@ without: the engine never asks the API for that data and never renders an empty
|
|
|
125
630
|
reference type you do not have is worse than useless, because `include=Author` is a 400 from the API
|
|
126
631
|
for a post type with no such field.
|
|
127
632
|
|
|
128
|
-
| Key | Default | What |
|
|
633
|
+
| Key | Default | Tenant setting | What |
|
|
634
|
+
| --- | --- | --- | --- |
|
|
635
|
+
| `site` | required | `Name`, `Tagline`, `Url` and one per field | Name, tagline and absolute origin. Every absolute link is built from the origin |
|
|
636
|
+
| `types` | `post`, `author`, `category` | operator only | The content type names |
|
|
637
|
+
| `fields` | the blueprint's PascalCase names | operator only | Which field holds what |
|
|
638
|
+
| `pageFields` | the blueprint's PascalCase names | operator only | Which field on the page type holds what |
|
|
639
|
+
| `routes` | `/blog`, `/authors`, `/categories` | operator only | Where you mounted each route |
|
|
640
|
+
| `pageSizes` | 20, 50, 1000, 50 | `PageSizes` | Index, feed, sitemap, archive. The sitemap one bounds the entries one collection contributes, and is not a page size: the sitemap pages to that number at whatever size the API allows |
|
|
641
|
+
| `cacheTag` | `cms` | operator only | The tag this site purges. Two sites on one server need two tags |
|
|
642
|
+
| `backstopSeconds` | 300 | operator only | How long a cached read may live with no webhook. 0 disables it |
|
|
643
|
+
| `cmsTimeoutMs` | 5000 | operator only | How long any one call to the CMS may take, a share link redemption included. Past it the call has failed, and a request-time site answers from its last good copy |
|
|
644
|
+
| `locale` | `en-GB` | `Locale` | Passed to `toLocaleDateString` |
|
|
645
|
+
| `currency` | none | `Currency` | The ISO code a `money` binding formats with. Unset, an amount renders as a plain number |
|
|
646
|
+
| `embedHosts` | seven player hosts | `EmbedHosts` | The hosts an `embed` block may frame |
|
|
647
|
+
| `presets` | none | `Presets` | Named blocks saved as arrangements of primitives. See Presets |
|
|
648
|
+
| `cmsUrl` | `CMS_URL`, or `http://localhost:5005` | operator only | Where the CMS is, from this server. The variable is read when the CMS is called, not when this file runs |
|
|
649
|
+
| `tenant` | `CMS_TENANT` | operator only | Tenant slug, for a multi-tenant deployment. On a request-time site, pins every host to it. The variable is read when the CMS is called, not when this file runs |
|
|
650
|
+
| `sites` | off | operator only | Request-time identity and theme from the tenant's site settings. See below |
|
|
651
|
+
| `pages` | off | operator only | Where the Pages module's pages are mounted. `""` is the site root. It has to match a route file on disk, which is why it is not a tenant's to set |
|
|
652
|
+
| `reservedSlugs` | the routes and the engine's files | `ReservedSlugs`, added to them | First path segments a root-mounted page may not take. Adds to the defaults |
|
|
653
|
+
| `regions` | off | `HeaderPath`, `HeaderTone`, `FooterPath`, `FooterTone` | The header and the footer as block regions |
|
|
654
|
+
| `collections` | the blog's `post`, `author` and `category` | `Collections` | Content types rendered as lists and detail pages. See Collections |
|
|
655
|
+
| `optionStyles` | none | `OptionStyles` | Tone, icon and label by `type.field` and option, for `colorBy` |
|
|
656
|
+
| `optionColors` | none | `OptionColors` | The same, when a tone is all an option has. Read as `optionStyles` |
|
|
657
|
+
| `labels` | English | `Labels` | The words the screens print for a visitor. See below |
|
|
658
|
+
| `store` | in process | operator only | Where the state a fleet has to agree on is kept: kept answers, the host map, the replay guard, the generation of each cache tag. Needed only when more than one container serves the site. See below |
|
|
659
|
+
| `home` | the post index | `HomePath`, `HomeCollection` | What `createHome` serves at `/`. See below |
|
|
660
|
+
| `theme` | the barakoCMS palette | `Colors`, `Fonts`, `Radii`, `Layout`, `Space`, `Text` | Colours, faces, radii and column widths. See below |
|
|
661
|
+
|
|
662
|
+
The third column is the whole of the split. A key marked operator only is one the image decides for
|
|
663
|
+
every tenant it serves, and each is that for a reason you can name: `types`, `fields`, `pageFields`
|
|
664
|
+
and `routes` are what the blog factories compile against, `cacheTag`, `backstopSeconds`,
|
|
665
|
+
`cmsTimeoutMs`, `cmsUrl`, `tenant`, `sites` and `store` are facts about the deployment rather than
|
|
666
|
+
the site,
|
|
667
|
+
and `pages` has to match a route file on disk. Everything else is that tenant's data, edited in
|
|
668
|
+
barakoBrew, and wins over what this file said. A tenant that sets nothing renders exactly as the
|
|
669
|
+
file says.
|
|
670
|
+
|
|
671
|
+
### The environment
|
|
672
|
+
|
|
673
|
+
Every environment value this package reads goes through one reader, `readEnv` in `src/env.ts`, and
|
|
674
|
+
every one of them is read on the call that uses it. None is read when `press.config.ts` runs. That
|
|
675
|
+
used to differ per variable: `CMS_URL` and `CMS_TENANT` were read inside `defineConfig`, the rest
|
|
676
|
+
per request, so when a value was read depended on which value it was.
|
|
677
|
+
|
|
678
|
+
| Variable | What it sets |
|
|
679
|
+
| --- | --- |
|
|
680
|
+
| `CMS_URL` | Where the delivery API is. `cmsUrl` in the config wins |
|
|
681
|
+
| `CMS_TENANT` | Pins the process to one tenant. `tenant` in the config wins |
|
|
682
|
+
| `CMS_DEFAULT_TENANT` | The tenant for a host the CMS does not know. `sites.defaultTenant` wins |
|
|
683
|
+
| `CMS_RENDERER_KEY` | Sent to the CMS when a share link is redeemed. See [Share links](#one-build-many-sites) |
|
|
684
|
+
| `PRESS_CONSOLE_ORIGINS` | Browser origins allowed to read the block schema, comma separated |
|
|
685
|
+
| `PRESS_SECRET` | The HMAC key for everything this renderer signs. See [One secret](#one-secret) |
|
|
686
|
+
| `REVALIDATE_SECRET` | The webhook key before `PRESS_SECRET`, read only while that is unset |
|
|
687
|
+
| `PRESS_PREVIEW_SECRET` | The share key before `PRESS_SECRET`, read only while that is unset |
|
|
688
|
+
|
|
689
|
+
Values are used exactly as the environment has them, untrimmed. A secret with a trailing space is a
|
|
690
|
+
different HMAC key, so trimming one here would stop a webhook that verifies today.
|
|
691
|
+
|
|
692
|
+
**A site is build time or request time.** Without `sites`, identity is build time: the index, the
|
|
693
|
+
feed, the sitemap and robots are prerendered, so anything *your own* `press.config.ts` reads from the
|
|
694
|
+
environment is baked when you build, not when the server starts. Write per-site values as literals in
|
|
695
|
+
that file. Getting this wrong is how a client site ships with the vendor's name in its masthead. With
|
|
696
|
+
`sites`, identity is data in the CMS and read per request, which is the next section.
|
|
697
|
+
|
|
698
|
+
### One build, many sites
|
|
699
|
+
|
|
700
|
+
barakoCMS D22 reverses "identity is build time" for the shared renderer: every site runs the same
|
|
701
|
+
image, and what makes a site that site is its tenant's `site` settings entry, edited in barakoBrew.
|
|
702
|
+
|
|
703
|
+
```ts
|
|
704
|
+
export const config = defineConfig({ sites: {} });
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
A request-time site puts its page routes under one tenant segment and adds a `proxy.ts` beside
|
|
708
|
+
`app/`:
|
|
709
|
+
|
|
710
|
+
```
|
|
711
|
+
proxy.ts export default createPressProxy(config)
|
|
712
|
+
app/
|
|
713
|
+
%5Fpress/[site]/ the tenant segment. %5F is `_`, which Next reads as a
|
|
714
|
+
layout.tsx private folder when it is written plainly
|
|
715
|
+
page.tsx
|
|
716
|
+
[...path]/page.tsx
|
|
717
|
+
blog/[slug]/page.tsx
|
|
718
|
+
feed.xml/route.ts these resolve their own tenant and stay where they are
|
|
719
|
+
robots.ts
|
|
720
|
+
sitemap.ts
|
|
721
|
+
api/...
|
|
722
|
+
%5Fshare/route.ts
|
|
723
|
+
```
|
|
724
|
+
|
|
725
|
+
```ts
|
|
726
|
+
// proxy.ts
|
|
727
|
+
import { createPressProxy } from "barakopress";
|
|
728
|
+
import { config } from "@/press.config";
|
|
729
|
+
|
|
730
|
+
export default createPressProxy(config);
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
The proxy resolves the tenant and the share session once and rewrites to
|
|
734
|
+
`/_press/<tenant>~<gate>~<host>/<path>`. The pages read all three out of that segment, so nothing in
|
|
735
|
+
a page reads a header or a cookie, and Next can keep the render. Why the tenant has to be in the
|
|
736
|
+
path, and what is cached and what is not, is [The render cache](#the-render-cache) below. A build-time
|
|
737
|
+
site needs none of this and keeps its routes where they are.
|
|
738
|
+
|
|
739
|
+
On each request the engine resolves the tenant, reads that tenant's settings, and renders with them:
|
|
740
|
+
|
|
741
|
+
1. `CMS_TENANT` (or `tenant`) set: every host is that tenant, with no lookup.
|
|
742
|
+
2. `sites.tenantHeader` set and the request carries a valid handle in it: that tenant. Off by default.
|
|
743
|
+
3. The host, from `sites.hostHeader` (default `host`), looked up with `GET /api/tenants/by-host/{host}`.
|
|
744
|
+
4. `sites.defaultTenant`, or `CMS_DEFAULT_TENANT`, read at request time.
|
|
745
|
+
5. None of those: a 404. Never another tenant's site.
|
|
746
|
+
|
|
747
|
+
A handle is only ever read from the request through a header the operator named. `X-Tenant` and
|
|
748
|
+
`X-Forwarded-Host` sent by a caller are ignored unless you configure them, and you should configure
|
|
749
|
+
them only behind a proxy that sets the header and strips a caller's value.
|
|
750
|
+
|
|
751
|
+
The settings are the singleton `site` type from barakoCMS `docs/site-settings.md`
|
|
752
|
+
(`POST /api/content-types/blueprints/site`, then publish its one entry). The engine reads `Name`,
|
|
753
|
+
`Tagline`, `Url`, `Locale`, `Logo`, `LogoAlt`, `FooterLogo`, `Favicon`, `ShareImage`, `Copyright`,
|
|
754
|
+
`Colors` (the theme slots), `Fonts` (a family name per role, and the stylesheet that loads it),
|
|
755
|
+
`Radii`, `Layout`, `TopBar`, `HeaderLinks`, `FooterColumns`, `SocialLinks`, `HeaderPath`,
|
|
756
|
+
`HeaderTone`, `FooterPath`, `FooterTone`, `AssetsAsSupplied`, `LogoAsSupplied`, `LogoClearSpace`,
|
|
757
|
+
`PageSizes`, `ReservedSlugs`, `Labels`, `HomePath` and `HomeCollection`. `Collections`, `OptionStyles` and `OptionColors` are read as the collections section
|
|
758
|
+
describes. `Variants` are not rendered yet. Every value is checked for shape; one that fails, and any the
|
|
759
|
+
entry leaves out, keeps the configured value, so a half-filled theme renders. A link is a path on the
|
|
760
|
+
site or an absolute http or https URL. Set `Url`: without it the feed and sitemap fall back to the
|
|
761
|
+
host the tenant was found by.
|
|
762
|
+
|
|
763
|
+
`createSiteLayout` and `createSiteMetadata` render the root layout from all of this: `lang`, the
|
|
764
|
+
faces, the palette, the top bar, header links, footer columns, social links and the copyright line.
|
|
765
|
+
|
|
766
|
+
**What the site serves at `/`.** Every site used to be a blog at the root, because the root route
|
|
767
|
+
mounted the post index and nothing else could be named:
|
|
768
|
+
|
|
769
|
+
| Field | Type | What |
|
|
770
|
+
| --- | --- | --- |
|
|
771
|
+
| `HomePath` | string | A site path such as `/home`. The page the Pages module serves there is the home page. Nothing served there falls back to the index, so naming a page before writing it is safe |
|
|
772
|
+
| `HomeCollection` | string | The key of a collection. Its index is the home page. `HomePath` wins when both are set |
|
|
773
|
+
|
|
774
|
+
Neither set, `/` is the post index, which is what it was. The blog's own `post`, `author` and
|
|
775
|
+
`category` are ordinary `Collections` entries now, so a school whose news lives in `article` with a
|
|
776
|
+
`Headline` replaces `post` in its settings and gets both its list and its item pages from that entry.
|
|
777
|
+
The RSS link in the built-in header, and the feed alternate in the page metadata, appear only when
|
|
778
|
+
some collection has `feed` on, so a clinic with no posts stops advertising an empty feed.
|
|
779
|
+
|
|
780
|
+
**The words a visitor reads.** `Labels` is the visitor-facing copy, key by key. A school setting
|
|
781
|
+
`Locale` to `fil-PH` used to get Filipino dates beside English "min read" and "Related":
|
|
782
|
+
|
|
783
|
+
```json
|
|
784
|
+
{ "Labels": { "minRead": "minutong pagbasa", "by": "ni", "related": "Kaugnay" } }
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
| Key | English |
|
|
788
|
+
| --- | --- |
|
|
789
|
+
| `minRead` | `min read` |
|
|
790
|
+
| `by` | `by` |
|
|
791
|
+
| `related` | `Related` |
|
|
792
|
+
| `relatedNote` | `cosine similarity, computed on load, not curated` |
|
|
793
|
+
| `featured` | `Featured` |
|
|
794
|
+
| `back` | `Back` |
|
|
795
|
+
| `home` | `Home` |
|
|
796
|
+
| `preview` | The banner over a draft being previewed |
|
|
797
|
+
| `untitled` | `Untitled` |
|
|
798
|
+
| `feed` | `RSS` |
|
|
799
|
+
| `empty`, `emptyNote` | The notice on an index with nothing published |
|
|
800
|
+
| `failed`, `failedNote` | The notice on an index whose read failed |
|
|
801
|
+
| `shareInvalid` | `This link is not valid or has expired.` |
|
|
802
|
+
|
|
803
|
+
A key left out, or saved as anything but a word, keeps the English, so a half-filled map reads. A
|
|
804
|
+
build-time site passes `labels` to `defineConfig`. Nothing about a site's own content is here: a
|
|
805
|
+
collection's heading is its `label` and how its count reads is its `noun`.
|
|
806
|
+
|
|
807
|
+
**The colour slots, by role.** `Colors` sets any slot of the palette, one at a time. The slots are
|
|
808
|
+
`pageBg`, `surface`, `ink`, `proseInk`, `secondaryInk`, `muted`, `hairline`, `accent`, `accentHover`,
|
|
809
|
+
`accentInk`, `accentTint`, `accentTintBorder`, `accentBorderStrong`, `inverse`, `inverseChrome`,
|
|
810
|
+
`inverseInk`, `inverseAccent`, `code` and `success`. A role says where a colour goes rather than what
|
|
811
|
+
it looks like: `inverse` is the band that reverses the page, the footer and a code panel and an
|
|
812
|
+
inverse block, so a bakery with a cream footer sets `inverse` to cream and reads right doing it.
|
|
813
|
+
|
|
814
|
+
```json
|
|
815
|
+
{ "Colors": { "accent": "#17458F", "inverse": "#F4E3C1", "inverseInk": "#3B2A17" } }
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
Six slots shipped in 0.3.0 under barakocms.com's own names, and those still work: `darkPanel`,
|
|
819
|
+
`darkPanelChrome`, `darkPanelInk`, `darkPanelAccent`, `codeGreen` and `accentTintBorderStrong` are
|
|
820
|
+
read into `inverse`, `inverseChrome`, `inverseInk`, `inverseAccent`, `code` and `accentBorderStrong`.
|
|
821
|
+
Setting either name sets both, so a tenant saved before the rename keeps its site and a consumer's
|
|
822
|
+
own component reading `theme.colors.darkPanel` keeps compiling. The old names are deprecated and go
|
|
823
|
+
in 2.0.0. An `OptionStyles` or `OptionColors` entry naming an old slot resolves too.
|
|
824
|
+
|
|
825
|
+
Sizes work the same way. `Text` is the type scale by role, `meta`, `small`, `body`, `lead`,
|
|
826
|
+
`subheading`, `heading`, `title`, `display` and `pageTitle`, and `Space` is the spacing scale. The
|
|
827
|
+
blocks and the screens read those names, so a tenant that wants bigger headings sets `title` once
|
|
828
|
+
instead of asking for a release.
|
|
829
|
+
|
|
830
|
+
**How many items, per tenant.** `PageSizes` sets the four counts for this site, each on its own:
|
|
831
|
+
|
|
832
|
+
```json
|
|
833
|
+
{ "PageSizes": { "index": 50 } }
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
A bakery listing 50 products and an agency listing 9 case studies run the same image. A key the
|
|
837
|
+
entry leaves out keeps the configured count, and a collection's own `pageSize` still wins over the
|
|
838
|
+
site's. barakoCMS clamps a public list at 100 whatever is asked for, so a larger number is not an
|
|
839
|
+
error and does not buy more rows.
|
|
840
|
+
|
|
841
|
+
**Paths this site does not serve.** `ReservedSlugs` adds to the configured reserved list:
|
|
842
|
+
|
|
843
|
+
```json
|
|
844
|
+
{ "ReservedSlugs": ["shop", "status"] }
|
|
845
|
+
```
|
|
846
|
+
|
|
847
|
+
A first segment on it is left out of the menu and the sitemap, and a page there is never asked for.
|
|
848
|
+
It is what a proxy in front of this domain answers instead of the renderer, which is a fact about
|
|
849
|
+
one tenant rather than about the image. It only ever adds: a tenant cannot free a segment the app's
|
|
850
|
+
own routes already hold, because a page there would sit behind a route file and render nowhere. A
|
|
851
|
+
tenant's collection routes need no entry, since those are read off its settings already.
|
|
852
|
+
|
|
853
|
+
**Fonts, from an allow list.** A family name on its own is loaded from Google Fonts, which is what it
|
|
854
|
+
has always meant:
|
|
855
|
+
|
|
856
|
+
```json
|
|
857
|
+
{ "Fonts": { "heading": "Zilla Slab" } }
|
|
858
|
+
```
|
|
859
|
+
|
|
860
|
+
A site that cannot use Google Fonts, a school with a licensed face on its own host or a tenant that
|
|
861
|
+
must not send visitor addresses to a third party, names the stylesheet instead:
|
|
862
|
+
|
|
863
|
+
```json
|
|
864
|
+
{ "Fonts": { "heading": { "family": "Zilla Slab", "url": "https://type.school.example/zilla.css" } } }
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
That URL is a tenant's setting on its way into a `<link>` in every visitor's page, so which origins a
|
|
868
|
+
page may reach is the deployment's decision and not the tenant's. `PRESS_FONT_ORIGINS` is the list:
|
|
869
|
+
origins separated by commas or spaces, each `https://host`, a bare host read as https.
|
|
870
|
+
|
|
871
|
+
| `PRESS_FONT_ORIGINS` | What a page may link |
|
|
872
|
+
| --- | --- |
|
|
873
|
+
| unset or blank | Google Fonts, and nothing else. This is what every site rendered before the list existed |
|
|
874
|
+
| `https://type.school.example` | That origin only. Nothing goes to Google Fonts, the built-in link and its preconnects included |
|
|
875
|
+
| `fonts.googleapis.com, type.school.example` | Both |
|
|
876
|
+
|
|
877
|
+
A URL on any other origin is refused: no link to it is rendered, the role falls back to its family
|
|
878
|
+
name, and the server log says so once rather than once a page view. The list replaces the default
|
|
879
|
+
rather than adding to it, which is what gives a tenant that must not reach Google Fonts a deployment
|
|
880
|
+
where nothing can. `createSiteLayout(config, { loadFonts: false })` still turns off every font link
|
|
881
|
+
for the whole image.
|
|
882
|
+
|
|
883
|
+
Only an absolute https URL is kept, for the whole chain: http is blocked as mixed content on every
|
|
884
|
+
site this serves, so allowing it would mean rendering a link that never loads. A role the tenant names
|
|
885
|
+
is the tenant's, family and stylesheet together, so a family set with no url clears a configured
|
|
886
|
+
stylesheet rather than leaving the page loading a face it no longer uses. A build-time site sets the
|
|
887
|
+
same thing in `theme.fontSources`, and it is held to the same list.
|
|
888
|
+
|
|
889
|
+
**Header and footer as block regions.** The built-in header and footer take links and text and
|
|
890
|
+
nothing else, so a clinic that wants a light footer with opening hours and a map cannot have one, and
|
|
891
|
+
a school that wants an enrolment banner with a button cannot either. Point a region at a page and its
|
|
892
|
+
blocks are drawn there instead, resolved and bound exactly as the page route resolves and binds them.
|
|
893
|
+
|
|
894
|
+
| Field | Type | What |
|
|
129
895
|
| --- | --- | --- |
|
|
130
|
-
| `
|
|
131
|
-
| `
|
|
132
|
-
| `
|
|
133
|
-
| `
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
896
|
+
| `HeaderPath` | string | A site path such as `/site/header`. The page served there is drawn in place of the top bar and the header band |
|
|
897
|
+
| `HeaderTone` | string | `page`, `surface`, `accent` or `inverse`: the tone behind the header region. `page` when unset or not one of the four |
|
|
898
|
+
| `FooterPath` | string | A site path such as `/site/footer`. The page served there is drawn in place of the footer |
|
|
899
|
+
| `FooterTone` | string | The same four names, behind the footer region |
|
|
900
|
+
|
|
901
|
+
Set neither and nothing changes: `TopBar`, `HeaderLinks`, `FooterColumns`, `SocialLinks` and
|
|
902
|
+
`Copyright` draw the built-in chrome with the markup they always had, which is what keeps a site
|
|
903
|
+
whose own CSS keys off that markup rendering. A path with nothing served at it does the same, so
|
|
904
|
+
naming a page before writing it is safe, and so is a typo.
|
|
905
|
+
|
|
906
|
+
A region page is chrome rather than somewhere to go, so it is left out of the menu and the sitemap.
|
|
907
|
+
It still answers on its own route, which is how an editor opens it to work on it.
|
|
908
|
+
|
|
909
|
+
A header region replaces the whole band, the site name, the menu and the RSS link along with the top
|
|
910
|
+
bar. There is no navigation or logo block yet, so a header region lists its own links until the block
|
|
911
|
+
library has one.
|
|
912
|
+
|
|
913
|
+
A build-time site sets the same thing in its config, and a tenant's settings win over it:
|
|
914
|
+
|
|
915
|
+
```ts
|
|
916
|
+
export const config = defineConfig({
|
|
917
|
+
site: { name: "Mabini Clinic", url: "https://clinic.example" },
|
|
918
|
+
pages: "",
|
|
919
|
+
regions: { footer: { path: "/site/footer", tone: "surface" } },
|
|
920
|
+
});
|
|
921
|
+
```
|
|
922
|
+
|
|
923
|
+
The registry the regions render with is the one passed to `createSiteLayout(config, { blocks })`, and
|
|
924
|
+
the built-in blocks when none was passed.
|
|
925
|
+
|
|
926
|
+
**Caching per tenant.** Every read carries the tenant in `X-Tenant` and in its cache tag,
|
|
927
|
+
`<cacheTag>:<tenant>`, and a narrower tag beside it: `<tenant tag>:entry:<type>:<slug>` on a read of
|
|
928
|
+
one entry, `<tenant tag>:type:<type>` on a list, a search, the settings and the page tree. The webhook
|
|
929
|
+
purges the tags of the tenant its host resolves to, so point each tenant's webhook at
|
|
930
|
+
`https://<that tenant's domain>/api/revalidate`, signed with that tenant's own key (see
|
|
931
|
+
[One key per tenant](#one-key-per-tenant)). A publish on one tenant leaves every other tenant's cached
|
|
932
|
+
reads in place.
|
|
933
|
+
|
|
934
|
+
**When the CMS is down.** Each successful read is also kept in the store, keyed by CMS, tenant and path.
|
|
935
|
+
A read that fails with a network error, a 5xx, or no answer within `cmsTimeoutMs` answers from the
|
|
936
|
+
last good copy and logs a warning; the next successful read replaces it. For ten seconds after such a
|
|
937
|
+
failure that read answers from the copy without asking the CMS, so an outage costs one request per
|
|
938
|
+
read every ten seconds rather than one per visitor. The same holds after a purge: a publish that lands
|
|
939
|
+
within those ten seconds shows once the ten seconds are up. Known hosts keep resolving the same way. A page that was cached
|
|
940
|
+
for a tenant keeps answering 200 with that tenant's identity and theme. A tenant never gets another
|
|
941
|
+
tenant's kept answer.
|
|
942
|
+
|
|
943
|
+
**Holding mode.** A tenant can show a holding page on every route in place of its site, for a launch,
|
|
944
|
+
maintenance or a seasonal break, and share the real site with a few people through site share links.
|
|
945
|
+
Three fields on the `site` entry control it:
|
|
946
|
+
|
|
947
|
+
| Field | Type | What |
|
|
948
|
+
| --- | --- | --- |
|
|
949
|
+
| `Mode` | string | `Live` or `Holding`. Unset, or anything else, is `Live` |
|
|
950
|
+
| `HoldingPath` | string | A site path such as `/coming-soon`. The page the Pages module serves there is the holding page. Empty, or nothing served there, renders the default holding page: the name, the tagline and `HoldingMessage`, in the theme |
|
|
951
|
+
| `HoldingMessage` | string | The line the default holding page shows under the name and tagline, as text, for example `Closed until 6 January.` Unset or blank shows no line. Read only while holding. For more than a sentence, use `HoldingPath` |
|
|
952
|
+
|
|
953
|
+
Holding is presentation, not access control: the API still delivers every published entry. Content
|
|
954
|
+
that must stay hidden before launch stays unpublished with a scheduled publish.
|
|
955
|
+
|
|
956
|
+
While a tenant is holding, for that tenant only:
|
|
957
|
+
|
|
958
|
+
- every page answers the holding page with `noindex` and `Cache-Control: private, no-store`. A page
|
|
959
|
+
stops in `siteConfig` with a not-found before it reads anything, so its content and its title never
|
|
960
|
+
reach the response. Next has already sent the status by then, so it is 200, the same for a path
|
|
961
|
+
that exists and one that does not;
|
|
962
|
+
- the holding page is read with `GET /api/public/pages/resolve?path=<HoldingPath>` and rendered with
|
|
963
|
+
the page renderer and the registry passed to `createSiteLayout(config, { blocks })`;
|
|
964
|
+
- a link to `HoldingPath` is left out of the header, top bar and footer. `feed.xml` and `sitemap.xml`
|
|
965
|
+
are 404 for everyone, session or not, and `robots.txt` answers `Disallow: /` with no sitemap line;
|
|
966
|
+
- route handlers (revalidate, blocks, `/_share`, `/api/share/redeem`) and `/_next/static` are served
|
|
967
|
+
as usual.
|
|
968
|
+
|
|
969
|
+
Switching `Mode` is a publish: the webhook drops the tag the settings read carries and the next
|
|
970
|
+
request reads the new settings. No deploy.
|
|
971
|
+
|
|
972
|
+
**Site share links.** barakoCMS creates, lists and revokes them; anyone who may update the `site` type
|
|
973
|
+
can. A client is given `{site Url}/_share#{key}`. The key is in the fragment, so no server log, proxy
|
|
974
|
+
or referrer sees it:
|
|
975
|
+
|
|
976
|
+
1. `/_share` is a tiny page. Its script reads the fragment, removes it from the address and history,
|
|
977
|
+
and posts the key in a form to `/api/share/redeem`. Without JavaScript it says the link needs
|
|
978
|
+
JavaScript. No key is ever accepted in a query string.
|
|
979
|
+
2. `/api/share/redeem` asks barakoCMS once, `POST /api/public/site/share-links/redeem` with the key in
|
|
980
|
+
the body and the tenant header. On 200 it sets `__Host-press-share` (HttpOnly, Secure,
|
|
981
|
+
SameSite=Lax, Path=/, no Domain, so only that host gets it) and answers a `no-store` 303 to `/`.
|
|
982
|
+
On 404, 429 or any failure it sets nothing and sends the visitor to `/#share-invalid`, the holding
|
|
983
|
+
page with "This link is not valid or has expired." A post whose `Origin` or `Sec-Fetch-Site` names
|
|
984
|
+
another site is refused the same way. The key is never logged.
|
|
985
|
+
3. With a valid cookie that visitor sees the real site for that tenant. A forged, expired or
|
|
986
|
+
other-tenant cookie is ignored.
|
|
987
|
+
|
|
988
|
+
The cookie holds no key. It is an expiry and an HMAC-SHA256 over the tenant and that expiry, so each
|
|
989
|
+
later request is checked in process without asking the CMS, and a cookie made for one tenant opens no
|
|
990
|
+
other. It needs one setting:
|
|
991
|
+
|
|
992
|
+
| Variable | What |
|
|
993
|
+
| --- | --- |
|
|
994
|
+
| `PRESS_SECRET` | The HMAC key, at least 32 characters, for example `openssl rand -base64 48`. Read per request. Unset or shorter, no session is issued or accepted and everyone gets the holding page. Every instance behind one domain needs the same value. `PRESS_PREVIEW_SECRET` is read in its place when `PRESS_SECRET` is unset. See [One secret](#one-secret) |
|
|
995
|
+
| `CMS_RENDERER_KEY` | Optional. Sent to barakoCMS as `X-Barako-Renderer-Key` when a link is redeemed, and must match the renderer key barakoCMS is configured with. Read per request and never logged. Unset, no key header is sent |
|
|
996
|
+
|
|
997
|
+
**Redemption is rate limited per tenant and visitor.** Every redemption leaves this container from the
|
|
998
|
+
same address, so barakoCMS needs the visitor's address to tell visitors apart. Name the header a
|
|
999
|
+
proxy in front sets it in, `sites: { visitorIpHeader: "x-real-ip" }`, and it is sent on as
|
|
1000
|
+
`X-Barako-Visitor-IP`. Name it only behind a proxy that sets that header and strips a caller's value,
|
|
1001
|
+
the same rule as `hostHeader` and `tenantHeader`. A value that is not exactly one IPv4 or IPv6
|
|
1002
|
+
address, a comma separated list included, is not sent. barakoCMS trusts the address only when
|
|
1003
|
+
`CMS_RENDERER_KEY` matches, so both are needed for a per visitor limit. With no header named nothing
|
|
1004
|
+
is sent: a Next route handler never sees the socket's address, and the `X-Forwarded-For` Next adds
|
|
1005
|
+
keeps whatever a caller put there.
|
|
1006
|
+
|
|
1007
|
+
**A session lasts until the link expires or for 24 hours, whichever is sooner.** Opening the link
|
|
1008
|
+
again starts a new one while the link is valid. **A revoked link can keep working for up to 24
|
|
1009
|
+
hours** for someone who already opened it, because the session is checked here, not in barakoCMS. To
|
|
1010
|
+
end every session now, change `PRESS_SECRET`, which does it for every tenant on that
|
|
1011
|
+
deployment, and changes every tenant's webhook key with it.
|
|
1012
|
+
|
|
1013
|
+
Whether a request gets the holding page is decided by the proxy, from the cookie, once per request,
|
|
1014
|
+
and the answer is a segment of the path the render is kept under. A render made for a visitor with a
|
|
1015
|
+
session is never served to one without, or the reverse, because the two are different paths. A page
|
|
1016
|
+
you write by hand must call `siteConfig(config, params)` before it reads or renders anything, which
|
|
1017
|
+
is what keeps it behind the holding page and what gives it its tenant. A build-time site has no
|
|
1018
|
+
settings entry and no holding mode.
|
|
1019
|
+
|
|
1020
|
+
`generateStaticParams` factories return nothing on a request-time site, since there is no tenant at
|
|
1021
|
+
build. `scripts/two-hosts.sh` runs the built reference app against a stand-in CMS with two tenants
|
|
1022
|
+
and checks all of the above; CI runs it on every push.
|
|
147
1023
|
|
|
148
1024
|
### The look is configuration too
|
|
149
1025
|
|
|
@@ -166,7 +1042,9 @@ values or build a palette from them.
|
|
|
166
1042
|
|
|
167
1043
|
Loading the faces is the site's job, not the engine's. The default theme names Sora, Manrope and
|
|
168
1044
|
JetBrains Mono with real fallback stacks, and a `<link>` in your root layout is what makes them
|
|
169
|
-
arrive.
|
|
1045
|
+
arrive. `createSiteLayout` writes that link for you: a family name from Google Fonts, or the
|
|
1046
|
+
stylesheet named in `theme.fontSources` when the face is not loaded from there, held to
|
|
1047
|
+
`PRESS_FONT_ORIGINS` either way.
|
|
170
1048
|
|
|
171
1049
|
**Three slots**, for what belongs to the site rather than the engine:
|
|
172
1050
|
|
|
@@ -186,6 +1064,45 @@ paragraphs belongs to the block model, which is issue #6, because only the body
|
|
|
186
1064
|
Read time is derived from the body at 200 words a minute, with fenced code blocks excluded, so there
|
|
187
1065
|
is no field to fill in and nothing to keep in sync.
|
|
188
1066
|
|
|
1067
|
+
### Assets used exactly as supplied
|
|
1068
|
+
|
|
1069
|
+
Some marks come with an identity manual: never recoloured, never outlined, never put in a box, never
|
|
1070
|
+
crowded. A renderer that rounds a corner or drops a logo into a tinted panel breaks that rule, and on
|
|
1071
|
+
screen it looks like a nice touch. Mark the asset and it is drawn from the file, with a minimum clear
|
|
1072
|
+
space held around it, everywhere the engine draws an image.
|
|
1073
|
+
|
|
1074
|
+
```ts
|
|
1075
|
+
export const config = defineConfig({
|
|
1076
|
+
site: { name: "The club", url: "https://club.example", logo: "/mark.svg" },
|
|
1077
|
+
theme: { asSupplied: [{ url: "/mark.svg", clearSpace: "lg" }] },
|
|
1078
|
+
});
|
|
1079
|
+
```
|
|
1080
|
+
|
|
1081
|
+
A tenant says the same thing in its site settings:
|
|
1082
|
+
|
|
1083
|
+
| Field | Type | What |
|
|
1084
|
+
| --- | --- | --- |
|
|
1085
|
+
| `AssetsAsSupplied` | list | URLs, or `{ "url": "...", "clearSpace": "lg" }` for one that needs more room. A list saved empty clears the configured one |
|
|
1086
|
+
| `LogoAsSupplied` | boolean | Marks `Logo` and `FooterLogo`, so replacing the logo file does not mean editing a second setting that names the old one |
|
|
1087
|
+
| `LogoClearSpace` | string | The clear space around those two |
|
|
1088
|
+
|
|
1089
|
+
The clear space is a name from the theme's spacing scale (`none`, `xs`, `sm`, `md`, `lg`, `xl`,
|
|
1090
|
+
`xxl`), `md` when unset, and it is a minimum: a block asking for more gets more, a block asking for
|
|
1091
|
+
less gets the site's. A URL is matched without its query, so a mark the CMS resized with `?w=480` is
|
|
1092
|
+
still that mark.
|
|
1093
|
+
|
|
1094
|
+
What a marked asset gets is the file: no tint, no border, no corner, no shadow, no filter, no crop,
|
|
1095
|
+
and the clear space around it at every width. A block that asked for a frame draws the mark alone
|
|
1096
|
+
instead, which is what the `image` block's own `asSupplied` and `clearSpace` props are for when the
|
|
1097
|
+
site has not listed the file. It holds in the header, the footer, the holding page, a header or
|
|
1098
|
+
footer region, a page block, a preset, a post's cover image, a collection item's image and an image
|
|
1099
|
+
inside markdown, and `src/assets.test.tsx` walks all of those and fails if a new way to draw an image
|
|
1100
|
+
skips the rule.
|
|
1101
|
+
|
|
1102
|
+
One thing it cannot do: it does not know what is behind the mark. A tenant that puts a marked asset
|
|
1103
|
+
on an `inverse` band gets the supplied file on that band, drawn plainly. Choosing the band is the
|
|
1104
|
+
tenant's, and a white box behind the mark would itself be the boxing the rule forbids.
|
|
1105
|
+
|
|
189
1106
|
### Related posts, if the CMS has the AI module
|
|
190
1107
|
|
|
191
1108
|
`listRelated` asks `BarakoCMS.AI` for the posts closest to this one and hands them to `PostView`,
|
|
@@ -217,6 +1134,49 @@ Every read in `src/delivery.ts` is tagged with your `cacheTag`. `POST /api/reval
|
|
|
217
1134
|
the moment barakoCMS says something changed, so a publish is live in one request and the steady state
|
|
218
1135
|
is no database reads.
|
|
219
1136
|
|
|
1137
|
+
### What a publish drops
|
|
1138
|
+
|
|
1139
|
+
A read carries a second, narrower tag beside the site's own: the entry's when it read one entry, the
|
|
1140
|
+
type's when it read a list, a search, the site settings or the page tree. barakoCMS names the content
|
|
1141
|
+
type and sends the entry's public data with every delivery, so a publish drops that type's tag and
|
|
1142
|
+
that entry's tag, and leaves every other entry of the type cached. Correcting one typo on a school
|
|
1143
|
+
with a thousand news posts re-renders that post and the lists it appears in, not the other 999.
|
|
1144
|
+
|
|
1145
|
+
A delivery that names no content type, or one this site renders nothing of, drops the site's own tag,
|
|
1146
|
+
which is every read it has cached. That is what every delivery did before this, so a workflow posting
|
|
1147
|
+
a body of its own keeps working.
|
|
1148
|
+
|
|
1149
|
+
A response barakoCMS marks `Cache-Control: no-store` is not cached: the class is remembered against
|
|
1150
|
+
that path and every later read of it asks the CMS uncached, carrying no tag. That is how a type that
|
|
1151
|
+
has to be fresh to the minute lives beside pages cached for hours.
|
|
1152
|
+
|
|
1153
|
+
### Running more than one container
|
|
1154
|
+
|
|
1155
|
+
The kept answers, the host to tenant map, the webhook replay guard and the generation of each cache
|
|
1156
|
+
tag are in process by default, which is right for one container and wrong for two: a purge reaches
|
|
1157
|
+
one of them through the load balancer, and the others keep serving their own copies until the
|
|
1158
|
+
backstop runs out.
|
|
1159
|
+
|
|
1160
|
+
Pass a `store` on the config and they share it. It is three methods over anything the deployment
|
|
1161
|
+
already runs:
|
|
1162
|
+
|
|
1163
|
+
```ts
|
|
1164
|
+
import type { PressStore } from "barakopress";
|
|
1165
|
+
|
|
1166
|
+
const store: PressStore = {
|
|
1167
|
+
async get(key) { return (await redis.get(key)) ?? null; },
|
|
1168
|
+
async set(key, value, ttlSeconds) { await (ttlSeconds ? redis.set(key, value, { EX: ttlSeconds }) : redis.set(key, value)); },
|
|
1169
|
+
async delete(key) { await redis.del(key); },
|
|
1170
|
+
// Only when the key is absent, atomically. This is what honours a replayed delivery once.
|
|
1171
|
+
async add(key, value, ttlSeconds) { return (await redis.set(key, value, { NX: true, ...(ttlSeconds ? { EX: ttlSeconds } : {}) })) !== null; },
|
|
1172
|
+
};
|
|
1173
|
+
```
|
|
1174
|
+
|
|
1175
|
+
A purge one container receives then reaches the rest: the honoured delivery writes a generation
|
|
1176
|
+
against each tag it dropped, and a read carries the newest generation of its own tags in the URL it
|
|
1177
|
+
asks the CMS for, so a container that was never told is asking for something it has never cached.
|
|
1178
|
+
Next's own data cache stays per container; what crosses is the knowledge that it is out of date.
|
|
1179
|
+
|
|
220
1180
|
Each read also carries a backstop, 300 seconds by default. That is not for correctness, it is for the
|
|
221
1181
|
deployment where nobody ever created the webhook: without it their blog would be empty forever and
|
|
222
1182
|
nothing would say why. With it, a missing webhook degrades publishing from instant to a few minutes.
|
|
@@ -225,12 +1185,118 @@ nothing would say why. With it, a missing webhook degrades publishing from insta
|
|
|
225
1185
|
type, trigger `Published`, one Webhook action with the URL and a shared secret. Nothing is deployed
|
|
226
1186
|
to change it.
|
|
227
1187
|
|
|
1188
|
+
### The render cache
|
|
1189
|
+
|
|
1190
|
+
Reads being cached is half of it. The other half is not rendering the page again, and for a
|
|
1191
|
+
request-time site that used to be impossible: resolving the tenant meant reading the request host,
|
|
1192
|
+
reading a header makes a route dynamic, and Next never keeps a dynamic route. One container serving
|
|
1193
|
+
forty domains re-rendered every page for every visitor, with every read under it already cached.
|
|
1194
|
+
|
|
1195
|
+
Next keys what it keeps by the path and by nothing else. There is no `Vary` and no second key to
|
|
1196
|
+
add. So whatever a render depends on has to be in the path, and three things are:
|
|
1197
|
+
|
|
1198
|
+
| In the segment | Why |
|
|
1199
|
+
| --- | --- |
|
|
1200
|
+
| the tenant | two tenants must never share an entry. This is the whole reason the segment exists |
|
|
1201
|
+
| the gate | `public`, or `shared` for a request carrying a valid share session. A holding tenant answers differently for each, so each gets its own entry |
|
|
1202
|
+
| the host | the site's origin when the tenant's settings leave `Url` empty. Two hosts on one tenant are two renders, not one |
|
|
1203
|
+
|
|
1204
|
+
The proxy writes them, as `/_press/<tenant>~<gate>~<host>/<path>`, and it is the only thing that
|
|
1205
|
+
does: a path that arrives under `/_press` from outside is a 404, because otherwise
|
|
1206
|
+
`https://one.example/_press/other~public~other.example/` would render another tenant's site on this
|
|
1207
|
+
tenant's domain. A host the CMS does not know is a 404 before anything renders, so an invented host
|
|
1208
|
+
never makes an entry: only a host a tenant owns can put one there.
|
|
1209
|
+
|
|
1210
|
+
**What is cached.** The index, the pages tree, the collection indexes and the archives, per tenant
|
|
1211
|
+
and per path. `revalidateTag` drops a tenant's renders along with its reads, so the webhook that was
|
|
1212
|
+
already purging one purges both, and a publish on one tenant leaves every other tenant's renders in
|
|
1213
|
+
place. The first few views of a path answer `STALE` rather than `HIT` while the reads under them are
|
|
1214
|
+
still filling Next's data cache; after that it is `HIT` with no render and no read.
|
|
1215
|
+
|
|
1216
|
+
**What is not cached, deliberately.**
|
|
1217
|
+
|
|
1218
|
+
| Not cached | Why |
|
|
1219
|
+
| --- | --- |
|
|
1220
|
+
| a route that reads `?preview=` | a draft must never be in a shared cache, and reading the query is what keeps the route out of it. `createBlogPostPreview` is such a route; `createBlogPost` is not |
|
|
1221
|
+
| a page binding `{{query.X}}` | same reason. On a kept route the query is not handed to the blocks at all, so the binding is reported as an unbound scope and renders as nothing. A site that wants it writes `createPage(config, blocks, { query: true })` and leaves `generateStaticParams` out of that file |
|
|
1222
|
+
| `createViewerPage` | per viewer by definition. It calls `connection()`, and a route that does cannot be kept |
|
|
1223
|
+
| the feed, the sitemap and robots | `sitemap.ts` and `robots.ts` have to sit at the root of the app tree, so neither can carry a tenant segment. They resolve their own tenant and stay dynamic |
|
|
1224
|
+
| `/_share` and the redeem route | per visitor |
|
|
1225
|
+
|
|
1226
|
+
**Which routes are kept is the consumer's call, in the consumer's file**, the same as `revalidate`.
|
|
1227
|
+
A page route that exports `createSiteStaticParams()` is kept; one that does not is rendered per
|
|
1228
|
+
request. That is also the switch for the two rows above: a route that reads the query leaves it out.
|
|
1229
|
+
|
|
1230
|
+
**Nothing downstream may keep a copy.** Every rewritten answer carries `Cache-Control: private,
|
|
1231
|
+
no-store`, which is what a request-time site has always sent. Next's cache is the server's own and is
|
|
1232
|
+
not that header, so the render is still kept here. What stays true is that a browser or a proxy
|
|
1233
|
+
holding `/` is never holding one visitor's gate for the next visitor.
|
|
1234
|
+
|
|
1235
|
+
### One secret
|
|
1236
|
+
|
|
1237
|
+
`PRESS_SECRET` keys everything this renderer signs: each tenant's webhook key and each share session
|
|
1238
|
+
cookie. Every signature puts its purpose first in what it signs (`revalidate.` or `press-share.`), so
|
|
1239
|
+
one made for one purpose never verifies as another. It is read per request and has one rule for every
|
|
1240
|
+
purpose: at least 32 characters, for example `openssl rand -base64 48`.
|
|
1241
|
+
|
|
1242
|
+
| When `PRESS_SECRET` is | Webhooks | Share sessions |
|
|
1243
|
+
| --- | --- | --- |
|
|
1244
|
+
| 32 characters or more | verified with it | signed with it |
|
|
1245
|
+
| set but shorter | refused with 503 | none issued or accepted |
|
|
1246
|
+
| unset | `REVALIDATE_SECRET`, as in 0.3.0 | `PRESS_PREVIEW_SECRET` |
|
|
1247
|
+
|
|
1248
|
+
The older names are read only when `PRESS_SECRET` is unset, so a site that set them keeps working, and
|
|
1249
|
+
the keys derive byte for byte as before, so a key already pasted into a tenant's workflow keeps
|
|
1250
|
+
verifying. A `REVALIDATE_SECRET` shorter than 32 characters still verifies and logs a warning once,
|
|
1251
|
+
until 1.0.0. A `PRESS_PREVIEW_SECRET` shorter than 32 characters opens no session, as before.
|
|
1252
|
+
|
|
1253
|
+
Moving to the new name is copying the value: `PRESS_SECRET` set to what `REVALIDATE_SECRET` held
|
|
1254
|
+
derives the same tenant keys, provided it is 32 characters or more. A shorter one has to be replaced,
|
|
1255
|
+
and each tenant given its new key.
|
|
1256
|
+
|
|
228
1257
|
### Wiring the webhook
|
|
229
1258
|
|
|
230
|
-
1. Put a
|
|
1259
|
+
1. Put a random value of at least 32 characters in `PRESS_SECRET` where your app runs.
|
|
231
1260
|
2. In barakoBrew, create a workflow on your post content type, event `Published`.
|
|
232
1261
|
3. Add a Webhook action with `Url` set to `https://your-site/api/revalidate` and `Secret` set to the
|
|
233
|
-
same value.
|
|
1262
|
+
same value. On a site with `sites` configured, the `Secret` is the tenant's key instead, below.
|
|
1263
|
+
|
|
1264
|
+
### One key per tenant
|
|
1265
|
+
|
|
1266
|
+
With `sites` configured, one app serves many tenants, and each tenant's admin can read and edit its
|
|
1267
|
+
own workflows. So no tenant is given `PRESS_SECRET`. Each delivery is verified with a key derived
|
|
1268
|
+
for the tenant its host resolves to:
|
|
1269
|
+
|
|
1270
|
+
```
|
|
1271
|
+
key = lowercase hex HMAC-SHA256(PRESS_SECRET, "revalidate." + tenant handle)
|
|
1272
|
+
```
|
|
1273
|
+
|
|
1274
|
+
A delivery signed with one tenant's key gets a 401 on every other tenant's host, and so does one
|
|
1275
|
+
signed with `PRESS_SECRET` itself. Print a tenant's key where `PRESS_SECRET` (or `REVALIDATE_SECRET`) is set:
|
|
1276
|
+
|
|
1277
|
+
```bash
|
|
1278
|
+
npx barakopress revalidate-key baryo
|
|
1279
|
+
# or, with no Node:
|
|
1280
|
+
printf 'revalidate.%s' baryo | openssl dgst -sha256 -hmac "${PRESS_SECRET:-$REVALIDATE_SECRET}" | sed 's/^.* //'
|
|
1281
|
+
```
|
|
1282
|
+
|
|
1283
|
+
Both read the secret from the environment and print only the key. Paste it into the `Secret` of that
|
|
1284
|
+
tenant's Webhook action, with `Url` on that tenant's domain. A new tenant needs nothing on the
|
|
1285
|
+
renderer. Changing `PRESS_SECRET` changes every tenant's key, so each workflow needs its new one.
|
|
1286
|
+
|
|
1287
|
+
A site without `sites` (one build, one site) verifies with `PRESS_SECRET` itself, as it did with
|
|
1288
|
+
`REVALIDATE_SECRET`. Its workflow holds that value, so give it a value no other deployment uses.
|
|
1289
|
+
|
|
1290
|
+
**Upgrading a multi-tenant site to 0.4.0 is a breaking change.** Every tenant's workflow holds
|
|
1291
|
+
`REVALIDATE_SECRET` today, and after the upgrade that value verifies for no tenant: deliveries get a
|
|
1292
|
+
401 and purges stop, with the backstop the only refresh. Before or right after deploying, print each
|
|
1293
|
+
tenant's key and put it in that tenant's Webhook `Secret`. Then set a new `PRESS_SECRET` and print
|
|
1294
|
+
the keys again, because every tenant admin has seen the old value and could derive any tenant's key
|
|
1295
|
+
from it.
|
|
1296
|
+
|
|
1297
|
+
The barakoCMS webhook body does not name its tenant yet, so the host is what picks the key. Once the
|
|
1298
|
+
body carries the tenant (barakoCMS #868), a delivery whose body names a different tenant than its host
|
|
1299
|
+
resolves to is to be refused.
|
|
234
1300
|
|
|
235
1301
|
**If your site sets `trailingSlash: true`, the webhook URL needs the slash.** Next redirects
|
|
236
1302
|
`/api/revalidate` to `/api/revalidate/` with a 308, and barakoCMS does not follow redirects on a
|
|
@@ -245,8 +1311,9 @@ way.
|
|
|
245
1311
|
|
|
246
1312
|
Verification follows the recipe in the API's `docs/webhooks.md`: HMAC-SHA256 over
|
|
247
1313
|
`"<timestamp>.<raw body>"`, compared in constant time, with a 300 second tolerance so a captured
|
|
248
|
-
delivery cannot be replayed later, and each signature honoured once. An unsigned, missigned or stale
|
|
249
|
-
delivery gets a 401. If `REVALIDATE_SECRET` is
|
|
1314
|
+
delivery cannot be replayed later, and each signature honoured once per tenant. An unsigned, missigned or stale
|
|
1315
|
+
delivery gets a 401. If neither `PRESS_SECRET` nor `REVALIDATE_SECRET` is set, or `PRESS_SECRET` is
|
|
1316
|
+
shorter than 32 characters, the endpoint answers 503 and purges nothing,
|
|
250
1317
|
because an open cache-purge endpoint is a free denial of service.
|
|
251
1318
|
|
|
252
1319
|
## What it reads
|
|
@@ -267,6 +1334,20 @@ attribute. An editor is authenticated, so this is the second line of defence, no
|
|
|
267
1334
|
trade is that an author cannot embed raw HTML or an iframe. When you want that, the answer is a
|
|
268
1335
|
content field your frontend renders deliberately, not a hole here.
|
|
269
1336
|
|
|
1337
|
+
The same renderer is its own entry, `barakopress/markdown`, for code that runs in the browser, such
|
|
1338
|
+
as an editor previewing a post. The only package it reaches is `marked`, where the main entry also
|
|
1339
|
+
pulls in `next/cache`, `next/server` and `node:crypto`.
|
|
1340
|
+
|
|
1341
|
+
```ts
|
|
1342
|
+
import { renderMarkdown } from "barakopress/markdown";
|
|
1343
|
+
|
|
1344
|
+
renderMarkdown(source); // what the site renders
|
|
1345
|
+
renderMarkdown(source, { headingIds: false, newTab: true }); // no ids, links open a new tab
|
|
1346
|
+
```
|
|
1347
|
+
|
|
1348
|
+
Both options change only the markup around what is already sanitised. `headingIds` defaults to true
|
|
1349
|
+
and `newTab` to false, which is the site's output.
|
|
1350
|
+
|
|
270
1351
|
## Two behaviours that were measured, not assumed
|
|
271
1352
|
|
|
272
1353
|
**`revalidateTag` needs `{ expire: 0 }`, not a named profile.** Next 16 made the second argument
|
|
@@ -285,7 +1366,7 @@ does, so the package cannot quietly depend on something only its own repository
|
|
|
285
1366
|
container, a compose stack with Caddy terminating TLS, and a BaryoVM release manifest.
|
|
286
1367
|
|
|
287
1368
|
```bash
|
|
288
|
-
cp .env.example .env # point CMS_URL at your instance, set
|
|
1369
|
+
cp .env.example .env # point CMS_URL at your instance, set PRESS_SECRET
|
|
289
1370
|
npm install
|
|
290
1371
|
npm run build && npm start
|
|
291
1372
|
```
|
|
@@ -302,10 +1383,35 @@ baryovm stack release blog
|
|
|
302
1383
|
|
|
303
1384
|
Before the first release, three DNS names have to point at the machine (`SITE_DOMAIN`, `API_DOMAIN`,
|
|
304
1385
|
`CONSOLE_DOMAIN`) and a `.env` has to exist on it at `/opt/barakopress/.env`. The release refuses to
|
|
305
|
-
start without that file, and refuses again if `REVALIDATE_SECRET`
|
|
1386
|
+
start without that file, and refuses again if `PRESS_SECRET` and `REVALIDATE_SECRET` are both empty, because a stack that
|
|
306
1387
|
comes up with no secret can never be told that content changed. Only ports 80 and 443 are published:
|
|
307
1388
|
the API, the console and the site are reachable only through Caddy on the compose network.
|
|
308
1389
|
|
|
1390
|
+
## The look check
|
|
1391
|
+
|
|
1392
|
+
Before a site's domain moves to this stack, the look check proves the rebuilt pages look like the
|
|
1393
|
+
design that was approved. It takes pairs, a reference and a rebuilt page, screenshots both at 390px
|
|
1394
|
+
and 1280px in the same run, and fails the page whose pixels moved more than that page allows,
|
|
1395
|
+
handing back the reference, the rebuilt screenshot and a diff image.
|
|
1396
|
+
|
|
1397
|
+
The reference is either a prototype file on disk with a page state, or the live URL of the site
|
|
1398
|
+
being replaced. The pages themselves are data the site owns, so adding a page, or a whole site,
|
|
1399
|
+
never means editing the job:
|
|
1400
|
+
|
|
1401
|
+
```yaml
|
|
1402
|
+
jobs:
|
|
1403
|
+
look:
|
|
1404
|
+
uses: BaryoDev/barakoPress/.github/workflows/look-check.yml@master
|
|
1405
|
+
with:
|
|
1406
|
+
pairs: look/pairs.json
|
|
1407
|
+
variables: '{"REBUILT_BASE":"https://staging.rckoronadal.org"}'
|
|
1408
|
+
```
|
|
1409
|
+
|
|
1410
|
+
The pair list format, the per page threshold and the list of things that would otherwise make a run
|
|
1411
|
+
flake are in [docs/look-check.md](docs/look-check.md). `npm run look:selftest` runs the check twice
|
|
1412
|
+
over fixture pages, once green and once against a deliberate colour change, which is how anyone can
|
|
1413
|
+
see for themselves that it fails when it should.
|
|
1414
|
+
|
|
309
1415
|
## Working on the engine
|
|
310
1416
|
|
|
311
1417
|
```bash
|
|
@@ -329,5 +1435,4 @@ Releasing is in [RELEASING.md](RELEASING.md). No npm token is stored anywhere.
|
|
|
329
1435
|
## Status
|
|
330
1436
|
|
|
331
1437
|
Early. The blog works end to end against a real instance. Known gaps, all tracked upstream: no media
|
|
332
|
-
picker, no rich editor,
|
|
333
|
-
it is created.
|
|
1438
|
+
picker, no rich editor, and no visitor theme variants.
|