@contentbit/studio 1.0.0 → 2.0.0-next.1
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 +22 -11
- package/dist/client/assets/api-aCc2x-IO.js +1 -0
- package/dist/client/assets/arrow-right-tp4VknZo.js +1 -0
- package/dist/client/assets/document-DIh3ZPXr.js +56 -0
- package/dist/client/assets/documents-CjBZYbQ4.js +1 -0
- package/dist/client/assets/file-code-corner-Fzc5liO9.js +1 -0
- package/dist/client/assets/file-text-B8O46COn.js +1 -0
- package/dist/client/assets/index-Cd04OFZT.js +11 -0
- package/dist/client/assets/page-BMU8eIrR.js +1 -0
- package/dist/client/assets/routes-WndCJoku.js +1 -0
- package/dist/client/assets/search-BnUPH8AI.js +1 -0
- package/dist/client/assets/styles-hAsz_paS.css +2 -0
- package/dist/client/assets/target-BMSXP2fU.js +1 -0
- package/dist/client/assets/templates-IJid1Zwh.js +1 -0
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/assets/_tanstack-start-manifest_v-WfZ3uz_l.js +69 -0
- package/dist/server/assets/api-CHfynRIj.js +342 -0
- package/dist/server/assets/{document-DSV89Ser.js → document-BjPXZ9gS.js} +2529 -1317
- package/dist/server/assets/{routes-FGdym0e5.js → documents-jT4KnSkA.js} +63 -112
- package/dist/server/assets/empty-plugin-adapters-Ctp1ZmyT.js +4 -0
- package/dist/server/assets/page--xw7NmtK.js +388 -0
- package/dist/server/assets/router-xI8HUWRI.js +125 -0
- package/dist/server/assets/routes-CfwU-Ww2.js +372 -0
- package/dist/server/assets/start-Dk-BJfGT.js +3 -0
- package/dist/server/assets/templates--9wK-MK9.js +123 -0
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +6217 -112
- package/dist/server/scan.d.ts +1 -2
- package/dist/server/scan.d.ts.map +1 -1
- package/dist/server/server.js +3150 -1878
- package/dist/server/site.d.ts +38 -0
- package/dist/server/site.d.ts.map +1 -0
- package/dist/server/types.d.ts +33 -31
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +26 -15
- package/src/components/studio.test.ts +10 -0
- package/src/components/studio.tsx +209 -0
- package/src/lib/api.test.ts +80 -0
- package/src/lib/api.ts +68 -7
- package/src/routeTree.gen.ts +57 -3
- package/src/routes/document.tsx +34 -88
- package/src/routes/documents.tsx +433 -0
- package/src/routes/index.tsx +295 -414
- package/src/routes/page.tsx +401 -0
- package/src/routes/templates.tsx +104 -0
- package/src/server/api.ts +19 -3
- package/src/server/index.ts +31 -12
- package/src/server/scan.test.ts +34 -47
- package/src/server/scan.ts +56 -82
- package/src/server/site.test.ts +355 -0
- package/src/server/site.ts +164 -0
- package/src/server/types.ts +28 -30
- package/tsconfig.json +1 -1
- package/dist/client/assets/api-BX-WUPtV.js +0 -1
- package/dist/client/assets/document-BOMp4_F5.js +0 -65
- package/dist/client/assets/index-C0ybJ4zQ.js +0 -12
- package/dist/client/assets/routes-ACKdIhYm.js +0 -1
- package/dist/client/assets/styles-DogO4Wcf.css +0 -2
- package/dist/server/assets/_tanstack-start-manifest_v-BC1PNuB0.js +0 -25
- package/dist/server/assets/api-Bqt_atjc.js +0 -72
- package/dist/server/assets/document-BB_UYqNL.js +0 -9
- package/dist/server/assets/empty-plugin-adapters-De7E1vAI.js +0 -5
- package/dist/server/assets/router-BJiN6b7L.js +0 -63
- package/dist/server/assets/routes-p0tk6PAr.js +0 -20
- package/dist/server/assets/start-m8EQRpUf.js +0 -4
package/src/server/scan.test.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { mkdir,
|
|
2
|
-
import { tmpdir } from 'node:os'
|
|
1
|
+
import { mkdir, symlink, writeFile } from 'node:fs/promises'
|
|
3
2
|
import { dirname, join } from 'node:path'
|
|
4
3
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
5
4
|
import { afterEach, expect, test } from 'vitest'
|
|
6
5
|
|
|
7
|
-
import { scanDocument,
|
|
6
|
+
import { scanDocument, scanProject } from './scan'
|
|
8
7
|
import { startStudio, type StudioServer } from './index'
|
|
8
|
+
import { tempDir } from '../../../../test/temp-dir.js'
|
|
9
9
|
|
|
10
10
|
const root = fileURLToPath(new URL('../../../..', import.meta.url))
|
|
11
11
|
const runningServers: StudioServer[] = []
|
|
@@ -14,7 +14,7 @@ afterEach(async () => {
|
|
|
14
14
|
await Promise.all(runningServers.splice(0).map((server) => server.close()))
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
test('scanProject returns health, block
|
|
17
|
+
test('scanProject returns health, block and keyword summaries, and no frontmatter link graph', async () => {
|
|
18
18
|
const dir = await fixture({
|
|
19
19
|
'content/a.md': `---
|
|
20
20
|
slug: alpha
|
|
@@ -50,7 +50,6 @@ This second page closes the loop and keeps the graph free of dangling links.
|
|
|
50
50
|
const project = await scanProject({
|
|
51
51
|
globs: ['content/*.md'],
|
|
52
52
|
cwd: dir,
|
|
53
|
-
minSectionWords: 0,
|
|
54
53
|
})
|
|
55
54
|
|
|
56
55
|
expect(project.summary.files).toBe(2)
|
|
@@ -58,10 +57,10 @@ This second page closes the loop and keeps the graph free of dangling links.
|
|
|
58
57
|
expect(project.blockUsage.callout).toBe(1)
|
|
59
58
|
expect(project.keywordCoverage.withPrimary).toBe(2)
|
|
60
59
|
expect(project.keywordCoverage.withSecondary).toBe(1)
|
|
61
|
-
expect(project
|
|
60
|
+
expect(project).not.toHaveProperty('linkGraph')
|
|
62
61
|
})
|
|
63
62
|
|
|
64
|
-
test('scanProject ranks validation, link,
|
|
63
|
+
test('scanProject ranks validation findings before stats findings, and lists no frontmatter link finding, as check does', async () => {
|
|
65
64
|
const dir = await fixture({
|
|
66
65
|
'content/a.md': `---
|
|
67
66
|
slug: alpha
|
|
@@ -91,15 +90,13 @@ ${Array.from({ length: 260 }, (_, index) => `word${index}`).join(' ')}
|
|
|
91
90
|
`,
|
|
92
91
|
})
|
|
93
92
|
|
|
94
|
-
const project = await scanProject({ globs: ['content/*.md'], cwd: dir })
|
|
93
|
+
const project = await scanProject({ globs: ['content/*.md'], cwd: dir, blocks: true })
|
|
95
94
|
const codes = project.findings.map((finding) => finding.code)
|
|
96
95
|
|
|
97
96
|
expect(codes).toContain('CB_PROPS_INVALID')
|
|
98
|
-
expect(codes).toContain('CB_LINK_UNRESOLVED')
|
|
99
|
-
expect(codes).toContain('CB_THIN_SECTION')
|
|
100
|
-
expect(codes).toContain('CB_BLOCKLESS_DOCUMENT')
|
|
101
97
|
expect(codes).toContain('CB_IMAGE_ALT_MISSING')
|
|
102
|
-
expect(codes
|
|
98
|
+
expect(codes).not.toContain('CB_LINK_UNRESOLVED')
|
|
99
|
+
expect(codes.indexOf('CB_PROPS_INVALID')).toBeLessThan(codes.indexOf('CB_IMAGE_ALT_MISSING'))
|
|
103
100
|
})
|
|
104
101
|
|
|
105
102
|
test('scanProject reads seoKeywords as keyword data', async () => {
|
|
@@ -123,7 +120,6 @@ Useful body.
|
|
|
123
120
|
const project = await scanProject({
|
|
124
121
|
globs: ['content/*.md'],
|
|
125
122
|
cwd: dir,
|
|
126
|
-
minSectionWords: 0,
|
|
127
123
|
})
|
|
128
124
|
|
|
129
125
|
expect(project.keywordCoverage).toEqual({ total: 1, withPrimary: 1, withSecondary: 1 })
|
|
@@ -173,7 +169,7 @@ Custom block content for the local registry.
|
|
|
173
169
|
await linkContentbitCore(dir)
|
|
174
170
|
|
|
175
171
|
const document = await scanDocument(
|
|
176
|
-
{ globs: ['content/*.md'], cwd: dir, registryPath: 'blocks/registry.mjs'
|
|
172
|
+
{ globs: ['content/*.md'], cwd: dir, registryPath: 'blocks/registry.mjs' },
|
|
177
173
|
'content/a.md',
|
|
178
174
|
)
|
|
179
175
|
|
|
@@ -216,7 +212,6 @@ Project-owned quick reference content.
|
|
|
216
212
|
cwd: dir,
|
|
217
213
|
registryPath: 'blocks/registry.mjs',
|
|
218
214
|
includeGenericBlocks: false,
|
|
219
|
-
minSectionWords: 0,
|
|
220
215
|
},
|
|
221
216
|
'content/a.md',
|
|
222
217
|
)
|
|
@@ -226,21 +221,17 @@ Project-owned quick reference content.
|
|
|
226
221
|
expect(document?.previewHtml).toContain('data-cb-custom="quick-ref"')
|
|
227
222
|
})
|
|
228
223
|
|
|
229
|
-
test('
|
|
224
|
+
test('a document lists no frontmatter links or backlinks, since links are judged on the built pages', async () => {
|
|
230
225
|
const dir = await fixture({
|
|
231
226
|
'content/a.md': '---\nslug: alpha\nlinksTo:\n - beta\n - missing\n---\n\n# Alpha\n\nBody.',
|
|
232
|
-
'content/b.md': '---\nslug: beta\n---\n\n# Beta\n\nBody.',
|
|
227
|
+
'content/b.md': '---\nslug: beta\nlinksTo:\n - alpha\n---\n\n# Beta\n\nBody.',
|
|
233
228
|
})
|
|
234
229
|
|
|
235
|
-
const
|
|
230
|
+
const document = await scanDocument({ globs: ['content/*.md'], cwd: dir }, 'content/a.md')
|
|
236
231
|
|
|
237
|
-
expect(
|
|
238
|
-
expect(
|
|
239
|
-
|
|
240
|
-
)
|
|
241
|
-
expect(
|
|
242
|
-
graph.edges.some((edge) => edge.status === 'unresolved' && edge.target === 'missing'),
|
|
243
|
-
).toBe(true)
|
|
232
|
+
expect(document).not.toHaveProperty('linksTo')
|
|
233
|
+
expect(document).not.toHaveProperty('linkedFrom')
|
|
234
|
+
expect(document?.findings).toEqual([])
|
|
244
235
|
})
|
|
245
236
|
|
|
246
237
|
test('scanProject and scanDocument expose SEO status and briefs', async () => {
|
|
@@ -277,8 +268,7 @@ Useful overview body.
|
|
|
277
268
|
const project = await scanProject({
|
|
278
269
|
globs: ['content/*.md'],
|
|
279
270
|
cwd: dir,
|
|
280
|
-
|
|
281
|
-
seoConfig,
|
|
271
|
+
loadSeo: () => Promise.resolve({ config: seoConfig }),
|
|
282
272
|
})
|
|
283
273
|
expect(project.seo).toMatchObject({
|
|
284
274
|
schemaVersion: 'contentbit.seo.v1',
|
|
@@ -295,11 +285,15 @@ Useful overview body.
|
|
|
295
285
|
expect(project.findings.map((finding) => finding.code)).toContain('CB_SEO_SECTION_MISSING')
|
|
296
286
|
|
|
297
287
|
const document = await scanDocument(
|
|
298
|
-
{
|
|
288
|
+
{
|
|
289
|
+
globs: ['content/*.md'],
|
|
290
|
+
cwd: dir,
|
|
291
|
+
loadSeo: () => Promise.resolve({ config: seoConfig }),
|
|
292
|
+
},
|
|
299
293
|
'content/a.md',
|
|
300
294
|
)
|
|
301
295
|
expect(document?.seoBrief).toMatchObject({
|
|
302
|
-
schemaVersion: 'contentbit.seo.brief.
|
|
296
|
+
schemaVersion: 'contentbit.seo.brief.v2',
|
|
303
297
|
target: { id: 'alpha-alternatives' },
|
|
304
298
|
})
|
|
305
299
|
expect(document?.seoBrief?.acceptanceChecks).toContain(
|
|
@@ -313,9 +307,8 @@ test('scanProject and scanDocument cover a Cookwise-style multilingual SEO fixtu
|
|
|
313
307
|
const options = {
|
|
314
308
|
globs: ['content/**/*.md'],
|
|
315
309
|
cwd: dir,
|
|
316
|
-
minSectionWords: 0,
|
|
317
310
|
linkOptions: { resolve: 'same-locale-key' as const },
|
|
318
|
-
seoConfig,
|
|
311
|
+
loadSeo: () => Promise.resolve({ config: seoConfig }),
|
|
319
312
|
}
|
|
320
313
|
|
|
321
314
|
const project = await scanProject(options)
|
|
@@ -338,24 +331,13 @@ test('scanProject and scanDocument cover a Cookwise-style multilingual SEO fixtu
|
|
|
338
331
|
|
|
339
332
|
const document = await scanDocument(options, 'content/blog/cooking-oil-smoke-points/fr.md')
|
|
340
333
|
expect(document?.seoBrief).toMatchObject({
|
|
341
|
-
schemaVersion: 'contentbit.seo.brief.
|
|
334
|
+
schemaVersion: 'contentbit.seo.brief.v2',
|
|
342
335
|
target: {
|
|
343
336
|
id: 'blog/cooking-oil-smoke-points:fr',
|
|
344
337
|
key: 'blog/cooking-oil-smoke-points',
|
|
345
338
|
locale: 'fr',
|
|
346
|
-
keywords: { primary: 'point de fumee huile cuisson' },
|
|
347
339
|
},
|
|
348
340
|
})
|
|
349
|
-
expect(document?.linksTo).toEqual(
|
|
350
|
-
expect.arrayContaining([
|
|
351
|
-
expect.objectContaining({
|
|
352
|
-
target: 'blog/butter-vs-oil',
|
|
353
|
-
locale: 'fr',
|
|
354
|
-
slug: 'beurre-ou-huile',
|
|
355
|
-
key: 'blog/butter-vs-oil',
|
|
356
|
-
}),
|
|
357
|
-
]),
|
|
358
|
-
)
|
|
359
341
|
expect(document?.seoBrief?.acceptanceChecks).toContain('Document includes section: Overview.')
|
|
360
342
|
})
|
|
361
343
|
|
|
@@ -368,7 +350,6 @@ test('startStudio serves read-only local API responses on port 0', async () => {
|
|
|
368
350
|
cwd: dir,
|
|
369
351
|
port: 0,
|
|
370
352
|
open: false,
|
|
371
|
-
minSectionWords: 0,
|
|
372
353
|
})
|
|
373
354
|
runningServers.push(server)
|
|
374
355
|
|
|
@@ -377,10 +358,12 @@ test('startStudio serves read-only local API responses on port 0', async () => {
|
|
|
377
358
|
}
|
|
378
359
|
const blocked = await fetch(new URL('/api/document?path=../secret.md', server.url))
|
|
379
360
|
const write = await fetch(new URL('/api/project', server.url), { method: 'POST' })
|
|
361
|
+
const graph = await fetch(new URL('/api/graph', server.url))
|
|
380
362
|
|
|
381
363
|
expect(project.summary.files).toBe(1)
|
|
382
364
|
expect(blocked.status).toBe(404)
|
|
383
365
|
expect(write.status).toBe(405)
|
|
366
|
+
expect(graph.status).toBe(404)
|
|
384
367
|
})
|
|
385
368
|
|
|
386
369
|
test('startStudio with port 0 listens on an OS-assigned port and reports it', async () => {
|
|
@@ -436,7 +419,12 @@ test('scanProject validates against the registry as it is on disk now', async ()
|
|
|
436
419
|
await linkContentbitCore(dir)
|
|
437
420
|
const errors = async () =>
|
|
438
421
|
(
|
|
439
|
-
await scanProject({
|
|
422
|
+
await scanProject({
|
|
423
|
+
globs: ['content/*.md'],
|
|
424
|
+
cwd: dir,
|
|
425
|
+
registryPath: 'blocks/registry.mjs',
|
|
426
|
+
blocks: true,
|
|
427
|
+
})
|
|
440
428
|
).findings
|
|
441
429
|
.filter((finding) => finding.severity === 'error')
|
|
442
430
|
.map((finding) => finding.code)
|
|
@@ -498,7 +486,6 @@ slug: alpha
|
|
|
498
486
|
registryPath: 'blocks/registry.mjs',
|
|
499
487
|
port: 0,
|
|
500
488
|
open: false,
|
|
501
|
-
minSectionWords: 0,
|
|
502
489
|
})
|
|
503
490
|
runningServers.push(server)
|
|
504
491
|
|
|
@@ -536,7 +523,7 @@ export function Callout() { return createElement('aside', { 'data-project-styled
|
|
|
536
523
|
})
|
|
537
524
|
|
|
538
525
|
async function fixture(files: Record<string, string>): Promise<string> {
|
|
539
|
-
const dir = await
|
|
526
|
+
const dir = await tempDir('cb-studio-')
|
|
540
527
|
for (const [path, content] of Object.entries(files)) {
|
|
541
528
|
const fullPath = join(dir, path)
|
|
542
529
|
await mkdir(dirname(fullPath), { recursive: true })
|
package/src/server/scan.ts
CHANGED
|
@@ -1,36 +1,33 @@
|
|
|
1
1
|
import {
|
|
2
|
-
compareContentProjectFindings,
|
|
3
|
-
createLinkGraphView,
|
|
4
2
|
createSeoBrief,
|
|
5
3
|
readContentPageFacts,
|
|
6
|
-
summarizeContentProjectFindings,
|
|
7
|
-
type ContentProjectFinding,
|
|
8
4
|
type ContentProjectScan,
|
|
9
5
|
type DocumentStats,
|
|
10
6
|
type SeoPage,
|
|
11
7
|
} from '@contentbit/core'
|
|
12
|
-
import {
|
|
13
|
-
import { basename
|
|
8
|
+
import { relativeInside } from '@contentbit/project'
|
|
9
|
+
import { basename } from 'node:path'
|
|
14
10
|
|
|
15
11
|
import { renderStudioPreview } from './preview.js'
|
|
12
|
+
import { loadSiteOrJoinInFlight, pagesByFile } from './site.js'
|
|
16
13
|
import type {
|
|
14
|
+
AgentGuidanceFinding,
|
|
17
15
|
StudioDocument,
|
|
18
16
|
StudioFileSummary,
|
|
19
17
|
StudioFinding,
|
|
20
|
-
StudioGraph,
|
|
21
|
-
StudioGraphEdge,
|
|
22
|
-
StudioGraphNode,
|
|
23
18
|
StudioOptions,
|
|
24
19
|
StudioProject,
|
|
20
|
+
StudioSeverity,
|
|
25
21
|
StudioStatus,
|
|
26
22
|
} from './types.js'
|
|
27
23
|
|
|
28
24
|
interface ScanContext {
|
|
29
25
|
files: string[]
|
|
30
|
-
|
|
26
|
+
agentGuidanceFindings: AgentGuidanceFinding[]
|
|
27
|
+
scan?: ContentProjectScan
|
|
31
28
|
findings: StudioFinding[]
|
|
32
29
|
summaries: StudioFileSummary[]
|
|
33
|
-
|
|
30
|
+
pagesOfFile: Map<string, string[]>
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
export async function scanProject(options: StudioOptions): Promise<StudioProject> {
|
|
@@ -55,7 +52,8 @@ export async function scanProject(options: StudioOptions): Promise<StudioProject
|
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
const
|
|
55
|
+
const { agentGuidanceFindings } = context
|
|
56
|
+
const summary = summarize([...context.findings, ...agentGuidanceFindings])
|
|
59
57
|
return {
|
|
60
58
|
root: options.cwd ?? process.cwd(),
|
|
61
59
|
files: context.summaries,
|
|
@@ -75,8 +73,7 @@ export async function scanProject(options: StudioOptions): Promise<StudioProject
|
|
|
75
73
|
withPrimary,
|
|
76
74
|
withSecondary,
|
|
77
75
|
},
|
|
78
|
-
...(context.scan
|
|
79
|
-
...(context.scan.seo
|
|
76
|
+
...(context.scan?.seo
|
|
80
77
|
? {
|
|
81
78
|
seo: {
|
|
82
79
|
schemaVersion: context.scan.seo.schemaVersion,
|
|
@@ -88,6 +85,7 @@ export async function scanProject(options: StudioOptions): Promise<StudioProject
|
|
|
88
85
|
}
|
|
89
86
|
: {}),
|
|
90
87
|
findings: context.findings,
|
|
88
|
+
agentGuidanceFindings,
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
|
|
@@ -98,8 +96,8 @@ export async function scanDocument(
|
|
|
98
96
|
const context = await scanContext(options)
|
|
99
97
|
const file = findAllowedFile(context, options.cwd ?? process.cwd(), requestedPath)
|
|
100
98
|
if (!file) return null
|
|
101
|
-
const scanned = context.scan
|
|
102
|
-
if (!scanned) return null
|
|
99
|
+
const scanned = context.scan?.files.find((item) => item.path === file)
|
|
100
|
+
if (!context.scan || !scanned) return null
|
|
103
101
|
const summary = context.summaries.find((item) => item.path === file)
|
|
104
102
|
if (!summary) return null
|
|
105
103
|
|
|
@@ -108,9 +106,6 @@ export async function scanDocument(
|
|
|
108
106
|
(await options.previewComponents?.()) ?? {},
|
|
109
107
|
{ includeGenericComponents: options.includeGenericBlocks !== false },
|
|
110
108
|
)
|
|
111
|
-
const page = context.index
|
|
112
|
-
? [...context.index.pages.values()].find((entry) => entry.path === file)
|
|
113
|
-
: undefined
|
|
114
109
|
const seoPage = context.scan.seo?.pages.find((entry) => entry.path === file)
|
|
115
110
|
const seoBrief =
|
|
116
111
|
context.scan.seo && seoPage ? createSeoBrief(context.scan.seo, seoPage.id) : undefined
|
|
@@ -121,56 +116,40 @@ export async function scanDocument(
|
|
|
121
116
|
frontmatter: scanned.frontmatter,
|
|
122
117
|
stats: scanned.stats,
|
|
123
118
|
findings: context.findings.filter((finding) => finding.file === file),
|
|
124
|
-
linksTo: page ? (page.linkRefs.length > 0 ? page.linkRefs : page.linksTo) : [],
|
|
125
|
-
linkedFrom: page
|
|
126
|
-
? page.linkedFromRefs.length > 0
|
|
127
|
-
? page.linkedFromRefs
|
|
128
|
-
: page.linkedFrom
|
|
129
|
-
: [],
|
|
130
119
|
...(seoBrief ? { seoBrief } : {}),
|
|
131
120
|
previewHtml,
|
|
121
|
+
pages: context.pagesOfFile.get(file) ?? [],
|
|
132
122
|
}
|
|
133
123
|
}
|
|
134
124
|
|
|
135
|
-
export async function scanGraph(options: StudioOptions): Promise<StudioGraph> {
|
|
136
|
-
const context = await scanContext(options)
|
|
137
|
-
if (!context.index) return { nodes: [], edges: [] }
|
|
138
|
-
|
|
139
|
-
const summaryByPath = new Map(context.summaries.map((summary) => [summary.path, summary]))
|
|
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 } : {}),
|
|
149
|
-
}))
|
|
150
|
-
const edges: StudioGraphEdge[] = view.edges
|
|
151
|
-
return { nodes, edges }
|
|
152
|
-
}
|
|
153
|
-
|
|
154
125
|
async function scanContext(options: StudioOptions): Promise<ScanContext> {
|
|
155
126
|
const cwd = options.cwd ?? process.cwd()
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
127
|
+
const loaded = await loadSiteOrJoinInFlight(options)
|
|
128
|
+
const files = loaded.markdown?.files ?? []
|
|
129
|
+
const scan = loaded.markdown?.scan
|
|
130
|
+
const findings = [
|
|
131
|
+
...(loaded.findings ?? []).flatMap(({ severity, code, message, hint, origin }) =>
|
|
132
|
+
origin.kind === 'source'
|
|
133
|
+
? [
|
|
134
|
+
studioFinding(
|
|
135
|
+
{
|
|
136
|
+
severity,
|
|
137
|
+
source: 'page',
|
|
138
|
+
code,
|
|
139
|
+
file: origin.file,
|
|
140
|
+
line: origin.line,
|
|
141
|
+
column: origin.column,
|
|
142
|
+
message,
|
|
143
|
+
hint,
|
|
144
|
+
},
|
|
145
|
+
cwd,
|
|
146
|
+
),
|
|
147
|
+
]
|
|
148
|
+
: [],
|
|
149
|
+
),
|
|
150
|
+
...loaded.contentFindings.map((finding) => studioFinding(finding, cwd)),
|
|
151
|
+
]
|
|
152
|
+
const summaries = (scan?.files ?? []).map((file) =>
|
|
174
153
|
fileSummary(
|
|
175
154
|
file.path,
|
|
176
155
|
cwd,
|
|
@@ -178,16 +157,20 @@ async function scanContext(options: StudioOptions): Promise<ScanContext> {
|
|
|
178
157
|
file.stats,
|
|
179
158
|
findings.filter((finding) => finding.file === file.path),
|
|
180
159
|
options,
|
|
181
|
-
scan
|
|
160
|
+
scan?.seo?.pages.find((page) => page.path === file.path),
|
|
182
161
|
),
|
|
183
162
|
)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
163
|
+
return {
|
|
164
|
+
files,
|
|
165
|
+
agentGuidanceFindings: loaded.agentFindings,
|
|
166
|
+
scan,
|
|
167
|
+
findings,
|
|
168
|
+
summaries,
|
|
169
|
+
pagesOfFile: pagesByFile(loaded.sources),
|
|
170
|
+
}
|
|
188
171
|
}
|
|
189
172
|
|
|
190
|
-
function
|
|
173
|
+
function studioFinding(finding: Omit<StudioFinding, 'relativePath'>, cwd: string): StudioFinding {
|
|
191
174
|
return {
|
|
192
175
|
severity: finding.severity,
|
|
193
176
|
source: finding.source,
|
|
@@ -251,8 +234,10 @@ function titleFor(
|
|
|
251
234
|
return stringValue(frontmatter.title) ?? stats.outline[0]?.text ?? basename(file)
|
|
252
235
|
}
|
|
253
236
|
|
|
254
|
-
function summarize(findings:
|
|
255
|
-
|
|
237
|
+
function summarize(findings: Array<{ severity: StudioSeverity }>): StudioFileSummary['findings'] {
|
|
238
|
+
const count = (severity: StudioSeverity) =>
|
|
239
|
+
findings.filter((finding) => finding.severity === severity).length
|
|
240
|
+
return { errors: count('error'), warnings: count('warning'), suggestions: count('info') }
|
|
256
241
|
}
|
|
257
242
|
|
|
258
243
|
function statusFor(findings: StudioFileSummary['findings']): StudioStatus {
|
|
@@ -270,21 +255,10 @@ function findAllowedFile(context: ScanContext, cwd: string, requestedPath: strin
|
|
|
270
255
|
)
|
|
271
256
|
}
|
|
272
257
|
|
|
273
|
-
function compareFindings(a: StudioFinding, b: StudioFinding): number {
|
|
274
|
-
return (
|
|
275
|
-
compareContentProjectFindings(a, b) ||
|
|
276
|
-
a.relativePath.localeCompare(b.relativePath) ||
|
|
277
|
-
(a.line ?? 0) - (b.line ?? 0) ||
|
|
278
|
-
(a.column ?? 0) - (b.column ?? 0) ||
|
|
279
|
-
a.code.localeCompare(b.code)
|
|
280
|
-
)
|
|
281
|
-
}
|
|
282
|
-
|
|
283
258
|
function stringValue(value: unknown): string | undefined {
|
|
284
259
|
return typeof value === 'string' && value.trim().length > 0 ? value : undefined
|
|
285
260
|
}
|
|
286
261
|
|
|
287
262
|
function relativePath(cwd: string, file: string): string {
|
|
288
|
-
|
|
289
|
-
return rel.startsWith('..') ? file : rel
|
|
263
|
+
return relativeInside(cwd, file) ?? file
|
|
290
264
|
}
|