brease-client 0.5.0 → 0.6.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 +36 -0
- package/dist/chunk-CQZLTZGN.js +79 -0
- package/dist/cli.cjs +126 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +51 -0
- package/dist/index.cjs +81 -0
- package/dist/index.d.cts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +2 -1
- package/dist/next.js +2 -1
- package/package.json +4 -1
- /package/dist/{chunk-ULU4ABCQ.js → chunk-OA7GXHT3.js} +0 -0
package/README.md
CHANGED
|
@@ -243,11 +243,47 @@ The Brease editor's Edit tool finds content through `data-brease` attributes:
|
|
|
243
243
|
|
|
244
244
|
- `data-brease="hero.title"` on an element that renders a page content field (a path into `page.content`)
|
|
245
245
|
- `data-brease="nav:footer"` on the element that wraps a navigation menu; clicking it opens that navigation's editor
|
|
246
|
+
- `data-brease-block="<name>"` on a section's root: which component renders it (a hint for the AI)
|
|
247
|
+
- `data-brease-sections="sections"` and `data-brease-section="<id>"`: the section list and its sections (see Sections)
|
|
246
248
|
|
|
247
249
|
```tsx
|
|
248
250
|
<nav data-brease="nav:footer">{footer.items.map(/* … */)}</nav>
|
|
249
251
|
```
|
|
250
252
|
|
|
253
|
+
## Sections
|
|
254
|
+
|
|
255
|
+
Editors can add, move, duplicate and delete page sections in the Brease editor when a site follows the sections convention:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
src/brease/sections/ (or brease/sections/)
|
|
259
|
+
index.tsx type -> component map, renders content.sections in order; unknown types render nothing
|
|
260
|
+
testimonials/
|
|
261
|
+
section.json { "name": "Testimonials", "description": "…", "addable": true, "fields": { JSON Schema } }
|
|
262
|
+
Testimonials.tsx
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
- A page's sections are one list, `content.sections: [{ id, type, ...fields }]`, with the same ids in the same order in every locale. Fixed parts (a page title, header, footer, site-wide content) stay outside it.
|
|
266
|
+
- `fields` describes the section's fields; Brease builds new sections from it (lorem ipsum, a placeholder image, `default`s, `enum`s' first values, `minItems` list items). Images are `{ assetId, url, alt }`, links `{ label, href }`, rich text `{ "type": "string", "format": "html" }`.
|
|
267
|
+
- `"shared": true` keeps one content for every page that shows the type, on the site-wide page (`_global`) under `content.shared.<type>`; pages list only `{ id, type }` for it, and its markers use the other-page prefix (`<_global pageId>:shared.<type>.<field>`).
|
|
268
|
+
- Markers: the list's element carries `data-brease-sections="sections"`, each section's root `data-brease-section={id}` and `data-brease-block={type}`, fields inside `data-brease="sections.<index>.<field>"`.
|
|
269
|
+
|
|
270
|
+
```tsx
|
|
271
|
+
import { type BreaseSection, sectionAttrs, sectionsAttrs } from 'brease-client'
|
|
272
|
+
|
|
273
|
+
export function Sections({ sections }: { sections: BreaseSection[] }) {
|
|
274
|
+
return (
|
|
275
|
+
<div {...sectionsAttrs}>
|
|
276
|
+
{sections.map((s, i) => {
|
|
277
|
+
const Component = map[s.type]
|
|
278
|
+
return Component ? <div key={s.id} {...sectionAttrs(s)}><Component section={s} index={i} /></div> : null
|
|
279
|
+
})}
|
|
280
|
+
</div>
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
`npx brease-client check` warns about folders without a valid `section.json`, types missing from the map file, a missing `data-brease-section`, unknown types in `brease-seed/` or `.brease/` content, and locales whose sections differ. Brease runs the same check before publishing.
|
|
286
|
+
|
|
251
287
|
## Images
|
|
252
288
|
|
|
253
289
|
```ts
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/sections.ts
|
|
2
|
+
var sectionsAttrs = { "data-brease-sections": "sections" };
|
|
3
|
+
function sectionAttrs(section) {
|
|
4
|
+
return { "data-brease-section": section.id, "data-brease-block": section.type };
|
|
5
|
+
}
|
|
6
|
+
var SECTION_FOLDERS = ["src/brease/sections", "brease/sections"];
|
|
7
|
+
var TYPE_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
8
|
+
function checkSections(files, pages = {}) {
|
|
9
|
+
const warnings = [];
|
|
10
|
+
const folder = SECTION_FOLDERS.find((f) => Object.keys(files).some((p) => p.startsWith(`${f}/`)));
|
|
11
|
+
if (!folder) return warnings;
|
|
12
|
+
const inFolder = Object.entries(files).map(([p, text]) => [p.slice(folder.length + 1), text]);
|
|
13
|
+
const types = [
|
|
14
|
+
...new Set(
|
|
15
|
+
inFolder.map(([p]) => p.split("/")).filter((s) => s.length > 1).map((s) => s[0])
|
|
16
|
+
)
|
|
17
|
+
];
|
|
18
|
+
const map = inFolder.find(([p]) => /^index\.[cm]?[jt]sx?$/.test(p));
|
|
19
|
+
if (!map)
|
|
20
|
+
warnings.push(`${folder} has no map file (index.tsx, index.ts or index.js) rendering the section types`);
|
|
21
|
+
const marked = inFolder.some(
|
|
22
|
+
([, text]) => text.includes("data-brease-section") || text.includes("sectionAttrs(")
|
|
23
|
+
);
|
|
24
|
+
if (!marked)
|
|
25
|
+
warnings.push(
|
|
26
|
+
`No component in ${folder} renders data-brease-section (or sectionAttrs), so editors can't add sections`
|
|
27
|
+
);
|
|
28
|
+
for (const type of types) {
|
|
29
|
+
if (!TYPE_NAME.test(type)) {
|
|
30
|
+
warnings.push(`${folder}/${type}: use lowercase letters, numbers and - in section folder names`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const json = files[`${folder}/${type}/section.json`];
|
|
34
|
+
if (json === void 0) {
|
|
35
|
+
warnings.push(`${folder}/${type} has no section.json`);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const meta = JSON.parse(json);
|
|
40
|
+
if (typeof meta.name !== "string" || !meta.name.trim())
|
|
41
|
+
warnings.push(`${folder}/${type}/section.json has no name`);
|
|
42
|
+
if (meta.fields !== void 0 && (typeof meta.fields !== "object" || meta.fields === null))
|
|
43
|
+
warnings.push(`${folder}/${type}/section.json: fields must be a JSON Schema object`);
|
|
44
|
+
} catch {
|
|
45
|
+
warnings.push(`${folder}/${type}/section.json is not valid JSON`);
|
|
46
|
+
}
|
|
47
|
+
if (map && !map[1].includes(type)) warnings.push(`${type} is in ${folder} but not in its map file`);
|
|
48
|
+
}
|
|
49
|
+
const known = new Set(types);
|
|
50
|
+
for (const [pageId, locales] of Object.entries(pages)) {
|
|
51
|
+
let reference = null;
|
|
52
|
+
for (const [locale, file] of Object.entries(locales)) {
|
|
53
|
+
const list = file.content?.sections;
|
|
54
|
+
if (list === void 0) continue;
|
|
55
|
+
if (!Array.isArray(list)) {
|
|
56
|
+
warnings.push(`${pageId} (${locale}): sections is not a list`);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const ids = /* @__PURE__ */ new Set();
|
|
60
|
+
for (const item of list) {
|
|
61
|
+
if (typeof item?.id !== "string" || typeof item.type !== "string") {
|
|
62
|
+
warnings.push(`${pageId} (${locale}): a section has no id or type`);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (ids.has(item.id)) warnings.push(`${pageId} (${locale}): section ${item.id} appears twice`);
|
|
66
|
+
ids.add(item.id);
|
|
67
|
+
if (!known.has(item.type))
|
|
68
|
+
warnings.push(`${pageId} (${locale}): section type "${item.type}" has no folder`);
|
|
69
|
+
}
|
|
70
|
+
const shape = list.map((s) => `${s?.id}:${s?.type}`).join(",");
|
|
71
|
+
if (reference === null) reference = shape;
|
|
72
|
+
else if (shape !== reference)
|
|
73
|
+
warnings.push(`${pageId}: the sections in ${locale} differ from the other locales`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return warnings;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { SECTION_FOLDERS, checkSections, sectionAttrs, sectionsAttrs };
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
|
|
7
|
+
// src/sections.ts
|
|
8
|
+
var SECTION_FOLDERS = ["src/brease/sections", "brease/sections"];
|
|
9
|
+
var TYPE_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
10
|
+
function checkSections(files2, pages = {}) {
|
|
11
|
+
const warnings2 = [];
|
|
12
|
+
const folder2 = SECTION_FOLDERS.find((f) => Object.keys(files2).some((p) => p.startsWith(`${f}/`)));
|
|
13
|
+
if (!folder2) return warnings2;
|
|
14
|
+
const inFolder = Object.entries(files2).map(([p, text]) => [p.slice(folder2.length + 1), text]);
|
|
15
|
+
const types = [
|
|
16
|
+
...new Set(
|
|
17
|
+
inFolder.map(([p]) => p.split("/")).filter((s) => s.length > 1).map((s) => s[0])
|
|
18
|
+
)
|
|
19
|
+
];
|
|
20
|
+
const map = inFolder.find(([p]) => /^index\.[cm]?[jt]sx?$/.test(p));
|
|
21
|
+
if (!map)
|
|
22
|
+
warnings2.push(`${folder2} has no map file (index.tsx, index.ts or index.js) rendering the section types`);
|
|
23
|
+
const marked = inFolder.some(
|
|
24
|
+
([, text]) => text.includes("data-brease-section") || text.includes("sectionAttrs(")
|
|
25
|
+
);
|
|
26
|
+
if (!marked)
|
|
27
|
+
warnings2.push(
|
|
28
|
+
`No component in ${folder2} renders data-brease-section (or sectionAttrs), so editors can't add sections`
|
|
29
|
+
);
|
|
30
|
+
for (const type of types) {
|
|
31
|
+
if (!TYPE_NAME.test(type)) {
|
|
32
|
+
warnings2.push(`${folder2}/${type}: use lowercase letters, numbers and - in section folder names`);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const json = files2[`${folder2}/${type}/section.json`];
|
|
36
|
+
if (json === void 0) {
|
|
37
|
+
warnings2.push(`${folder2}/${type} has no section.json`);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const meta = JSON.parse(json);
|
|
42
|
+
if (typeof meta.name !== "string" || !meta.name.trim())
|
|
43
|
+
warnings2.push(`${folder2}/${type}/section.json has no name`);
|
|
44
|
+
if (meta.fields !== void 0 && (typeof meta.fields !== "object" || meta.fields === null))
|
|
45
|
+
warnings2.push(`${folder2}/${type}/section.json: fields must be a JSON Schema object`);
|
|
46
|
+
} catch {
|
|
47
|
+
warnings2.push(`${folder2}/${type}/section.json is not valid JSON`);
|
|
48
|
+
}
|
|
49
|
+
if (map && !map[1].includes(type)) warnings2.push(`${type} is in ${folder2} but not in its map file`);
|
|
50
|
+
}
|
|
51
|
+
const known = new Set(types);
|
|
52
|
+
for (const [pageId, locales] of Object.entries(pages)) {
|
|
53
|
+
let reference = null;
|
|
54
|
+
for (const [locale, file] of Object.entries(locales)) {
|
|
55
|
+
const list = file.content?.sections;
|
|
56
|
+
if (list === void 0) continue;
|
|
57
|
+
if (!Array.isArray(list)) {
|
|
58
|
+
warnings2.push(`${pageId} (${locale}): sections is not a list`);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const ids = /* @__PURE__ */ new Set();
|
|
62
|
+
for (const item of list) {
|
|
63
|
+
if (typeof item?.id !== "string" || typeof item.type !== "string") {
|
|
64
|
+
warnings2.push(`${pageId} (${locale}): a section has no id or type`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (ids.has(item.id)) warnings2.push(`${pageId} (${locale}): section ${item.id} appears twice`);
|
|
68
|
+
ids.add(item.id);
|
|
69
|
+
if (!known.has(item.type))
|
|
70
|
+
warnings2.push(`${pageId} (${locale}): section type "${item.type}" has no folder`);
|
|
71
|
+
}
|
|
72
|
+
const shape = list.map((s) => `${s?.id}:${s?.type}`).join(",");
|
|
73
|
+
if (reference === null) reference = shape;
|
|
74
|
+
else if (shape !== reference)
|
|
75
|
+
warnings2.push(`${pageId}: the sections in ${locale} differ from the other locales`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return warnings2;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/cli.ts
|
|
82
|
+
function walk(dir, out = []) {
|
|
83
|
+
for (const name of fs.readdirSync(dir)) {
|
|
84
|
+
if (name === "node_modules") continue;
|
|
85
|
+
const path$1 = path.join(dir, name);
|
|
86
|
+
if (fs.statSync(path$1).isDirectory()) walk(path$1, out);
|
|
87
|
+
else out.push(path$1);
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
function pagesIn(root) {
|
|
92
|
+
const pages = {};
|
|
93
|
+
const dir = path.join(root, "pages");
|
|
94
|
+
if (!fs.existsSync(dir)) return pages;
|
|
95
|
+
for (const pageId of fs.readdirSync(dir)) {
|
|
96
|
+
for (const file of fs.readdirSync(path.join(dir, pageId))) {
|
|
97
|
+
if (!file.endsWith(".json") || file === "page.json") continue;
|
|
98
|
+
const locales = pages[pageId] ?? {};
|
|
99
|
+
pages[pageId] = locales;
|
|
100
|
+
try {
|
|
101
|
+
locales[file.slice(0, -5)] = JSON.parse(fs.readFileSync(path.join(dir, pageId, file), "utf8"));
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return pages;
|
|
107
|
+
}
|
|
108
|
+
var [command] = process.argv.slice(2);
|
|
109
|
+
if (command !== "check") {
|
|
110
|
+
console.log("Usage: brease-client check");
|
|
111
|
+
process.exit(command ? 1 : 0);
|
|
112
|
+
}
|
|
113
|
+
var cwd = process.cwd();
|
|
114
|
+
var folder = SECTION_FOLDERS.find((f) => fs.existsSync(path.join(cwd, f)));
|
|
115
|
+
if (!folder) {
|
|
116
|
+
console.log("No sections folder (src/brease/sections or brease/sections): nothing to check.");
|
|
117
|
+
process.exit(0);
|
|
118
|
+
}
|
|
119
|
+
var files = Object.fromEntries(
|
|
120
|
+
walk(path.join(cwd, folder)).map((p) => [path.relative(cwd, p).split("\\").join("/"), fs.readFileSync(p, "utf8")])
|
|
121
|
+
);
|
|
122
|
+
var content = ["brease-seed", ".brease"].map((d) => path.join(cwd, d)).find((d) => fs.existsSync(d));
|
|
123
|
+
var warnings = checkSections(files, content ? pagesIn(content) : {});
|
|
124
|
+
for (const w of warnings) console.log(`warning: ${w}`);
|
|
125
|
+
console.log(warnings.length ? `${warnings.length} warning(s)` : "Sections look right.");
|
|
126
|
+
process.exit(warnings.length ? 1 : 0);
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { SECTION_FOLDERS, checkSections } from './chunk-CQZLTZGN.js';
|
|
3
|
+
import './chunk-PKBMQBKP.js';
|
|
4
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
|
|
5
|
+
import { join, relative } from 'path';
|
|
6
|
+
|
|
7
|
+
function walk(dir, out = []) {
|
|
8
|
+
for (const name of readdirSync(dir)) {
|
|
9
|
+
if (name === "node_modules") continue;
|
|
10
|
+
const path = join(dir, name);
|
|
11
|
+
if (statSync(path).isDirectory()) walk(path, out);
|
|
12
|
+
else out.push(path);
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
function pagesIn(root) {
|
|
17
|
+
const pages = {};
|
|
18
|
+
const dir = join(root, "pages");
|
|
19
|
+
if (!existsSync(dir)) return pages;
|
|
20
|
+
for (const pageId of readdirSync(dir)) {
|
|
21
|
+
for (const file of readdirSync(join(dir, pageId))) {
|
|
22
|
+
if (!file.endsWith(".json") || file === "page.json") continue;
|
|
23
|
+
const locales = pages[pageId] ?? {};
|
|
24
|
+
pages[pageId] = locales;
|
|
25
|
+
try {
|
|
26
|
+
locales[file.slice(0, -5)] = JSON.parse(readFileSync(join(dir, pageId, file), "utf8"));
|
|
27
|
+
} catch {
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return pages;
|
|
32
|
+
}
|
|
33
|
+
var [command] = process.argv.slice(2);
|
|
34
|
+
if (command !== "check") {
|
|
35
|
+
console.log("Usage: brease-client check");
|
|
36
|
+
process.exit(command ? 1 : 0);
|
|
37
|
+
}
|
|
38
|
+
var cwd = process.cwd();
|
|
39
|
+
var folder = SECTION_FOLDERS.find((f) => existsSync(join(cwd, f)));
|
|
40
|
+
if (!folder) {
|
|
41
|
+
console.log("No sections folder (src/brease/sections or brease/sections): nothing to check.");
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
var files = Object.fromEntries(
|
|
45
|
+
walk(join(cwd, folder)).map((p) => [relative(cwd, p).split("\\").join("/"), readFileSync(p, "utf8")])
|
|
46
|
+
);
|
|
47
|
+
var content = ["brease-seed", ".brease"].map((d) => join(cwd, d)).find((d) => existsSync(d));
|
|
48
|
+
var warnings = checkSections(files, content ? pagesIn(content) : {});
|
|
49
|
+
for (const w of warnings) console.log(`warning: ${w}`);
|
|
50
|
+
console.log(warnings.length ? `${warnings.length} warning(s)` : "Sections look right.");
|
|
51
|
+
process.exit(warnings.length ? 1 : 0);
|
package/dist/index.cjs
CHANGED
|
@@ -95,6 +95,84 @@ function nativeName(locale) {
|
|
|
95
95
|
}
|
|
96
96
|
var localeHref = (settings, slug, locale) => buildPath(settings, slug, locale);
|
|
97
97
|
|
|
98
|
+
// src/sections.ts
|
|
99
|
+
var sectionsAttrs = { "data-brease-sections": "sections" };
|
|
100
|
+
function sectionAttrs(section) {
|
|
101
|
+
return { "data-brease-section": section.id, "data-brease-block": section.type };
|
|
102
|
+
}
|
|
103
|
+
var SECTION_FOLDERS = ["src/brease/sections", "brease/sections"];
|
|
104
|
+
var TYPE_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
105
|
+
function checkSections(files, pages = {}) {
|
|
106
|
+
const warnings = [];
|
|
107
|
+
const folder = SECTION_FOLDERS.find((f) => Object.keys(files).some((p) => p.startsWith(`${f}/`)));
|
|
108
|
+
if (!folder) return warnings;
|
|
109
|
+
const inFolder = Object.entries(files).map(([p, text]) => [p.slice(folder.length + 1), text]);
|
|
110
|
+
const types = [
|
|
111
|
+
...new Set(
|
|
112
|
+
inFolder.map(([p]) => p.split("/")).filter((s) => s.length > 1).map((s) => s[0])
|
|
113
|
+
)
|
|
114
|
+
];
|
|
115
|
+
const map = inFolder.find(([p]) => /^index\.[cm]?[jt]sx?$/.test(p));
|
|
116
|
+
if (!map)
|
|
117
|
+
warnings.push(`${folder} has no map file (index.tsx, index.ts or index.js) rendering the section types`);
|
|
118
|
+
const marked = inFolder.some(
|
|
119
|
+
([, text]) => text.includes("data-brease-section") || text.includes("sectionAttrs(")
|
|
120
|
+
);
|
|
121
|
+
if (!marked)
|
|
122
|
+
warnings.push(
|
|
123
|
+
`No component in ${folder} renders data-brease-section (or sectionAttrs), so editors can't add sections`
|
|
124
|
+
);
|
|
125
|
+
for (const type of types) {
|
|
126
|
+
if (!TYPE_NAME.test(type)) {
|
|
127
|
+
warnings.push(`${folder}/${type}: use lowercase letters, numbers and - in section folder names`);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const json = files[`${folder}/${type}/section.json`];
|
|
131
|
+
if (json === void 0) {
|
|
132
|
+
warnings.push(`${folder}/${type} has no section.json`);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
const meta = JSON.parse(json);
|
|
137
|
+
if (typeof meta.name !== "string" || !meta.name.trim())
|
|
138
|
+
warnings.push(`${folder}/${type}/section.json has no name`);
|
|
139
|
+
if (meta.fields !== void 0 && (typeof meta.fields !== "object" || meta.fields === null))
|
|
140
|
+
warnings.push(`${folder}/${type}/section.json: fields must be a JSON Schema object`);
|
|
141
|
+
} catch {
|
|
142
|
+
warnings.push(`${folder}/${type}/section.json is not valid JSON`);
|
|
143
|
+
}
|
|
144
|
+
if (map && !map[1].includes(type)) warnings.push(`${type} is in ${folder} but not in its map file`);
|
|
145
|
+
}
|
|
146
|
+
const known = new Set(types);
|
|
147
|
+
for (const [pageId, locales] of Object.entries(pages)) {
|
|
148
|
+
let reference = null;
|
|
149
|
+
for (const [locale, file] of Object.entries(locales)) {
|
|
150
|
+
const list = file.content?.sections;
|
|
151
|
+
if (list === void 0) continue;
|
|
152
|
+
if (!Array.isArray(list)) {
|
|
153
|
+
warnings.push(`${pageId} (${locale}): sections is not a list`);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const ids = /* @__PURE__ */ new Set();
|
|
157
|
+
for (const item of list) {
|
|
158
|
+
if (typeof item?.id !== "string" || typeof item.type !== "string") {
|
|
159
|
+
warnings.push(`${pageId} (${locale}): a section has no id or type`);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (ids.has(item.id)) warnings.push(`${pageId} (${locale}): section ${item.id} appears twice`);
|
|
163
|
+
ids.add(item.id);
|
|
164
|
+
if (!known.has(item.type))
|
|
165
|
+
warnings.push(`${pageId} (${locale}): section type "${item.type}" has no folder`);
|
|
166
|
+
}
|
|
167
|
+
const shape = list.map((s) => `${s?.id}:${s?.type}`).join(",");
|
|
168
|
+
if (reference === null) reference = shape;
|
|
169
|
+
else if (shape !== reference)
|
|
170
|
+
warnings.push(`${pageId}: the sections in ${locale} differ from the other locales`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return warnings;
|
|
174
|
+
}
|
|
175
|
+
|
|
98
176
|
// src/index.ts
|
|
99
177
|
var RETRY_AFTER_CAP_MS = 1e4;
|
|
100
178
|
var SITE_TTL_MS = 6e4;
|
|
@@ -225,9 +303,12 @@ function pathOf(url) {
|
|
|
225
303
|
|
|
226
304
|
exports.BreaseError = BreaseError;
|
|
227
305
|
exports.buildPath = buildPath;
|
|
306
|
+
exports.checkSections = checkSections;
|
|
228
307
|
exports.createBrease = createBrease;
|
|
229
308
|
exports.localeHref = localeHref;
|
|
230
309
|
exports.localeLinks = localeLinks;
|
|
231
310
|
exports.nativeName = nativeName;
|
|
232
311
|
exports.normalizeSlug = normalizeSlug;
|
|
233
312
|
exports.resolvePath = resolvePath;
|
|
313
|
+
exports.sectionAttrs = sectionAttrs;
|
|
314
|
+
exports.sectionsAttrs = sectionsAttrs;
|
package/dist/index.d.cts
CHANGED
|
@@ -21,6 +21,25 @@ declare function localeLinks(context: LocaleContext): LocaleLink[];
|
|
|
21
21
|
declare function nativeName(locale: string): string;
|
|
22
22
|
declare const localeHref: (settings: UrlSettings, slug: string, locale: string) => string;
|
|
23
23
|
|
|
24
|
+
type BreaseSection<T = Record<string, unknown>> = {
|
|
25
|
+
id: string;
|
|
26
|
+
type: string;
|
|
27
|
+
} & T;
|
|
28
|
+
declare const sectionsAttrs: {
|
|
29
|
+
readonly 'data-brease-sections': "sections";
|
|
30
|
+
};
|
|
31
|
+
declare function sectionAttrs(section: {
|
|
32
|
+
id: string;
|
|
33
|
+
type: string;
|
|
34
|
+
}): {
|
|
35
|
+
'data-brease-section': string;
|
|
36
|
+
'data-brease-block': string;
|
|
37
|
+
};
|
|
38
|
+
type PageLocales = Record<string, Record<string, {
|
|
39
|
+
content?: unknown;
|
|
40
|
+
}>>;
|
|
41
|
+
declare function checkSections(files: Record<string, string>, pages?: PageLocales): string[];
|
|
42
|
+
|
|
24
43
|
declare function normalizeSlug(input: string): string;
|
|
25
44
|
declare function buildPath(settings: UrlSettings, slug: string, locale: string): string;
|
|
26
45
|
declare function resolvePath(settings: UrlSettings, pathname: string): {
|
|
@@ -71,4 +90,4 @@ interface Brease {
|
|
|
71
90
|
}
|
|
72
91
|
declare function createBrease(opts?: BreaseOptions): Brease;
|
|
73
92
|
|
|
74
|
-
export { type Brease, BreaseError, type BreaseOptions, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, Site, SitemapEntry, UrlSettings, buildPath, createBrease, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath };
|
|
93
|
+
export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, Site, SitemapEntry, UrlSettings, buildPath, checkSections, createBrease, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs };
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,25 @@ declare function localeLinks(context: LocaleContext): LocaleLink[];
|
|
|
21
21
|
declare function nativeName(locale: string): string;
|
|
22
22
|
declare const localeHref: (settings: UrlSettings, slug: string, locale: string) => string;
|
|
23
23
|
|
|
24
|
+
type BreaseSection<T = Record<string, unknown>> = {
|
|
25
|
+
id: string;
|
|
26
|
+
type: string;
|
|
27
|
+
} & T;
|
|
28
|
+
declare const sectionsAttrs: {
|
|
29
|
+
readonly 'data-brease-sections': "sections";
|
|
30
|
+
};
|
|
31
|
+
declare function sectionAttrs(section: {
|
|
32
|
+
id: string;
|
|
33
|
+
type: string;
|
|
34
|
+
}): {
|
|
35
|
+
'data-brease-section': string;
|
|
36
|
+
'data-brease-block': string;
|
|
37
|
+
};
|
|
38
|
+
type PageLocales = Record<string, Record<string, {
|
|
39
|
+
content?: unknown;
|
|
40
|
+
}>>;
|
|
41
|
+
declare function checkSections(files: Record<string, string>, pages?: PageLocales): string[];
|
|
42
|
+
|
|
24
43
|
declare function normalizeSlug(input: string): string;
|
|
25
44
|
declare function buildPath(settings: UrlSettings, slug: string, locale: string): string;
|
|
26
45
|
declare function resolvePath(settings: UrlSettings, pathname: string): {
|
|
@@ -71,4 +90,4 @@ interface Brease {
|
|
|
71
90
|
}
|
|
72
91
|
declare function createBrease(opts?: BreaseOptions): Brease;
|
|
73
92
|
|
|
74
|
-
export { type Brease, BreaseError, type BreaseOptions, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, Site, SitemapEntry, UrlSettings, buildPath, createBrease, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath };
|
|
93
|
+
export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, Site, SitemapEntry, UrlSettings, buildPath, checkSections, createBrease, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { BreaseError, buildPath, createBrease, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath } from './chunk-
|
|
1
|
+
export { BreaseError, buildPath, createBrease, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath } from './chunk-OA7GXHT3.js';
|
|
2
|
+
export { checkSections, sectionAttrs, sectionsAttrs } from './chunk-CQZLTZGN.js';
|
|
2
3
|
import './chunk-PKBMQBKP.js';
|
package/dist/next.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brease-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Brease delivery API client for Next.js, Astro and any fetch-capable runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -74,6 +74,9 @@
|
|
|
74
74
|
"access": "public",
|
|
75
75
|
"provenance": true
|
|
76
76
|
},
|
|
77
|
+
"bin": {
|
|
78
|
+
"brease-client": "./dist/cli.js"
|
|
79
|
+
},
|
|
77
80
|
"scripts": {
|
|
78
81
|
"build": "tsup",
|
|
79
82
|
"dev": "tsup --watch",
|
|
File without changes
|