@contentbit/studio 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/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 +2 -0
- package/dist/server/scan.d.ts.map +1 -1
- package/dist/server/scan.js +59 -119
- package/dist/server/server.js +2 -2
- package/dist/server/types.d.ts +20 -2
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/routes/document.tsx +39 -0
- package/src/routes/index.tsx +21 -1
- package/src/server/index.ts +2 -0
- package/src/server/scan.test.ts +96 -0
- package/src/server/scan.ts +65 -131
- package/src/server/types.ts +20 -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/routes/document.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
Link2,
|
|
9
9
|
RefreshCw,
|
|
10
10
|
Search,
|
|
11
|
+
Target,
|
|
11
12
|
} from 'lucide-react'
|
|
12
13
|
import type { ReactNode } from 'react'
|
|
13
14
|
import { useEffect, useState } from 'react'
|
|
@@ -163,12 +164,50 @@ function DocumentDetail() {
|
|
|
163
164
|
</div>
|
|
164
165
|
</div>
|
|
165
166
|
)}
|
|
167
|
+
{(document.file.keywords.lsi?.length ?? 0) > 0 && (
|
|
168
|
+
<div>
|
|
169
|
+
<p className="text-xs uppercase text-muted-foreground">LSI</p>
|
|
170
|
+
<div className="mt-2 flex flex-wrap gap-1">
|
|
171
|
+
{document.file.keywords.lsi?.map((keyword) => (
|
|
172
|
+
<Badge key={keyword}>{keyword}</Badge>
|
|
173
|
+
))}
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
)}
|
|
166
177
|
</div>
|
|
167
178
|
) : (
|
|
168
179
|
<p className="text-sm text-muted-foreground">No keyword frontmatter found.</p>
|
|
169
180
|
)}
|
|
170
181
|
</Panel>
|
|
171
182
|
|
|
183
|
+
{document.seoBrief && (
|
|
184
|
+
<Panel title="SEO Brief" icon={<Target className="size-4" />}>
|
|
185
|
+
<div className="space-y-3 text-sm">
|
|
186
|
+
<div className="flex flex-wrap gap-1">
|
|
187
|
+
{document.seoBrief.target.type && (
|
|
188
|
+
<Badge>{document.seoBrief.target.type}</Badge>
|
|
189
|
+
)}
|
|
190
|
+
{document.seoBrief.target.intent && (
|
|
191
|
+
<Badge>{document.seoBrief.target.intent}</Badge>
|
|
192
|
+
)}
|
|
193
|
+
<Badge>{document.seoBrief.target.source}</Badge>
|
|
194
|
+
</div>
|
|
195
|
+
{document.seoBrief.acceptanceChecks.length > 0 && (
|
|
196
|
+
<div>
|
|
197
|
+
<p className="text-xs uppercase text-muted-foreground">Acceptance</p>
|
|
198
|
+
<ul className="mt-2 space-y-1">
|
|
199
|
+
{document.seoBrief.acceptanceChecks.map((check) => (
|
|
200
|
+
<li key={check} className="border bg-muted/40 px-2 py-1">
|
|
201
|
+
{check}
|
|
202
|
+
</li>
|
|
203
|
+
))}
|
|
204
|
+
</ul>
|
|
205
|
+
</div>
|
|
206
|
+
)}
|
|
207
|
+
</div>
|
|
208
|
+
</Panel>
|
|
209
|
+
)}
|
|
210
|
+
|
|
172
211
|
<Panel title="Findings" icon={<AlertTriangle className="size-4" />}>
|
|
173
212
|
{document.findings.length > 0 ? (
|
|
174
213
|
<ul className="space-y-3">
|
package/src/routes/index.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
RefreshCw,
|
|
10
10
|
Search,
|
|
11
11
|
ChevronsUpDown,
|
|
12
|
+
Target,
|
|
12
13
|
} from 'lucide-react'
|
|
13
14
|
import type { ReactNode } from 'react'
|
|
14
15
|
import { useEffect, useMemo, useState } from 'react'
|
|
@@ -77,6 +78,7 @@ function Dashboard() {
|
|
|
77
78
|
file.locale,
|
|
78
79
|
file.keywords?.primary,
|
|
79
80
|
...(file.keywords?.secondary ?? []),
|
|
81
|
+
...(file.keywords?.lsi ?? []),
|
|
80
82
|
]
|
|
81
83
|
.filter(Boolean)
|
|
82
84
|
.join(' ')
|
|
@@ -224,6 +226,20 @@ function Dashboard() {
|
|
|
224
226
|
</div>
|
|
225
227
|
|
|
226
228
|
<aside className="flex flex-col gap-4">
|
|
229
|
+
{project?.seo && (
|
|
230
|
+
<Panel title="SEO">
|
|
231
|
+
<div className="grid grid-cols-3 gap-px overflow-hidden border bg-border text-center">
|
|
232
|
+
<TinyMetric value={project.seo.pages} label="pages" />
|
|
233
|
+
<TinyMetric value={project.seo.planned} label="planned" />
|
|
234
|
+
<TinyMetric value={project.seo.findings} label="findings" />
|
|
235
|
+
</div>
|
|
236
|
+
<div className="mt-3 flex items-center gap-2 text-xs text-muted-foreground">
|
|
237
|
+
<Target className="size-4" />
|
|
238
|
+
<span>{project.seo.schemaVersion}</span>
|
|
239
|
+
</div>
|
|
240
|
+
</Panel>
|
|
241
|
+
)}
|
|
242
|
+
|
|
227
243
|
<Panel title="Link graph">
|
|
228
244
|
{project?.linkGraph ? (
|
|
229
245
|
<div className="grid grid-cols-3 gap-px overflow-hidden border bg-border text-center">
|
|
@@ -447,7 +463,11 @@ function compareFiles(a: StudioFileSummary, b: StudioFileSummary, sort: SortKey,
|
|
|
447
463
|
}
|
|
448
464
|
|
|
449
465
|
function keywordScore(file: StudioFileSummary): number {
|
|
450
|
-
return (
|
|
466
|
+
return (
|
|
467
|
+
(file.keywords?.primary ? 1 : 0) +
|
|
468
|
+
(file.keywords?.secondary?.length ? 1 : 0) +
|
|
469
|
+
(file.keywords?.lsi?.length ? 1 : 0)
|
|
470
|
+
)
|
|
451
471
|
}
|
|
452
472
|
|
|
453
473
|
function findingScore(file: StudioFileSummary): number {
|
package/src/server/index.ts
CHANGED
|
@@ -48,6 +48,8 @@ export async function startStudio(options: StartStudioOptions): Promise<StudioSe
|
|
|
48
48
|
includeGenericBlocks: options.includeGenericBlocks,
|
|
49
49
|
linkOptions: options.linkOptions,
|
|
50
50
|
minSectionWords: options.minSectionWords,
|
|
51
|
+
seoConfig: options.seoConfig,
|
|
52
|
+
seoConfigPath: options.seoConfigPath,
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
const vite = await createServer({
|
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.',
|
|
@@ -211,6 +243,70 @@ test('scanGraph returns resolved and unresolved edges', async () => {
|
|
|
211
243
|
).toBe(true)
|
|
212
244
|
})
|
|
213
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
|
+
|
|
214
310
|
test('startStudio serves read-only local API responses on port 0', async () => {
|
|
215
311
|
const dir = await fixture({
|
|
216
312
|
'content/a.md': '---\nslug: alpha\n---\n\n# Alpha\n\nReadable body.',
|
package/src/server/scan.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { genericBlocks } from '@contentbit/blocks'
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
compareContentProjectFindings,
|
|
3
|
+
createLinkGraphView,
|
|
4
|
+
createSeoBrief,
|
|
5
|
+
readContentPageFacts,
|
|
6
|
+
summarizeContentProjectFindings,
|
|
7
7
|
type ContentProjectFinding,
|
|
8
8
|
type ContentProjectScan,
|
|
9
9
|
type DocumentStats,
|
|
10
|
+
type SeoPage,
|
|
10
11
|
} from '@contentbit/core'
|
|
11
|
-
import {
|
|
12
|
-
import { basename,
|
|
13
|
-
import { pathToFileURL } from 'node:url'
|
|
14
|
-
import { glob } from 'tinyglobby'
|
|
12
|
+
import { loadContentProject } from '@contentbit/project'
|
|
13
|
+
import { basename, relative } from 'node:path'
|
|
15
14
|
|
|
16
15
|
import { renderStudioPreview } from './preview.js'
|
|
17
16
|
import type {
|
|
@@ -21,7 +20,6 @@ import type {
|
|
|
21
20
|
StudioGraph,
|
|
22
21
|
StudioGraphEdge,
|
|
23
22
|
StudioGraphNode,
|
|
24
|
-
StudioKeywordData,
|
|
25
23
|
StudioOptions,
|
|
26
24
|
StudioProject,
|
|
27
25
|
StudioStatus,
|
|
@@ -78,6 +76,17 @@ export async function scanProject(options: StudioOptions): Promise<StudioProject
|
|
|
78
76
|
withSecondary,
|
|
79
77
|
},
|
|
80
78
|
...(context.scan.linkGraph ? { linkGraph: context.scan.linkGraph } : {}),
|
|
79
|
+
...(context.scan.seo
|
|
80
|
+
? {
|
|
81
|
+
seo: {
|
|
82
|
+
schemaVersion: context.scan.seo.schemaVersion,
|
|
83
|
+
pages: context.scan.seo.pages.length,
|
|
84
|
+
existing: context.scan.seo.pages.filter((page) => page.source === 'existing').length,
|
|
85
|
+
planned: context.scan.seo.pages.filter((page) => page.source === 'planned').length,
|
|
86
|
+
findings: context.scan.seo.findings.length,
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
: {}),
|
|
81
90
|
findings: context.findings,
|
|
82
91
|
}
|
|
83
92
|
}
|
|
@@ -102,6 +111,9 @@ export async function scanDocument(
|
|
|
102
111
|
const page = context.index
|
|
103
112
|
? [...context.index.pages.values()].find((entry) => entry.path === file)
|
|
104
113
|
: undefined
|
|
114
|
+
const seoPage = context.scan.seo?.pages.find((entry) => entry.path === file)
|
|
115
|
+
const seoBrief =
|
|
116
|
+
context.scan.seo && seoPage ? createSeoBrief(context.scan.seo, seoPage.id) : undefined
|
|
105
117
|
|
|
106
118
|
return {
|
|
107
119
|
file: summary,
|
|
@@ -115,6 +127,7 @@ export async function scanDocument(
|
|
|
115
127
|
? page.linkedFromRefs
|
|
116
128
|
: page.linkedFrom
|
|
117
129
|
: [],
|
|
130
|
+
...(seoBrief ? { seoBrief } : {}),
|
|
118
131
|
previewHtml,
|
|
119
132
|
}
|
|
120
133
|
}
|
|
@@ -124,69 +137,36 @@ export async function scanGraph(options: StudioOptions): Promise<StudioGraph> {
|
|
|
124
137
|
if (!context.index) return { nodes: [], edges: [] }
|
|
125
138
|
|
|
126
139
|
const summaryByPath = new Map(context.summaries.map((summary) => [summary.path, summary]))
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
...(
|
|
140
|
+
const view = createLinkGraphView(context.index, context.scan.linkDiagnostics ?? [])
|
|
141
|
+
const nodes: StudioGraphNode[] = view.nodes.map((node) => ({
|
|
142
|
+
id: node.id,
|
|
143
|
+
label: node.label,
|
|
144
|
+
path: node.path,
|
|
145
|
+
status: summaryByPath.get(node.path)?.status ?? 'healthy',
|
|
146
|
+
slug: node.slug,
|
|
147
|
+
...(node.key ? { key: node.key } : {}),
|
|
148
|
+
...(node.locale ? { locale: node.locale } : {}),
|
|
135
149
|
}))
|
|
136
|
-
|
|
137
|
-
const pageByPath = new Map([...context.index.pages.values()].map((page) => [page.path, page]))
|
|
138
|
-
const edges: StudioGraphEdge[] = []
|
|
139
|
-
for (const page of context.index.pages.values()) {
|
|
140
|
-
for (const ref of page.linkRefs) {
|
|
141
|
-
const target = [...context.index.pages.values()].find(
|
|
142
|
-
(candidate) =>
|
|
143
|
-
candidate.slug === ref.slug &&
|
|
144
|
-
candidate.key === ref.key &&
|
|
145
|
-
candidate.locale === ref.locale,
|
|
146
|
-
)
|
|
147
|
-
edges.push({
|
|
148
|
-
from: pageIdentity(page),
|
|
149
|
-
to: target ? pageIdentity(target) : undefined,
|
|
150
|
-
target: ref.target ?? ref.key ?? ref.slug,
|
|
151
|
-
status:
|
|
152
|
-
target === page
|
|
153
|
-
? 'self'
|
|
154
|
-
: ref.locale && ref.locale !== page.locale
|
|
155
|
-
? 'cross-locale'
|
|
156
|
-
: 'resolved',
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
for (const finding of context.findings) {
|
|
162
|
-
if (finding.source !== 'links') continue
|
|
163
|
-
if (finding.code !== 'CB_LINK_UNRESOLVED' && finding.code !== 'CB_LINK_LOCALE_MISSING') continue
|
|
164
|
-
const page = pageByPath.get(finding.file)
|
|
165
|
-
if (!page) continue
|
|
166
|
-
edges.push({
|
|
167
|
-
from: pageIdentity(page),
|
|
168
|
-
target: targetFromMessage(finding.message) ?? 'unresolved',
|
|
169
|
-
status: 'unresolved',
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
|
|
150
|
+
const edges: StudioGraphEdge[] = view.edges
|
|
173
151
|
return { nodes, edges }
|
|
174
152
|
}
|
|
175
153
|
|
|
176
154
|
async function scanContext(options: StudioOptions): Promise<ScanContext> {
|
|
177
|
-
if (options.globs.length === 0) throw new Error('studio: provide at least one file or glob.')
|
|
178
155
|
const cwd = options.cwd ?? process.cwd()
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
)
|
|
186
|
-
const scan = scanContentProject(sourceFiles, registry, {
|
|
156
|
+
const project = await loadContentProject({
|
|
157
|
+
cmd: 'studio',
|
|
158
|
+
positionals: options.globs,
|
|
159
|
+
cwd,
|
|
160
|
+
registry: options.registryPath,
|
|
161
|
+
includeGenericBlocks: options.includeGenericBlocks,
|
|
187
162
|
linkOptions: options.linkOptions,
|
|
188
|
-
|
|
163
|
+
scan: {
|
|
164
|
+
minSectionWords: options.minSectionWords,
|
|
165
|
+
seoConfig: options.seoConfig,
|
|
166
|
+
seoConfigPath: options.seoConfigPath,
|
|
167
|
+
},
|
|
189
168
|
})
|
|
169
|
+
const { files, scan } = project
|
|
190
170
|
const findings = scan.findings
|
|
191
171
|
.map((finding) => findingFromProjectFinding(finding, cwd))
|
|
192
172
|
.sort(compareFindings)
|
|
@@ -198,6 +178,7 @@ async function scanContext(options: StudioOptions): Promise<ScanContext> {
|
|
|
198
178
|
file.stats,
|
|
199
179
|
findings.filter((finding) => finding.file === file.path),
|
|
200
180
|
options,
|
|
181
|
+
scan.seo?.pages.find((page) => page.path === file.path),
|
|
201
182
|
),
|
|
202
183
|
)
|
|
203
184
|
|
|
@@ -206,28 +187,6 @@ async function scanContext(options: StudioOptions): Promise<ScanContext> {
|
|
|
206
187
|
return { files, scan, findings, summaries, index }
|
|
207
188
|
}
|
|
208
189
|
|
|
209
|
-
async function loadStudioRegistry(
|
|
210
|
-
registryPath?: string,
|
|
211
|
-
cwd = process.cwd(),
|
|
212
|
-
includeGenericBlocks = true,
|
|
213
|
-
): Promise<BlockRegistry> {
|
|
214
|
-
const registry = createBlockRegistry()
|
|
215
|
-
if (includeGenericBlocks) registry.use(genericBlocks())
|
|
216
|
-
if (!registryPath) return registry
|
|
217
|
-
|
|
218
|
-
const resolvedPath = isAbsolute(registryPath) ? registryPath : join(cwd, registryPath)
|
|
219
|
-
const mod = (await import(pathToFileURL(resolvedPath).href)) as {
|
|
220
|
-
default?: BlockDefinition<unknown>[]
|
|
221
|
-
}
|
|
222
|
-
if (!Array.isArray(mod.default)) {
|
|
223
|
-
throw new Error(
|
|
224
|
-
`--registry module must default-export an array of block definitions: ${resolvedPath}`,
|
|
225
|
-
)
|
|
226
|
-
}
|
|
227
|
-
registry.use(mod.default)
|
|
228
|
-
return registry
|
|
229
|
-
}
|
|
230
|
-
|
|
231
190
|
function findingFromProjectFinding(finding: ContentProjectFinding, cwd: string): StudioFinding {
|
|
232
191
|
return {
|
|
233
192
|
severity: finding.severity,
|
|
@@ -249,20 +208,18 @@ function fileSummary(
|
|
|
249
208
|
stats: DocumentStats,
|
|
250
209
|
findings: StudioFinding[],
|
|
251
210
|
options: StudioOptions,
|
|
211
|
+
seoPage?: SeoPage,
|
|
252
212
|
): StudioFileSummary {
|
|
253
213
|
const counts = summarize(findings)
|
|
254
|
-
const
|
|
255
|
-
const slug = stringValue(frontmatter[options.linkOptions?.slugField ?? 'slug'])
|
|
256
|
-
const key = stringValue(frontmatter[options.linkOptions?.keyField ?? 'key'])
|
|
257
|
-
const locale = stringValue(frontmatter[options.linkOptions?.localeField ?? 'locale'])
|
|
214
|
+
const facts = readContentPageFacts(frontmatter, options.linkOptions)
|
|
258
215
|
return {
|
|
259
216
|
path: file,
|
|
260
217
|
relativePath: relativePath(cwd, file),
|
|
261
218
|
title: titleFor(file, frontmatter, stats),
|
|
262
|
-
...(slug ? { slug } : {}),
|
|
263
|
-
...(key ? { key } : {}),
|
|
264
|
-
...(locale ? { locale } : {}),
|
|
265
|
-
...(keywords ? { keywords } : {}),
|
|
219
|
+
...(facts.slug ? { slug: facts.slug } : {}),
|
|
220
|
+
...(facts.key ? { key: facts.key } : {}),
|
|
221
|
+
...(facts.locale ? { locale: facts.locale } : {}),
|
|
222
|
+
...(facts.keywords ? { keywords: facts.keywords } : {}),
|
|
266
223
|
words: stats.length.words,
|
|
267
224
|
readingMinutes: stats.length.readingMinutes,
|
|
268
225
|
blocks: stats.blocks.total,
|
|
@@ -270,6 +227,17 @@ function fileSummary(
|
|
|
270
227
|
links: stats.links.total,
|
|
271
228
|
externalLinks: stats.links.external,
|
|
272
229
|
missingAlt: stats.images.missingAlt,
|
|
230
|
+
...(seoPage
|
|
231
|
+
? {
|
|
232
|
+
seo: {
|
|
233
|
+
id: seoPage.id,
|
|
234
|
+
source: seoPage.source,
|
|
235
|
+
...(seoPage.type ? { type: seoPage.type } : {}),
|
|
236
|
+
...(seoPage.intent ? { intent: seoPage.intent } : {}),
|
|
237
|
+
findings: findings.filter((finding) => finding.source === 'seo').length,
|
|
238
|
+
},
|
|
239
|
+
}
|
|
240
|
+
: {}),
|
|
273
241
|
findings: counts,
|
|
274
242
|
status: statusFor(counts),
|
|
275
243
|
}
|
|
@@ -283,24 +251,8 @@ function titleFor(
|
|
|
283
251
|
return stringValue(frontmatter.title) ?? stats.outline[0]?.text ?? basename(file)
|
|
284
252
|
}
|
|
285
253
|
|
|
286
|
-
function keywordData(value: unknown): StudioKeywordData | undefined {
|
|
287
|
-
if (!value || typeof value !== 'object') return undefined
|
|
288
|
-
const record = value as Record<string, unknown>
|
|
289
|
-
const primary = stringValue(record.primary)
|
|
290
|
-
const secondary = Array.isArray(record.secondary)
|
|
291
|
-
? record.secondary.filter((item): item is string => typeof item === 'string')
|
|
292
|
-
: undefined
|
|
293
|
-
return primary || (secondary?.length ?? 0) > 0
|
|
294
|
-
? { ...(primary ? { primary } : {}), ...(secondary ? { secondary } : {}) }
|
|
295
|
-
: undefined
|
|
296
|
-
}
|
|
297
|
-
|
|
298
254
|
function summarize(findings: StudioFinding[]): StudioFileSummary['findings'] {
|
|
299
|
-
return
|
|
300
|
-
errors: findings.filter((finding) => finding.severity === 'error').length,
|
|
301
|
-
warnings: findings.filter((finding) => finding.severity === 'warning').length,
|
|
302
|
-
suggestions: findings.filter((finding) => finding.severity === 'info').length,
|
|
303
|
-
}
|
|
255
|
+
return summarizeContentProjectFindings(findings)
|
|
304
256
|
}
|
|
305
257
|
|
|
306
258
|
function statusFor(findings: StudioFileSummary['findings']): StudioStatus {
|
|
@@ -320,7 +272,7 @@ function findAllowedFile(context: ScanContext, cwd: string, requestedPath: strin
|
|
|
320
272
|
|
|
321
273
|
function compareFindings(a: StudioFinding, b: StudioFinding): number {
|
|
322
274
|
return (
|
|
323
|
-
|
|
275
|
+
compareContentProjectFindings(a, b) ||
|
|
324
276
|
a.relativePath.localeCompare(b.relativePath) ||
|
|
325
277
|
(a.line ?? 0) - (b.line ?? 0) ||
|
|
326
278
|
(a.column ?? 0) - (b.column ?? 0) ||
|
|
@@ -328,24 +280,6 @@ function compareFindings(a: StudioFinding, b: StudioFinding): number {
|
|
|
328
280
|
)
|
|
329
281
|
}
|
|
330
282
|
|
|
331
|
-
function rank(finding: StudioFinding): number {
|
|
332
|
-
if (finding.severity === 'error' && finding.source === 'validation') return 0
|
|
333
|
-
if (finding.severity === 'error' && finding.source === 'links') return 1
|
|
334
|
-
if (finding.severity === 'warning') return 2
|
|
335
|
-
if (finding.code === 'CB_THIN_SECTION') return 3
|
|
336
|
-
if (finding.code === 'CB_BLOCKLESS_DOCUMENT') return 4
|
|
337
|
-
if (finding.code === 'CB_IMAGE_ALT_MISSING') return 5
|
|
338
|
-
return 6
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
function pageIdentity(page: { locale?: string; key?: string; slug: string }): string {
|
|
342
|
-
return `${page.locale ?? ''}\0${page.key ?? page.slug}`
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function targetFromMessage(message: string): string | undefined {
|
|
346
|
-
return message.match(/linksTo "([^"]+)"/)?.[1]
|
|
347
|
-
}
|
|
348
|
-
|
|
349
283
|
function stringValue(value: unknown): string | undefined {
|
|
350
284
|
return typeof value === 'string' && value.trim().length > 0 ? value : undefined
|
|
351
285
|
}
|
package/src/server/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { DocumentStats, LinkReference, LinkResolverOptions } from '@contentbit/core'
|
|
1
|
+
import type { DocumentStats, LinkReference, LinkResolverOptions, SeoBrief } from '@contentbit/core'
|
|
2
2
|
import type { BlockComponent } from '@contentbit/react'
|
|
3
3
|
|
|
4
4
|
export type StudioSeverity = 'error' | 'warning' | 'info'
|
|
5
5
|
export type StudioStatus = 'error' | 'warning' | 'suggestion' | 'healthy'
|
|
6
|
-
export type StudioFindingSource = 'validation' | 'links' | 'stats'
|
|
6
|
+
export type StudioFindingSource = 'validation' | 'links' | 'stats' | 'seo'
|
|
7
7
|
|
|
8
8
|
export interface StudioFinding {
|
|
9
9
|
severity: StudioSeverity
|
|
@@ -20,6 +20,7 @@ export interface StudioFinding {
|
|
|
20
20
|
export interface StudioKeywordData {
|
|
21
21
|
primary?: string
|
|
22
22
|
secondary?: string[]
|
|
23
|
+
lsi?: string[]
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export interface StudioFileSummary {
|
|
@@ -37,6 +38,13 @@ export interface StudioFileSummary {
|
|
|
37
38
|
links: number
|
|
38
39
|
externalLinks: number
|
|
39
40
|
missingAlt: number
|
|
41
|
+
seo?: {
|
|
42
|
+
id: string
|
|
43
|
+
source: 'existing' | 'planned'
|
|
44
|
+
type?: string
|
|
45
|
+
intent?: string
|
|
46
|
+
findings: number
|
|
47
|
+
}
|
|
40
48
|
findings: { errors: number; warnings: number; suggestions: number }
|
|
41
49
|
status: StudioStatus
|
|
42
50
|
}
|
|
@@ -57,6 +65,13 @@ export interface StudioProject {
|
|
|
57
65
|
blockUsage: Record<string, number>
|
|
58
66
|
keywordCoverage: { total: number; withPrimary: number; withSecondary: number }
|
|
59
67
|
linkGraph?: { pages: number; links: number; orphans: number }
|
|
68
|
+
seo?: {
|
|
69
|
+
schemaVersion: string
|
|
70
|
+
pages: number
|
|
71
|
+
existing: number
|
|
72
|
+
planned: number
|
|
73
|
+
findings: number
|
|
74
|
+
}
|
|
60
75
|
findings: StudioFinding[]
|
|
61
76
|
}
|
|
62
77
|
|
|
@@ -68,6 +83,7 @@ export interface StudioDocument {
|
|
|
68
83
|
findings: StudioFinding[]
|
|
69
84
|
linksTo: string[] | LinkReference[]
|
|
70
85
|
linkedFrom: string[] | LinkReference[]
|
|
86
|
+
seoBrief?: SeoBrief
|
|
71
87
|
previewHtml: string
|
|
72
88
|
}
|
|
73
89
|
|
|
@@ -100,6 +116,8 @@ export interface StudioOptions {
|
|
|
100
116
|
cwd?: string
|
|
101
117
|
linkOptions?: LinkResolverOptions
|
|
102
118
|
minSectionWords?: number
|
|
119
|
+
seoConfig?: unknown
|
|
120
|
+
seoConfigPath?: string
|
|
103
121
|
previewComponents?: () => Promise<Record<string, BlockComponent> | undefined>
|
|
104
122
|
}
|
|
105
123
|
|