@contentbit/studio 0.4.2 → 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 +8 -4
- package/dist/client/assets/api-DbvlDnoO.js +1 -0
- package/dist/client/assets/document-RcoEgi0r.js +1 -0
- package/dist/client/assets/{index-DTXIZgkK.js → index-BOeG6kVU.js} +2 -2
- package/dist/client/assets/routes-cJNV3NIG.js +1 -0
- package/dist/server/assets/{_tanstack-start-manifest_v-wPlN1Hjy.js → _tanstack-start-manifest_v-BSt6T4tK.js} +4 -4
- package/dist/server/assets/{document-DjmCb_Rp.js → document-DlS34LM6.js} +1 -1
- package/dist/server/assets/{document-CxPFBdxd.js → document-G8TsI311.js} +49 -15
- package/dist/server/assets/{router-D4DnWGjU.js → router-734kIJxk.js} +2 -2
- package/dist/server/assets/{routes-BVJt9Z6a.js → routes-FGdym0e5.js} +28 -4
- package/dist/server/assets/{routes-6jOjWQ0D.js → routes-p0tk6PAr.js} +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +27 -8
- package/dist/server/preview.d.ts +4 -2
- package/dist/server/preview.d.ts.map +1 -1
- package/dist/server/preview.js +1 -1
- package/dist/server/scan.d.ts.map +1 -1
- package/dist/server/scan.js +84 -222
- package/dist/server/server.js +2 -2
- package/dist/server/types.d.ts +21 -2
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/routes/document.tsx +39 -0
- package/src/routes/index.tsx +21 -1
- package/src/server/index.ts +43 -14
- package/src/server/preview.ts +3 -2
- package/src/server/scan.test.ts +138 -0
- package/src/server/scan.ts +107 -277
- package/src/server/types.ts +21 -2
- package/dist/client/assets/api-MWiK2l_P.js +0 -1
- package/dist/client/assets/document-w62o-wDp.js +0 -1
- package/dist/client/assets/routes-Dg9spe-7.js +0 -1
package/src/server/index.ts
CHANGED
|
@@ -45,8 +45,11 @@ export async function startStudio(options: StartStudioOptions): Promise<StudioSe
|
|
|
45
45
|
globs: options.globs,
|
|
46
46
|
cwd,
|
|
47
47
|
registryPath: options.registryPath,
|
|
48
|
+
includeGenericBlocks: options.includeGenericBlocks,
|
|
48
49
|
linkOptions: options.linkOptions,
|
|
49
50
|
minSectionWords: options.minSectionWords,
|
|
51
|
+
seoConfig: options.seoConfig,
|
|
52
|
+
seoConfigPath: options.seoConfigPath,
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
const vite = await createServer({
|
|
@@ -86,20 +89,39 @@ async function loadProjectComponents(
|
|
|
86
89
|
vite: ViteDevServer,
|
|
87
90
|
options: { cwd: string; registryPath?: string },
|
|
88
91
|
): Promise<Record<string, BlockComponent> | undefined> {
|
|
92
|
+
const merged: Record<string, BlockComponent> = {}
|
|
89
93
|
for (const candidate of componentCandidates(options)) {
|
|
90
|
-
if (!existsSync(candidate)) continue
|
|
91
|
-
|
|
94
|
+
if (!existsSync(candidate.path)) continue
|
|
95
|
+
let mod: {
|
|
96
|
+
styledComponents?: Record<string, BlockComponent>
|
|
92
97
|
blockComponents?: Record<string, BlockComponent>
|
|
93
98
|
components?: Record<string, BlockComponent>
|
|
94
99
|
default?: Record<string, BlockComponent>
|
|
95
100
|
}
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
try {
|
|
102
|
+
mod = (await vite.ssrLoadModule(candidate.path)) as typeof mod
|
|
103
|
+
} catch {
|
|
104
|
+
if (!candidate.bestEffort)
|
|
105
|
+
throw new Error(`Failed to load block components: ${candidate.path}`)
|
|
106
|
+
continue
|
|
107
|
+
}
|
|
108
|
+
const maps = [mod.styledComponents, mod.blockComponents, mod.components, mod.default]
|
|
109
|
+
for (const components of maps) {
|
|
110
|
+
if (components && typeof components === 'object') Object.assign(merged, components)
|
|
111
|
+
}
|
|
98
112
|
}
|
|
99
|
-
return undefined
|
|
113
|
+
return Object.keys(merged).length > 0 ? merged : undefined
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
interface ComponentCandidate {
|
|
117
|
+
path: string
|
|
118
|
+
bestEffort: boolean
|
|
100
119
|
}
|
|
101
120
|
|
|
102
|
-
function componentCandidates(options: {
|
|
121
|
+
function componentCandidates(options: {
|
|
122
|
+
cwd: string
|
|
123
|
+
registryPath?: string
|
|
124
|
+
}): ComponentCandidate[] {
|
|
103
125
|
const dirs = new Set<string>()
|
|
104
126
|
if (options.registryPath) {
|
|
105
127
|
const registryPath = isAbsolute(options.registryPath)
|
|
@@ -109,14 +131,21 @@ function componentCandidates(options: { cwd: string; registryPath?: string }): s
|
|
|
109
131
|
}
|
|
110
132
|
dirs.add(join(options.cwd, 'blocks'))
|
|
111
133
|
|
|
112
|
-
|
|
113
|
-
join(
|
|
114
|
-
join(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
134
|
+
const rendererCandidates = [
|
|
135
|
+
join(options.cwd, 'components/content-blocks/content-renderer.tsx'),
|
|
136
|
+
join(options.cwd, 'src/components/content-blocks/content-renderer.tsx'),
|
|
137
|
+
].map((path) => ({ path, bestEffort: true }))
|
|
138
|
+
const blockComponentCandidates = [...dirs].flatMap((dir) =>
|
|
139
|
+
[
|
|
140
|
+
join(dir, 'components.tsx'),
|
|
141
|
+
join(dir, 'components.ts'),
|
|
142
|
+
join(dir, 'preview.tsx'),
|
|
143
|
+
join(dir, 'preview.ts'),
|
|
144
|
+
join(dir, 'renderers.tsx'),
|
|
145
|
+
join(dir, 'renderers.ts'),
|
|
146
|
+
].map((path) => ({ path, bestEffort: false })),
|
|
147
|
+
)
|
|
148
|
+
return [...rendererCandidates, ...blockComponentCandidates]
|
|
120
149
|
}
|
|
121
150
|
|
|
122
151
|
function studioApiPlugin(options: StudioOptions): Plugin {
|
package/src/server/preview.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BlockComponent } from '@contentbit/react'
|
|
2
|
-
import type {
|
|
2
|
+
import type { ValidatedDocumentNode } from '@contentbit/core'
|
|
3
3
|
import type { ComponentType } from 'react'
|
|
4
4
|
|
|
5
5
|
import { ContentBlocks } from '@contentbit/react'
|
|
@@ -14,8 +14,9 @@ interface FallbackProps {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function renderStudioPreview(
|
|
17
|
-
document:
|
|
17
|
+
document: ValidatedDocumentNode,
|
|
18
18
|
components: Record<string, BlockComponent> = {},
|
|
19
|
+
_options: { includeGenericComponents?: boolean } = {},
|
|
19
20
|
): string {
|
|
20
21
|
return renderToStaticMarkup(
|
|
21
22
|
createElement(ContentBlocks, {
|
package/src/server/scan.test.ts
CHANGED
|
@@ -102,6 +102,38 @@ ${Array.from({ length: 260 }, (_, index) => `word${index}`).join(' ')}
|
|
|
102
102
|
expect(codes.indexOf('CB_PROPS_INVALID')).toBeLessThan(codes.indexOf('CB_LINK_UNRESOLVED'))
|
|
103
103
|
})
|
|
104
104
|
|
|
105
|
+
test('scanProject reads seoKeywords as keyword data', async () => {
|
|
106
|
+
const dir = await fixture({
|
|
107
|
+
'content/oil.md': `---
|
|
108
|
+
slug: cooking-oil-smoke-points
|
|
109
|
+
seoKeywords:
|
|
110
|
+
primary: cooking oil smoke points
|
|
111
|
+
secondary:
|
|
112
|
+
- oil smoke point chart
|
|
113
|
+
lsi:
|
|
114
|
+
- avocado oil smoke point
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
# Oil Smoke Points
|
|
118
|
+
|
|
119
|
+
Useful body.
|
|
120
|
+
`,
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
const project = await scanProject({
|
|
124
|
+
globs: ['content/*.md'],
|
|
125
|
+
cwd: dir,
|
|
126
|
+
minSectionWords: 0,
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
expect(project.keywordCoverage).toEqual({ total: 1, withPrimary: 1, withSecondary: 1 })
|
|
130
|
+
expect(project.files[0].keywords).toEqual({
|
|
131
|
+
primary: 'cooking oil smoke points',
|
|
132
|
+
secondary: ['oil smoke point chart'],
|
|
133
|
+
lsi: ['avocado oil smoke point'],
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
|
|
105
137
|
test('scanDocument rejects paths outside the matched content set', async () => {
|
|
106
138
|
const dir = await fixture({
|
|
107
139
|
'content/a.md': '---\nslug: alpha\n---\n\n# Alpha\n\nBody.',
|
|
@@ -152,6 +184,48 @@ Custom block content for the local registry.
|
|
|
152
184
|
expect(document?.previewHtml).toContain('<p>Custom block content for the local registry.</p>')
|
|
153
185
|
})
|
|
154
186
|
|
|
187
|
+
test('scanDocument can let a project registry own generic block names', async () => {
|
|
188
|
+
const dir = await fixture({
|
|
189
|
+
'blocks/registry.mjs': `import { defineBlock, markdownBody } from '@contentbit/core'
|
|
190
|
+
import { z } from 'zod'
|
|
191
|
+
|
|
192
|
+
const quickRef = defineBlock({
|
|
193
|
+
name: 'quick-ref',
|
|
194
|
+
props: z.object({}),
|
|
195
|
+
content: markdownBody({ minLength: 3 }),
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
export default [quickRef]
|
|
199
|
+
`,
|
|
200
|
+
'content/a.md': `---
|
|
201
|
+
slug: alpha
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
# Alpha
|
|
205
|
+
|
|
206
|
+
:::quick-ref
|
|
207
|
+
Project-owned quick reference content.
|
|
208
|
+
:::
|
|
209
|
+
`,
|
|
210
|
+
})
|
|
211
|
+
await linkContentbitCore(dir)
|
|
212
|
+
|
|
213
|
+
const document = await scanDocument(
|
|
214
|
+
{
|
|
215
|
+
globs: ['content/*.md'],
|
|
216
|
+
cwd: dir,
|
|
217
|
+
registryPath: 'blocks/registry.mjs',
|
|
218
|
+
includeGenericBlocks: false,
|
|
219
|
+
minSectionWords: 0,
|
|
220
|
+
},
|
|
221
|
+
'content/a.md',
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
expect(document?.findings.filter((finding) => finding.source === 'validation')).toEqual([])
|
|
225
|
+
expect(document?.file.blockNames['quick-ref']).toBe(1)
|
|
226
|
+
expect(document?.previewHtml).toContain('data-cb-custom="quick-ref"')
|
|
227
|
+
})
|
|
228
|
+
|
|
155
229
|
test('scanGraph returns resolved and unresolved edges', async () => {
|
|
156
230
|
const dir = await fixture({
|
|
157
231
|
'content/a.md': '---\nslug: alpha\nlinksTo:\n - beta\n - missing\n---\n\n# Alpha\n\nBody.',
|
|
@@ -169,6 +243,70 @@ test('scanGraph returns resolved and unresolved edges', async () => {
|
|
|
169
243
|
).toBe(true)
|
|
170
244
|
})
|
|
171
245
|
|
|
246
|
+
test('scanProject and scanDocument expose SEO status and briefs', async () => {
|
|
247
|
+
const dir = await fixture({
|
|
248
|
+
'content/a.md': `---
|
|
249
|
+
key: alpha-alternatives
|
|
250
|
+
slug: alpha-alternatives
|
|
251
|
+
type: alternative
|
|
252
|
+
intent: commercial
|
|
253
|
+
keywords:
|
|
254
|
+
primary: alpha alternatives
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
# Alpha Alternatives
|
|
258
|
+
|
|
259
|
+
## Overview
|
|
260
|
+
|
|
261
|
+
Useful overview body.
|
|
262
|
+
`,
|
|
263
|
+
})
|
|
264
|
+
const seoConfig = {
|
|
265
|
+
pageTypes: {
|
|
266
|
+
alternative: {
|
|
267
|
+
requiredFrontmatter: ['type', 'intent', 'keywords.primary'],
|
|
268
|
+
requiredSections: [
|
|
269
|
+
{ id: 'overview', headings: ['Overview'] },
|
|
270
|
+
{ id: 'alternatives', headings: ['Best alternatives'] },
|
|
271
|
+
],
|
|
272
|
+
minOutgoingLinks: 1,
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const project = await scanProject({
|
|
278
|
+
globs: ['content/*.md'],
|
|
279
|
+
cwd: dir,
|
|
280
|
+
minSectionWords: 0,
|
|
281
|
+
seoConfig,
|
|
282
|
+
})
|
|
283
|
+
expect(project.seo).toMatchObject({
|
|
284
|
+
schemaVersion: 'contentbit.seo.v1',
|
|
285
|
+
pages: 1,
|
|
286
|
+
existing: 1,
|
|
287
|
+
planned: 0,
|
|
288
|
+
})
|
|
289
|
+
expect(project.files[0].seo).toMatchObject({
|
|
290
|
+
id: 'alpha-alternatives',
|
|
291
|
+
source: 'existing',
|
|
292
|
+
type: 'alternative',
|
|
293
|
+
intent: 'commercial',
|
|
294
|
+
})
|
|
295
|
+
expect(project.findings.map((finding) => finding.code)).toContain('CB_SEO_SECTION_MISSING')
|
|
296
|
+
|
|
297
|
+
const document = await scanDocument(
|
|
298
|
+
{ globs: ['content/*.md'], cwd: dir, minSectionWords: 0, seoConfig },
|
|
299
|
+
'content/a.md',
|
|
300
|
+
)
|
|
301
|
+
expect(document?.seoBrief).toMatchObject({
|
|
302
|
+
schemaVersion: 'contentbit.seo.brief.v1',
|
|
303
|
+
target: { id: 'alpha-alternatives' },
|
|
304
|
+
})
|
|
305
|
+
expect(document?.seoBrief?.acceptanceChecks).toContain(
|
|
306
|
+
'Document includes section: Best alternatives.',
|
|
307
|
+
)
|
|
308
|
+
})
|
|
309
|
+
|
|
172
310
|
test('startStudio serves read-only local API responses on port 0', async () => {
|
|
173
311
|
const dir = await fixture({
|
|
174
312
|
'content/a.md': '---\nslug: alpha\n---\n\n# Alpha\n\nReadable body.',
|