@contentbit/studio 0.5.0 → 0.6.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/dist/client/assets/api-DA8X6vBb.js +1 -0
- package/dist/client/assets/document-BJw10sM7.js +65 -0
- package/dist/client/assets/{index-DTXIZgkK.js → index-WzJZ-6CK.js} +2 -2
- package/dist/client/assets/routes-BWt7eK2V.js +1 -0
- package/dist/client/assets/styles-DogO4Wcf.css +2 -0
- package/dist/server/assets/{_tanstack-start-manifest_v-wPlN1Hjy.js → _tanstack-start-manifest_v-DyPYRepF.js} +4 -4
- package/dist/server/assets/{document-DjmCb_Rp.js → document-BB_UYqNL.js} +1 -1
- package/dist/server/assets/document-DSV89Ser.js +4704 -0
- package/dist/server/assets/{router-D4DnWGjU.js → router-BJiN6b7L.js} +3 -3
- 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 +475 -124
- package/dist/server/scan.d.ts.map +1 -1
- 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 +6 -5
- package/src/routes/document.tsx +272 -1
- package/src/routes/index.tsx +21 -1
- package/src/server/index.ts +2 -0
- package/src/server/scan.test.ts +157 -1
- 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/dist/client/assets/styles-DxZJz8Oi.css +0 -2
- package/dist/server/api.js +0 -47
- package/dist/server/assets/document-CxPFBdxd.js +0 -265
- package/dist/server/preview.js +0 -19
- package/dist/server/scan.js +0 -274
- package/dist/server/types.js +0 -1
package/dist/server/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
|
export type StudioSeverity = 'error' | 'warning' | 'info';
|
|
4
4
|
export type StudioStatus = 'error' | 'warning' | 'suggestion' | 'healthy';
|
|
5
|
-
export type StudioFindingSource = 'validation' | 'links' | 'stats';
|
|
5
|
+
export type StudioFindingSource = 'validation' | 'links' | 'stats' | 'seo';
|
|
6
6
|
export interface StudioFinding {
|
|
7
7
|
severity: StudioSeverity;
|
|
8
8
|
source: StudioFindingSource;
|
|
@@ -17,6 +17,7 @@ export interface StudioFinding {
|
|
|
17
17
|
export interface StudioKeywordData {
|
|
18
18
|
primary?: string;
|
|
19
19
|
secondary?: string[];
|
|
20
|
+
lsi?: string[];
|
|
20
21
|
}
|
|
21
22
|
export interface StudioFileSummary {
|
|
22
23
|
path: string;
|
|
@@ -33,6 +34,13 @@ export interface StudioFileSummary {
|
|
|
33
34
|
links: number;
|
|
34
35
|
externalLinks: number;
|
|
35
36
|
missingAlt: number;
|
|
37
|
+
seo?: {
|
|
38
|
+
id: string;
|
|
39
|
+
source: 'existing' | 'planned';
|
|
40
|
+
type?: string;
|
|
41
|
+
intent?: string;
|
|
42
|
+
findings: number;
|
|
43
|
+
};
|
|
36
44
|
findings: {
|
|
37
45
|
errors: number;
|
|
38
46
|
warnings: number;
|
|
@@ -64,6 +72,13 @@ export interface StudioProject {
|
|
|
64
72
|
links: number;
|
|
65
73
|
orphans: number;
|
|
66
74
|
};
|
|
75
|
+
seo?: {
|
|
76
|
+
schemaVersion: string;
|
|
77
|
+
pages: number;
|
|
78
|
+
existing: number;
|
|
79
|
+
planned: number;
|
|
80
|
+
findings: number;
|
|
81
|
+
};
|
|
67
82
|
findings: StudioFinding[];
|
|
68
83
|
}
|
|
69
84
|
export interface StudioDocument {
|
|
@@ -74,6 +89,7 @@ export interface StudioDocument {
|
|
|
74
89
|
findings: StudioFinding[];
|
|
75
90
|
linksTo: string[] | LinkReference[];
|
|
76
91
|
linkedFrom: string[] | LinkReference[];
|
|
92
|
+
seoBrief?: SeoBrief;
|
|
77
93
|
previewHtml: string;
|
|
78
94
|
}
|
|
79
95
|
export interface StudioGraphNode {
|
|
@@ -102,6 +118,8 @@ export interface StudioOptions {
|
|
|
102
118
|
cwd?: string;
|
|
103
119
|
linkOptions?: LinkResolverOptions;
|
|
104
120
|
minSectionWords?: number;
|
|
121
|
+
seoConfig?: unknown;
|
|
122
|
+
seoConfigPath?: string;
|
|
105
123
|
previewComponents?: () => Promise<Record<string, BlockComponent> | undefined>;
|
|
106
124
|
}
|
|
107
125
|
export interface StartStudioOptions extends StudioOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACnG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAA;AACzD,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAAA;AACzE,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAA;AAE1E,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,cAAc,CAAA;IACxB,MAAM,EAAE,mBAAmB,CAAA;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 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentbit/studio",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Local read-only content studio for contentbit projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"tinyglobby": "^0.2.10",
|
|
49
49
|
"tw-animate-css": "^1.4.0",
|
|
50
50
|
"vite": "^8",
|
|
51
|
-
"@contentbit/blocks": "0.
|
|
52
|
-
"@contentbit/core": "0.
|
|
53
|
-
"@contentbit/react": "0.
|
|
51
|
+
"@contentbit/blocks": "0.6.1",
|
|
52
|
+
"@contentbit/core": "0.6.1",
|
|
53
|
+
"@contentbit/react": "0.6.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@testing-library/dom": "^10.4.1",
|
|
@@ -58,13 +58,14 @@
|
|
|
58
58
|
"@types/node": "^22",
|
|
59
59
|
"@types/react": "^19",
|
|
60
60
|
"@types/react-dom": "^19",
|
|
61
|
+
"esbuild": "^0.28.0",
|
|
61
62
|
"jsdom": "^28",
|
|
62
63
|
"typescript": "^6",
|
|
63
64
|
"vitest": "^4"
|
|
64
65
|
},
|
|
65
66
|
"scripts": {
|
|
66
67
|
"dev": "vite dev --port 3000",
|
|
67
|
-
"build": "vite build && tsc -p tsconfig.server.json",
|
|
68
|
+
"build": "vite build && tsc -p tsconfig.server.json --emitDeclarationOnly && node build-server.mjs",
|
|
68
69
|
"preview": "vite preview",
|
|
69
70
|
"test": "vitest run",
|
|
70
71
|
"lint": "oxlint",
|
package/src/routes/document.tsx
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
+
import { formatSeoBriefMarkdown, type SeoBrief, type SeoPage } from '@contentbit/core'
|
|
1
2
|
import { createFileRoute, Link } from '@tanstack/react-router'
|
|
2
3
|
import {
|
|
3
4
|
AlertTriangle,
|
|
4
5
|
ArrowLeft,
|
|
5
6
|
BarChart3,
|
|
6
7
|
Braces,
|
|
8
|
+
Check,
|
|
9
|
+
Clipboard,
|
|
10
|
+
Download,
|
|
7
11
|
FileCode2,
|
|
12
|
+
FileJson,
|
|
13
|
+
FileText,
|
|
14
|
+
ListChecks,
|
|
8
15
|
Link2,
|
|
9
16
|
RefreshCw,
|
|
10
17
|
Search,
|
|
18
|
+
Target,
|
|
11
19
|
} from 'lucide-react'
|
|
12
20
|
import type { ReactNode } from 'react'
|
|
13
|
-
import { useEffect, useState } from 'react'
|
|
21
|
+
import { useEffect, useMemo, useState } from 'react'
|
|
14
22
|
|
|
15
23
|
import { Button } from '@/components/ui/button'
|
|
16
24
|
import { fetchDocument } from '@/lib/api'
|
|
@@ -115,6 +123,12 @@ function DocumentDetail() {
|
|
|
115
123
|
/>
|
|
116
124
|
</Panel>
|
|
117
125
|
|
|
126
|
+
{document.seoBrief && (
|
|
127
|
+
<Panel title="Brief" icon={<Target className="size-4" />}>
|
|
128
|
+
<SeoBriefView brief={document.seoBrief} />
|
|
129
|
+
</Panel>
|
|
130
|
+
)}
|
|
131
|
+
|
|
118
132
|
<Panel title="Source" icon={<FileCode2 className="size-4" />}>
|
|
119
133
|
<pre className="max-h-[34rem] overflow-auto whitespace-pre-wrap break-words bg-muted p-4 font-mono text-xs leading-5">
|
|
120
134
|
{document.source}
|
|
@@ -163,6 +177,16 @@ function DocumentDetail() {
|
|
|
163
177
|
</div>
|
|
164
178
|
</div>
|
|
165
179
|
)}
|
|
180
|
+
{(document.file.keywords.lsi?.length ?? 0) > 0 && (
|
|
181
|
+
<div>
|
|
182
|
+
<p className="text-xs uppercase text-muted-foreground">LSI</p>
|
|
183
|
+
<div className="mt-2 flex flex-wrap gap-1">
|
|
184
|
+
{document.file.keywords.lsi?.map((keyword) => (
|
|
185
|
+
<Badge key={keyword}>{keyword}</Badge>
|
|
186
|
+
))}
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
189
|
+
)}
|
|
166
190
|
</div>
|
|
167
191
|
) : (
|
|
168
192
|
<p className="text-sm text-muted-foreground">No keyword frontmatter found.</p>
|
|
@@ -219,6 +243,224 @@ function MetricGrid({ items }: { items: Array<[string, number | string]> }) {
|
|
|
219
243
|
)
|
|
220
244
|
}
|
|
221
245
|
|
|
246
|
+
type BriefFormat = 'markdown' | 'json'
|
|
247
|
+
|
|
248
|
+
function SeoBriefView({ brief }: { brief: SeoBrief }) {
|
|
249
|
+
const [rawFormat, setRawFormat] = useState<BriefFormat>('markdown')
|
|
250
|
+
const [copiedFormat, setCopiedFormat] = useState<BriefFormat | null>(null)
|
|
251
|
+
const markdown = useMemo(() => formatSeoBriefMarkdown(brief), [brief])
|
|
252
|
+
const json = useMemo(() => JSON.stringify(brief, null, 2), [brief])
|
|
253
|
+
const raw = rawFormat === 'markdown' ? markdown : json
|
|
254
|
+
|
|
255
|
+
async function copy(format: BriefFormat) {
|
|
256
|
+
const value = format === 'markdown' ? markdown : json
|
|
257
|
+
try {
|
|
258
|
+
await navigator.clipboard.writeText(value)
|
|
259
|
+
setCopiedFormat(format)
|
|
260
|
+
window.setTimeout(() => setCopiedFormat(null), 1400)
|
|
261
|
+
} catch {
|
|
262
|
+
setCopiedFormat(null)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function download(format: BriefFormat) {
|
|
267
|
+
const value = format === 'markdown' ? markdown : json
|
|
268
|
+
const extension = format === 'markdown' ? 'md' : 'json'
|
|
269
|
+
downloadText(`${briefFilename(brief)}.${extension}`, value)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return (
|
|
273
|
+
<div className="space-y-5">
|
|
274
|
+
<div className="flex flex-col gap-3 border-b pb-4 md:flex-row md:items-start md:justify-between">
|
|
275
|
+
<div className="min-w-0">
|
|
276
|
+
<div className="flex flex-wrap gap-1">
|
|
277
|
+
<Badge>{brief.target.source}</Badge>
|
|
278
|
+
{brief.target.type && <Badge>{brief.target.type}</Badge>}
|
|
279
|
+
{brief.target.intent && <Badge>{brief.target.intent}</Badge>}
|
|
280
|
+
</div>
|
|
281
|
+
<h3 className="mt-2 break-words text-xl font-semibold">
|
|
282
|
+
{brief.target.title ?? brief.target.key ?? brief.target.slug ?? brief.target.id}
|
|
283
|
+
</h3>
|
|
284
|
+
<div className="mt-2 grid gap-2 text-xs text-muted-foreground md:grid-cols-2">
|
|
285
|
+
<BriefMeta label="id" value={brief.target.id} />
|
|
286
|
+
<BriefMeta label="key" value={brief.target.key} />
|
|
287
|
+
<BriefMeta label="slug" value={brief.target.slug} />
|
|
288
|
+
<BriefMeta label="primary" value={brief.target.keywords?.primary} />
|
|
289
|
+
</div>
|
|
290
|
+
</div>
|
|
291
|
+
<div className="flex flex-wrap gap-2">
|
|
292
|
+
<Button
|
|
293
|
+
type="button"
|
|
294
|
+
variant="outline"
|
|
295
|
+
className="h-8 gap-2 px-2.5 text-xs"
|
|
296
|
+
onClick={() => void copy('markdown')}
|
|
297
|
+
>
|
|
298
|
+
{copiedFormat === 'markdown' ? (
|
|
299
|
+
<Check className="size-3.5" />
|
|
300
|
+
) : (
|
|
301
|
+
<Clipboard className="size-3.5" />
|
|
302
|
+
)}
|
|
303
|
+
{copiedFormat === 'markdown' ? 'Copied' : 'Copy Markdown'}
|
|
304
|
+
</Button>
|
|
305
|
+
<Button
|
|
306
|
+
type="button"
|
|
307
|
+
variant="outline"
|
|
308
|
+
className="h-8 gap-2 px-2.5 text-xs"
|
|
309
|
+
onClick={() => void copy('json')}
|
|
310
|
+
>
|
|
311
|
+
{copiedFormat === 'json' ? (
|
|
312
|
+
<Check className="size-3.5" />
|
|
313
|
+
) : (
|
|
314
|
+
<Clipboard className="size-3.5" />
|
|
315
|
+
)}
|
|
316
|
+
{copiedFormat === 'json' ? 'Copied' : 'Copy JSON'}
|
|
317
|
+
</Button>
|
|
318
|
+
<Button
|
|
319
|
+
type="button"
|
|
320
|
+
variant="outline"
|
|
321
|
+
className="h-8 gap-2 px-2.5 text-xs"
|
|
322
|
+
onClick={() => download('markdown')}
|
|
323
|
+
>
|
|
324
|
+
<Download className="size-3.5" />
|
|
325
|
+
Markdown
|
|
326
|
+
</Button>
|
|
327
|
+
<Button
|
|
328
|
+
type="button"
|
|
329
|
+
variant="outline"
|
|
330
|
+
className="h-8 gap-2 px-2.5 text-xs"
|
|
331
|
+
onClick={() => download('json')}
|
|
332
|
+
>
|
|
333
|
+
<Download className="size-3.5" />
|
|
334
|
+
JSON
|
|
335
|
+
</Button>
|
|
336
|
+
</div>
|
|
337
|
+
</div>
|
|
338
|
+
|
|
339
|
+
<div className="grid gap-5 lg:grid-cols-2">
|
|
340
|
+
<div className="space-y-4">
|
|
341
|
+
<KeywordList title="Secondary Keywords" items={brief.target.keywords?.secondary} />
|
|
342
|
+
<KeywordList title="LSI Keywords" items={brief.target.keywords?.lsi} />
|
|
343
|
+
<BriefList
|
|
344
|
+
title="Required Sections"
|
|
345
|
+
items={brief.requiredSections.map((section) => section.headings.join(' / '))}
|
|
346
|
+
/>
|
|
347
|
+
<BriefList title="Required Blocks" items={brief.requiredBlocks} />
|
|
348
|
+
<BriefList title="Recommended Blocks" items={brief.recommendedBlocks} />
|
|
349
|
+
</div>
|
|
350
|
+
<div className="space-y-4">
|
|
351
|
+
<BriefList title="Required Links" items={brief.requiredLinksTo} />
|
|
352
|
+
<BriefList
|
|
353
|
+
title="Current Findings"
|
|
354
|
+
items={brief.findings.map((finding) => `${finding.code}: ${finding.message}`)}
|
|
355
|
+
/>
|
|
356
|
+
<RelatedPages pages={brief.relatedPages} />
|
|
357
|
+
<BriefList
|
|
358
|
+
title="Acceptance"
|
|
359
|
+
items={brief.acceptanceChecks}
|
|
360
|
+
icon={<ListChecks className="size-4" />}
|
|
361
|
+
/>
|
|
362
|
+
</div>
|
|
363
|
+
</div>
|
|
364
|
+
|
|
365
|
+
<div className="border">
|
|
366
|
+
<div className="flex flex-col gap-3 border-b bg-muted/40 px-3 py-3 md:flex-row md:items-center md:justify-between">
|
|
367
|
+
<div className="flex items-center gap-2 text-sm font-medium">
|
|
368
|
+
{rawFormat === 'markdown' ? (
|
|
369
|
+
<FileText className="size-4" />
|
|
370
|
+
) : (
|
|
371
|
+
<FileJson className="size-4" />
|
|
372
|
+
)}
|
|
373
|
+
{rawFormat === 'markdown' ? 'Markdown' : 'JSON'}
|
|
374
|
+
</div>
|
|
375
|
+
<div className="flex w-fit gap-1 border bg-background p-1">
|
|
376
|
+
{(['markdown', 'json'] as const).map((format) => (
|
|
377
|
+
<button
|
|
378
|
+
key={format}
|
|
379
|
+
type="button"
|
|
380
|
+
onClick={() => setRawFormat(format)}
|
|
381
|
+
className={
|
|
382
|
+
rawFormat === format
|
|
383
|
+
? 'bg-foreground px-2.5 py-1.5 text-xs font-medium text-background'
|
|
384
|
+
: 'px-2.5 py-1.5 text-xs text-muted-foreground hover:text-foreground'
|
|
385
|
+
}
|
|
386
|
+
>
|
|
387
|
+
{format}
|
|
388
|
+
</button>
|
|
389
|
+
))}
|
|
390
|
+
</div>
|
|
391
|
+
</div>
|
|
392
|
+
<pre className="max-h-[28rem] overflow-auto whitespace-pre-wrap break-words bg-background p-4 font-mono text-xs leading-5">
|
|
393
|
+
{raw}
|
|
394
|
+
</pre>
|
|
395
|
+
</div>
|
|
396
|
+
</div>
|
|
397
|
+
)
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function BriefMeta({ label, value }: { label: string; value?: string }) {
|
|
401
|
+
if (!value) return null
|
|
402
|
+
return (
|
|
403
|
+
<div className="min-w-0">
|
|
404
|
+
<span className="mr-2 font-mono uppercase">{label}</span>
|
|
405
|
+
<span className="break-words text-foreground">{value}</span>
|
|
406
|
+
</div>
|
|
407
|
+
)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function KeywordList({ title, items }: { title: string; items?: string[] }) {
|
|
411
|
+
if (!items?.length) return null
|
|
412
|
+
return (
|
|
413
|
+
<div>
|
|
414
|
+
<p className="mb-2 text-xs uppercase text-muted-foreground">{title}</p>
|
|
415
|
+
<div className="flex flex-wrap gap-1">
|
|
416
|
+
{items.map((item) => (
|
|
417
|
+
<Badge key={item}>{item}</Badge>
|
|
418
|
+
))}
|
|
419
|
+
</div>
|
|
420
|
+
</div>
|
|
421
|
+
)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function BriefList({ title, items, icon }: { title: string; items: string[]; icon?: ReactNode }) {
|
|
425
|
+
if (items.length === 0) return null
|
|
426
|
+
return (
|
|
427
|
+
<div>
|
|
428
|
+
<div className="mb-2 flex items-center gap-2 text-xs uppercase text-muted-foreground">
|
|
429
|
+
{icon}
|
|
430
|
+
<p>{title}</p>
|
|
431
|
+
</div>
|
|
432
|
+
<ul className="space-y-1 text-sm">
|
|
433
|
+
{items.map((item) => (
|
|
434
|
+
<li key={item} className="break-words border bg-muted/40 px-2 py-1.5">
|
|
435
|
+
{item}
|
|
436
|
+
</li>
|
|
437
|
+
))}
|
|
438
|
+
</ul>
|
|
439
|
+
</div>
|
|
440
|
+
)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function RelatedPages({ pages }: { pages: SeoPage[] }) {
|
|
444
|
+
if (pages.length === 0) return null
|
|
445
|
+
return (
|
|
446
|
+
<div>
|
|
447
|
+
<p className="mb-2 text-xs uppercase text-muted-foreground">Related Pages</p>
|
|
448
|
+
<ul className="space-y-1 text-sm">
|
|
449
|
+
{pages.map((page) => (
|
|
450
|
+
<li key={page.id} className="min-w-0 border bg-muted/40 px-2 py-1.5">
|
|
451
|
+
<p className="break-words font-medium">{pageLabel(page)}</p>
|
|
452
|
+
<div className="mt-1 flex flex-wrap gap-1">
|
|
453
|
+
{page.source && <Badge>{page.source}</Badge>}
|
|
454
|
+
{page.type && <Badge>{page.type}</Badge>}
|
|
455
|
+
{page.slug && <Badge>{page.slug}</Badge>}
|
|
456
|
+
</div>
|
|
457
|
+
</li>
|
|
458
|
+
))}
|
|
459
|
+
</ul>
|
|
460
|
+
</div>
|
|
461
|
+
)
|
|
462
|
+
}
|
|
463
|
+
|
|
222
464
|
function LinkList({ title, items }: { title: string; items: StudioDocument['linksTo'] }) {
|
|
223
465
|
return (
|
|
224
466
|
<div className="mb-4 last:mb-0">
|
|
@@ -266,3 +508,32 @@ function linkLabel(item: StudioDocument['linksTo'][number]): string {
|
|
|
266
508
|
if (typeof item === 'string') return item
|
|
267
509
|
return item.target ?? item.key ?? item.slug
|
|
268
510
|
}
|
|
511
|
+
|
|
512
|
+
function pageLabel(page: SeoPage): string {
|
|
513
|
+
return page.title ?? page.key ?? page.slug ?? page.id
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function briefFilename(brief: SeoBrief): string {
|
|
517
|
+
return safeFilename(
|
|
518
|
+
`contentbit-brief-${brief.target.key ?? brief.target.slug ?? brief.target.id}`,
|
|
519
|
+
)
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function safeFilename(value: string): string {
|
|
523
|
+
return value
|
|
524
|
+
.toLowerCase()
|
|
525
|
+
.replace(/[^a-z0-9._-]+/g, '-')
|
|
526
|
+
.replace(/^-+|-+$/g, '')
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function downloadText(filename: string, content: string): void {
|
|
530
|
+
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' })
|
|
531
|
+
const url = URL.createObjectURL(blob)
|
|
532
|
+
const link = document.createElement('a')
|
|
533
|
+
link.href = url
|
|
534
|
+
link.download = filename
|
|
535
|
+
document.body.append(link)
|
|
536
|
+
link.click()
|
|
537
|
+
link.remove()
|
|
538
|
+
URL.revokeObjectURL(url)
|
|
539
|
+
}
|
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdir, mkdtemp, symlink, writeFile } from 'node:fs/promises'
|
|
2
2
|
import { tmpdir } from 'node:os'
|
|
3
3
|
import { dirname, join } from 'node:path'
|
|
4
|
-
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
5
5
|
import { afterEach, expect, test } from 'vitest'
|
|
6
6
|
|
|
7
7
|
import { scanDocument, scanGraph, scanProject } from './scan'
|
|
@@ -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,122 @@ 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
|
+
|
|
310
|
+
test('scanProject and scanDocument cover a Cookwise-style multilingual SEO fixture', async () => {
|
|
311
|
+
const dir = join(root, 'fixtures/real-projects/cookwise-lite')
|
|
312
|
+
const seoConfig = await loadFixtureSeoConfig('cookwise-lite')
|
|
313
|
+
const options = {
|
|
314
|
+
globs: ['content/**/*.md'],
|
|
315
|
+
cwd: dir,
|
|
316
|
+
minSectionWords: 0,
|
|
317
|
+
linkOptions: { resolve: 'same-locale-key' as const },
|
|
318
|
+
seoConfig,
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const project = await scanProject(options)
|
|
322
|
+
expect(project.summary.files).toBe(6)
|
|
323
|
+
expect(project.keywordCoverage).toEqual({ total: 6, withPrimary: 6, withSecondary: 6 })
|
|
324
|
+
expect(project.seo).toMatchObject({
|
|
325
|
+
schemaVersion: 'contentbit.seo.v1',
|
|
326
|
+
pages: 7,
|
|
327
|
+
existing: 6,
|
|
328
|
+
planned: 1,
|
|
329
|
+
findings: 0,
|
|
330
|
+
})
|
|
331
|
+
expect(
|
|
332
|
+
project.files.find(
|
|
333
|
+
(file) => file.relativePath === 'content/blog/cooking-oil-smoke-points/fr.md',
|
|
334
|
+
)?.keywords,
|
|
335
|
+
).toMatchObject({
|
|
336
|
+
primary: 'point de fumee huile cuisson',
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
const document = await scanDocument(options, 'content/blog/cooking-oil-smoke-points/fr.md')
|
|
340
|
+
expect(document?.seoBrief).toMatchObject({
|
|
341
|
+
schemaVersion: 'contentbit.seo.brief.v1',
|
|
342
|
+
target: {
|
|
343
|
+
id: 'blog/cooking-oil-smoke-points:fr',
|
|
344
|
+
key: 'blog/cooking-oil-smoke-points',
|
|
345
|
+
locale: 'fr',
|
|
346
|
+
keywords: { primary: 'point de fumee huile cuisson' },
|
|
347
|
+
},
|
|
348
|
+
})
|
|
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
|
+
expect(document?.seoBrief?.acceptanceChecks).toContain('Document includes section: Overview.')
|
|
360
|
+
})
|
|
361
|
+
|
|
214
362
|
test('startStudio serves read-only local API responses on port 0', async () => {
|
|
215
363
|
const dir = await fixture({
|
|
216
364
|
'content/a.md': '---\nslug: alpha\n---\n\n# Alpha\n\nReadable body.',
|
|
@@ -314,6 +462,14 @@ async function linkContentbitCore(dir: string): Promise<void> {
|
|
|
314
462
|
await symlink(join(root, 'packages/studio/node_modules/react'), join(dir, 'node_modules/react'))
|
|
315
463
|
}
|
|
316
464
|
|
|
465
|
+
async function loadFixtureSeoConfig(name: string): Promise<unknown> {
|
|
466
|
+
const moduleUrl = pathToFileURL(
|
|
467
|
+
join(root, 'fixtures/real-projects', name, 'contentbit.seo.config.ts'),
|
|
468
|
+
).href
|
|
469
|
+
const mod = (await import(moduleUrl)) as { default: unknown }
|
|
470
|
+
return mod.default
|
|
471
|
+
}
|
|
472
|
+
|
|
317
473
|
async function fetchJson(url: URL): Promise<unknown> {
|
|
318
474
|
const response = await fetch(url)
|
|
319
475
|
if (!response.ok) throw new Error(`Request failed: ${response.status}`)
|