@contentbit/studio 1.0.0 → 2.0.0-next.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.
Files changed (66) hide show
  1. package/README.md +19 -9
  2. package/dist/client/assets/api-aCc2x-IO.js +1 -0
  3. package/dist/client/assets/arrow-right-tp4VknZo.js +1 -0
  4. package/dist/client/assets/document-DIh3ZPXr.js +56 -0
  5. package/dist/client/assets/documents-CjBZYbQ4.js +1 -0
  6. package/dist/client/assets/file-code-corner-Fzc5liO9.js +1 -0
  7. package/dist/client/assets/file-text-B8O46COn.js +1 -0
  8. package/dist/client/assets/index-Cd04OFZT.js +11 -0
  9. package/dist/client/assets/page-BMU8eIrR.js +1 -0
  10. package/dist/client/assets/routes-WndCJoku.js +1 -0
  11. package/dist/client/assets/search-BnUPH8AI.js +1 -0
  12. package/dist/client/assets/styles-hAsz_paS.css +2 -0
  13. package/dist/client/assets/target-BMSXP2fU.js +1 -0
  14. package/dist/client/assets/templates-IJid1Zwh.js +1 -0
  15. package/dist/server/api.d.ts.map +1 -1
  16. package/dist/server/assets/_tanstack-start-manifest_v-WfZ3uz_l.js +69 -0
  17. package/dist/server/assets/api-CHfynRIj.js +342 -0
  18. package/dist/server/assets/{document-DSV89Ser.js → document-BjPXZ9gS.js} +2529 -1317
  19. package/dist/server/assets/{routes-FGdym0e5.js → documents-jT4KnSkA.js} +63 -112
  20. package/dist/server/assets/empty-plugin-adapters-Ctp1ZmyT.js +4 -0
  21. package/dist/server/assets/page--xw7NmtK.js +388 -0
  22. package/dist/server/assets/router-xI8HUWRI.js +125 -0
  23. package/dist/server/assets/routes-CfwU-Ww2.js +372 -0
  24. package/dist/server/assets/start-Dk-BJfGT.js +3 -0
  25. package/dist/server/assets/templates--9wK-MK9.js +123 -0
  26. package/dist/server/index.d.ts +2 -2
  27. package/dist/server/index.d.ts.map +1 -1
  28. package/dist/server/index.js +6104 -110
  29. package/dist/server/scan.d.ts +1 -2
  30. package/dist/server/scan.d.ts.map +1 -1
  31. package/dist/server/server.js +3150 -1878
  32. package/dist/server/site.d.ts +38 -0
  33. package/dist/server/site.d.ts.map +1 -0
  34. package/dist/server/types.d.ts +33 -31
  35. package/dist/server/types.d.ts.map +1 -1
  36. package/package.json +26 -15
  37. package/src/components/studio.test.ts +10 -0
  38. package/src/components/studio.tsx +209 -0
  39. package/src/lib/api.test.ts +80 -0
  40. package/src/lib/api.ts +68 -7
  41. package/src/routeTree.gen.ts +57 -3
  42. package/src/routes/document.tsx +34 -88
  43. package/src/routes/documents.tsx +433 -0
  44. package/src/routes/index.tsx +295 -414
  45. package/src/routes/page.tsx +401 -0
  46. package/src/routes/templates.tsx +104 -0
  47. package/src/server/api.ts +19 -3
  48. package/src/server/index.ts +31 -12
  49. package/src/server/scan.test.ts +31 -44
  50. package/src/server/scan.ts +56 -82
  51. package/src/server/site.test.ts +355 -0
  52. package/src/server/site.ts +164 -0
  53. package/src/server/types.ts +28 -30
  54. package/tsconfig.json +1 -1
  55. package/dist/client/assets/api-BX-WUPtV.js +0 -1
  56. package/dist/client/assets/document-BOMp4_F5.js +0 -65
  57. package/dist/client/assets/index-C0ybJ4zQ.js +0 -12
  58. package/dist/client/assets/routes-ACKdIhYm.js +0 -1
  59. package/dist/client/assets/styles-DogO4Wcf.css +0 -2
  60. package/dist/server/assets/_tanstack-start-manifest_v-BC1PNuB0.js +0 -25
  61. package/dist/server/assets/api-Bqt_atjc.js +0 -72
  62. package/dist/server/assets/document-BB_UYqNL.js +0 -9
  63. package/dist/server/assets/empty-plugin-adapters-De7E1vAI.js +0 -5
  64. package/dist/server/assets/router-BJiN6b7L.js +0 -63
  65. package/dist/server/assets/routes-p0tk6PAr.js +0 -20
  66. package/dist/server/assets/start-m8EQRpUf.js +0 -4
@@ -2,112 +2,79 @@ import { createFileRoute, Link, useNavigate } from '@tanstack/react-router'
2
2
  import {
3
3
  AlertTriangle,
4
4
  ArrowRight,
5
- Blocks,
6
- FileText,
7
- Filter,
8
- Link2,
5
+ Bot,
6
+ KeyRound,
7
+ Link2Off,
9
8
  RefreshCw,
10
9
  Search,
11
- ChevronsUpDown,
12
- Target,
10
+ SlidersHorizontal,
13
11
  } from 'lucide-react'
14
- import type { ReactNode } from 'react'
15
- import { useEffect, useMemo, useState } from 'react'
12
+ import { useMemo } from 'react'
16
13
 
14
+ import {
15
+ FileFindings,
16
+ Metric,
17
+ NoBuild,
18
+ Panel,
19
+ plural,
20
+ relativeTo,
21
+ severityTone,
22
+ SiteFindingItem,
23
+ StudioNav,
24
+ } from '../components/studio'
17
25
  import { Button } from '../components/ui/button'
18
- import { fetchGraph, fetchProject } from '../lib/api'
19
- import type { StudioFileSummary, StudioGraph, StudioProject, StudioStatus } from '../server/types'
20
-
21
- type StatusFilter = 'all' | StudioStatus
22
- type SortKey = 'document' | 'status' | 'blocks' | 'keywords' | 'findings'
23
- type SortDir = 'asc' | 'desc'
26
+ import { useSite } from '../lib/api'
27
+ import type { FindingCounts, StudioSite } from '../server/site'
24
28
 
25
- interface DashboardSearch {
29
+ interface SiteSearch {
26
30
  q: string
27
- status: StatusFilter
28
- sort: SortKey
29
- dir: SortDir
30
31
  }
31
32
 
33
+ const ORIGIN_SOURCES = {
34
+ flag: 'from --origin',
35
+ config: 'from site.origin',
36
+ canonicals: 'inferred from canonicals',
37
+ } as const
38
+
32
39
  export const Route = createFileRoute('/')({
33
- validateSearch: (search: Record<string, unknown>): DashboardSearch => ({
40
+ validateSearch: (search: Record<string, unknown>): SiteSearch => ({
34
41
  q: typeof search.q === 'string' ? search.q : '',
35
- status: isStatus(search.status) ? search.status : 'all',
36
- sort: isSortKey(search.sort) ? search.sort : 'status',
37
- dir: search.dir === 'asc' || search.dir === 'desc' ? search.dir : 'asc',
38
42
  }),
39
- component: Dashboard,
43
+ component: SiteView,
40
44
  })
41
45
 
42
- function Dashboard() {
46
+ function SiteView() {
43
47
  const search = Route.useSearch()
44
48
  const navigate = useNavigate({ from: '/' })
45
- const [project, setProject] = useState<StudioProject | null>(null)
46
- const [graph, setGraph] = useState<StudioGraph | null>(null)
47
- const [error, setError] = useState<string | null>(null)
48
- const [refreshing, setRefreshing] = useState(false)
49
-
50
- async function refresh() {
51
- setRefreshing(true)
52
- setError(null)
53
- try {
54
- const [project, graph] = await Promise.all([fetchProject(), fetchGraph()])
55
- setProject(project)
56
- setGraph(graph)
57
- } catch (err) {
58
- setError(err instanceof Error ? err.message : String(err))
59
- } finally {
60
- setRefreshing(false)
61
- }
62
- }
63
-
64
- useEffect(() => {
65
- void refresh()
66
- }, [])
49
+ const { data: site, error, refreshing, refresh } = useSite()
67
50
 
68
- const files = useMemo(() => {
69
- if (!project) return []
51
+ const pages = useMemo(() => {
52
+ if (site?.kind !== 'built') return []
70
53
  const query = search.q.toLowerCase().trim()
71
- return project.files
72
- .filter((file) => {
73
- const haystack = [
74
- file.relativePath,
75
- file.title,
76
- file.slug,
77
- file.key,
78
- file.locale,
79
- file.keywords?.primary,
80
- ...(file.keywords?.secondary ?? []),
81
- ...(file.keywords?.lsi ?? []),
82
- ]
83
- .filter(Boolean)
84
- .join(' ')
85
- .toLowerCase()
86
- return (
87
- (search.status === 'all' || file.status === search.status) && haystack.includes(query)
88
- )
89
- })
90
- .sort((a, b) => compareFiles(a, b, search.sort, search.dir))
91
- }, [project, search.dir, search.q, search.sort, search.status])
54
+ return site.context.pages.filter((page) =>
55
+ [page.path, page.title, page.source && relativeTo(site.root, page.source), page.type]
56
+ .concat(page.primaryKeyword)
57
+ .filter(Boolean)
58
+ .join(' ')
59
+ .toLowerCase()
60
+ .includes(query),
61
+ )
62
+ }, [site, search.q])
92
63
 
93
- function setSearch(next: Partial<DashboardSearch>) {
94
- void navigate({ to: '/', search: (prev) => ({ ...prev, ...next }) })
95
- }
96
-
97
- function setSort(sort: SortKey) {
98
- setSearch({ sort, dir: search.sort === sort && search.dir === 'asc' ? 'desc' : 'asc' })
99
- }
64
+ const built = site?.kind === 'built' ? site : undefined
65
+ const attached = built?.context.pages.filter(({ source }) => source !== undefined).length ?? 0
100
66
 
101
67
  return (
102
68
  <main className="min-h-svh bg-background text-foreground">
103
69
  <section className="border-b bg-muted/30">
104
70
  <div className="mx-auto flex max-w-7xl flex-col gap-6 px-5 py-6">
71
+ <StudioNav />
105
72
  <div className="flex flex-col gap-4 md:flex-row md:items-end md:justify-between">
106
73
  <div>
107
74
  <p className="font-mono text-xs uppercase text-muted-foreground">contentbit studio</p>
108
- <h1 className="mt-1 text-3xl font-semibold tracking-tight">Content dashboard</h1>
75
+ <h1 className="mt-1 text-3xl font-semibold tracking-tight">Built pages</h1>
109
76
  <p className="mt-2 max-w-2xl text-sm text-muted-foreground">
110
- Read-only view of content health, structure, links, keywords, and previews.
77
+ The pages the build serves, as contentbit check and contentbit context read them.
111
78
  </p>
112
79
  </div>
113
80
  <Button onClick={refresh} disabled={refreshing} className="w-fit gap-2">
@@ -116,370 +83,284 @@ function Dashboard() {
116
83
  </Button>
117
84
  </div>
118
85
 
119
- {project && (
120
- <div className="grid gap-px overflow-hidden rounded-sm border bg-border md:grid-cols-4">
121
- <Metric
122
- label="files"
123
- value={project.summary.files}
124
- icon={<FileText className="size-4" />}
125
- />
126
- <Metric
127
- label="findings"
128
- value={
129
- project.summary.errors + project.summary.warnings + project.summary.suggestions
130
- }
131
- icon={<AlertTriangle className="size-4" />}
132
- tone={
133
- project.summary.errors > 0 ? 'bad' : project.summary.warnings > 0 ? 'warn' : 'ok'
134
- }
135
- />
136
- <Metric
137
- label="blocks"
138
- value={project.summary.blocks}
139
- icon={<Blocks className="size-4" />}
140
- />
141
- <Metric
142
- label="graph"
143
- value={
144
- project.linkGraph
145
- ? `${project.linkGraph.pages}/${project.linkGraph.links}`
146
- : 'off'
147
- }
148
- icon={<Link2 className="size-4" />}
149
- />
150
- </div>
86
+ {built && (
87
+ <>
88
+ <dl className="grid gap-x-6 gap-y-1 text-sm md:grid-cols-[auto_1fr]">
89
+ <dt className="text-muted-foreground">Build</dt>
90
+ <dd className="font-mono">
91
+ {relativeTo(built.root, built.context.build)},{' '}
92
+ {plural(built.context.pages.length, 'page')}
93
+ </dd>
94
+ <dt className="text-muted-foreground">Origin</dt>
95
+ <dd className="font-mono">
96
+ {built.context.origin
97
+ ? `${built.context.origin.url} (${ORIGIN_SOURCES[built.context.origin.source]})`
98
+ : 'unknown'}
99
+ </dd>
100
+ <dt className="text-muted-foreground">Markdown</dt>
101
+ <dd>
102
+ {built.markdownFiles === 0
103
+ ? 'none'
104
+ : `${plural(built.markdownFiles, 'file')}, ${attached} with a built page`}
105
+ </dd>
106
+ {built.summary.ignored > 0 && (
107
+ <>
108
+ <dt className="text-muted-foreground">Ignored</dt>
109
+ <dd>{`${plural(built.summary.ignored, 'finding')}, by check.severity and check.ignore`}</dd>
110
+ </>
111
+ )}
112
+ </dl>
113
+ <div className="grid gap-px overflow-hidden rounded-sm border bg-border md:grid-cols-4">
114
+ <Metric label="pages" value={built.summary.pages} />
115
+ <Metric
116
+ label="errors"
117
+ value={built.summary.errors}
118
+ tone={built.summary.errors > 0 ? 'bad' : 'ok'}
119
+ />
120
+ <Metric
121
+ label="warnings"
122
+ value={built.summary.warnings}
123
+ tone={built.summary.warnings > 0 ? 'warn' : 'ok'}
124
+ />
125
+ <Metric label="template findings" value={built.context.templateFindings.length} />
126
+ </div>
127
+ </>
151
128
  )}
152
129
  </div>
153
130
  </section>
154
131
 
155
132
  <section className="mx-auto grid max-w-7xl gap-5 px-5 py-5 lg:grid-cols-[minmax(0,1fr)_320px]">
156
- <div className="min-w-0">
157
- <div className="mb-3 flex flex-col gap-2 md:flex-row">
158
- <label className="relative flex min-w-0 flex-1 items-center">
159
- <Search className="pointer-events-none absolute left-3 size-4 text-muted-foreground" />
160
- <input
161
- value={search.q}
162
- onChange={(event) => setSearch({ q: event.target.value })}
163
- placeholder="Search path, title, slug, keyword..."
164
- className="h-10 w-full border bg-background pl-9 pr-3 text-sm outline-none transition-colors focus:border-foreground"
165
- />
166
- </label>
167
- <div className="flex items-center gap-1 border bg-background p-1">
168
- <Filter className="mx-2 size-4 text-muted-foreground" />
169
- {(['all', 'error', 'warning', 'suggestion', 'healthy'] as const).map((status) => (
170
- <button
171
- key={status}
172
- onClick={() => setSearch({ status })}
173
- className={
174
- search.status === status
175
- ? 'bg-foreground px-2.5 py-1.5 text-xs font-medium text-background'
176
- : 'px-2.5 py-1.5 text-xs text-muted-foreground hover:text-foreground'
133
+ <div className="min-w-0 space-y-4">
134
+ {error && (
135
+ <Panel title="Error" icon={<AlertTriangle className="size-4" />}>
136
+ <p className="text-sm text-destructive">{error}</p>
137
+ </Panel>
138
+ )}
139
+ {!site && !error && (
140
+ <div className="border p-4 text-sm text-muted-foreground">Reading the site...</div>
141
+ )}
142
+ {site?.kind === 'unbuilt' && <NoBuild {...site} />}
143
+ {built && built.staleSources.length > 0 && (
144
+ <Panel title="Stale build" icon={<AlertTriangle className="size-4" />}>
145
+ <p className="text-sm">
146
+ {plural(built.staleSources.length, 'Markdown file')} changed after the build, so its
147
+ pages may not show them yet. Rebuild the site and press Refresh.
148
+ </p>
149
+ </Panel>
150
+ )}
151
+ {built && (
152
+ <>
153
+ <label className="relative flex min-w-0 items-center">
154
+ <Search className="pointer-events-none absolute left-3 size-4 text-muted-foreground" />
155
+ <input
156
+ value={search.q}
157
+ onChange={(event) =>
158
+ void navigate({ to: '/', search: { q: event.target.value } })
177
159
  }
178
- >
179
- {status}
180
- </button>
181
- ))}
182
- </div>
183
- </div>
184
-
185
- <div className="overflow-hidden border">
186
- <div className="grid grid-cols-[1.4fr_0.6fr_0.6fr_0.6fr_2rem] gap-px border-b bg-border text-xs font-medium uppercase text-muted-foreground">
187
- <SortHeader
188
- label="Document"
189
- active={search.sort === 'document'}
190
- onClick={() => setSort('document')}
191
- />
192
- <SortHeader
193
- label="Status"
194
- active={search.sort === 'status'}
195
- onClick={() => setSort('status')}
196
- />
197
- <SortHeader
198
- label="Blocks"
199
- active={search.sort === 'blocks'}
200
- onClick={() => setSort('blocks')}
201
- />
202
- <SortHeader
203
- label="Keywords"
204
- active={search.sort === 'keywords'}
205
- onClick={() => setSort('keywords')}
206
- />
207
- <div className="bg-muted/50 px-2 py-2" />
208
- </div>
209
- {error ? (
210
- <div className="p-4 text-sm text-destructive">{error}</div>
211
- ) : project ? (
212
- <div className="divide-y">
213
- {files.map((file) => (
214
- <FileRow key={file.path} file={file} />
215
- ))}
216
- {files.length === 0 && (
217
- <div className="p-4 text-sm text-muted-foreground">
218
- No documents match the current filters.
219
- </div>
220
- )}
160
+ placeholder="Search path, title, source, type, keyword..."
161
+ className="h-10 w-full border bg-background pl-9 pr-3 text-sm outline-none transition-colors focus:border-foreground"
162
+ />
163
+ </label>
164
+ <div className="overflow-hidden border">
165
+ <div className="grid grid-cols-[1.4fr_1fr_0.4fr_0.6fr_0.7fr_2rem] gap-px border-b bg-border text-xs font-medium uppercase text-muted-foreground">
166
+ {['Page', 'Source', 'Words', 'Links in', 'Findings', ''].map((label) => (
167
+ <div key={label} className="bg-muted/50 px-3 py-2">
168
+ {label}
169
+ </div>
170
+ ))}
171
+ </div>
172
+ <div className="divide-y">
173
+ {pages.map((page) => (
174
+ <Link
175
+ key={page.path}
176
+ to="/page"
177
+ search={{ path: page.path }}
178
+ className="grid grid-cols-[1.4fr_1fr_0.4fr_0.6fr_0.7fr_2rem] gap-px bg-border text-sm transition-colors hover:bg-foreground/20"
179
+ >
180
+ <div className="min-w-0 bg-background px-3 py-3">
181
+ <p className="truncate font-mono text-xs">{page.path}</p>
182
+ <p className="truncate text-muted-foreground">{page.title ?? 'No title'}</p>
183
+ </div>
184
+ <div className="min-w-0 bg-background px-3 py-3 font-mono text-xs text-muted-foreground">
185
+ <p className="truncate">
186
+ {page.source ? relativeTo(built.root, page.source) : 'none'}
187
+ </p>
188
+ {page.type && <p className="truncate">{page.type}</p>}
189
+ </div>
190
+ <div className="bg-background px-3 py-3 font-mono text-xs">{page.words}</div>
191
+ <div className="bg-background px-3 py-3 text-xs">
192
+ {page.linksIn.content} content
193
+ <span className="block text-muted-foreground">
194
+ {page.linksIn.layout} layout
195
+ </span>
196
+ </div>
197
+ <div className="bg-background px-3 py-3 text-xs">
198
+ <FindingCount counts={built.findingCountsByPage[page.path]} />
199
+ </div>
200
+ <div className="flex items-center justify-center bg-background px-2 py-3">
201
+ <ArrowRight className="size-4 text-muted-foreground" />
202
+ </div>
203
+ </Link>
204
+ ))}
205
+ {pages.length === 0 && (
206
+ <div className="p-4 text-sm text-muted-foreground">
207
+ No built page matches the search.
208
+ </div>
209
+ )}
210
+ </div>
221
211
  </div>
222
- ) : (
223
- <div className="p-4 text-sm text-muted-foreground">Scanning content...</div>
224
- )}
225
- </div>
212
+ </>
213
+ )}
226
214
  </div>
227
215
 
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>
216
+ {built && (
217
+ <aside className="flex flex-col gap-4">
218
+ <Panel title="Template findings" icon={<AlertTriangle className="size-4" />}>
219
+ {built.context.templateFindings.length === 0 ? (
220
+ <p className="text-sm text-muted-foreground">None.</p>
221
+ ) : (
222
+ <ul className="space-y-2 text-sm">
223
+ {built.context.templateFindings.slice(0, 5).map((finding, index) => (
224
+ <li key={`${finding.code}-${index}`} className="border bg-muted/30 px-2 py-1.5">
225
+ <span className={`font-medium ${severityTone(finding.severity)}`}>
226
+ {finding.code}
227
+ </span>
228
+ <span className="block text-xs text-muted-foreground">
229
+ {finding.origin.kind === 'template' &&
230
+ `on ${plural(finding.origin.pages.length, 'page')}`}
231
+ </span>
232
+ </li>
233
+ ))}
234
+ </ul>
235
+ )}
236
+ <Link
237
+ to="/templates"
238
+ className="mt-3 inline-block text-sm font-medium underline underline-offset-4"
239
+ >
240
+ All template findings
241
+ </Link>
240
242
  </Panel>
241
- )}
242
243
 
243
- <Panel title="Link graph">
244
- {project?.linkGraph ? (
245
- <div className="grid grid-cols-3 gap-px overflow-hidden border bg-border text-center">
246
- <TinyMetric value={project.linkGraph.pages} label="pages" />
247
- <TinyMetric value={project.linkGraph.links} label="links" />
248
- <TinyMetric value={project.linkGraph.orphans} label="orphans" />
249
- </div>
250
- ) : (
251
- <p className="text-sm text-muted-foreground">No slug frontmatter detected.</p>
252
- )}
253
- {graph && graph.edges.length > 0 && (
254
- <ul className="mt-3 flex max-h-56 flex-col gap-2 overflow-auto text-xs">
255
- {graph.edges.slice(0, 12).map((edge, index) => (
256
- <li
257
- key={`${edge.from}-${edge.target}-${index}`}
258
- className="flex items-center gap-2"
259
- >
260
- <span
261
- className={
262
- edge.status === 'unresolved' ? 'text-destructive' : 'text-muted-foreground'
263
- }
264
- >
265
- {edge.status}
266
- </span>
267
- <span className="truncate">{edge.target}</span>
268
- </li>
269
- ))}
270
- </ul>
244
+ {built.unbuiltFindings.length > 0 && (
245
+ <Panel title="Not on a built page" icon={<AlertTriangle className="size-4" />}>
246
+ <p className="mb-2 text-xs text-muted-foreground">
247
+ Findings about a URL the build has no page for.
248
+ </p>
249
+ <ul className="space-y-2">
250
+ {built.unbuiltFindings.map((finding, index) => (
251
+ <SiteFindingItem
252
+ key={`${finding.code}-${index}`}
253
+ finding={finding}
254
+ root={built.root}
255
+ showPage
256
+ />
257
+ ))}
258
+ </ul>
259
+ </Panel>
271
260
  )}
272
- </Panel>
273
261
 
274
- <Panel title="Block usage">
275
- {project && Object.keys(project.blockUsage).length > 0 ? (
276
- <div className="flex flex-wrap gap-1">
277
- {Object.entries(project.blockUsage).map(([name, count]) => (
278
- <span key={name} className="border bg-muted px-2 py-1 font-mono text-xs">
279
- {name} x{count}
280
- </span>
281
- ))}
282
- </div>
283
- ) : (
284
- <p className="text-sm text-muted-foreground">No blocks found yet.</p>
262
+ {built.configFindings.length > 0 && (
263
+ <Panel title="Check settings" icon={<SlidersHorizontal className="size-4" />}>
264
+ <FileFindings root={built.root} findings={built.configFindings} />
265
+ </Panel>
285
266
  )}
286
- </Panel>
287
267
 
288
- <Panel title="Keyword coverage">
289
- {project && (
290
- <div className="space-y-2 text-sm">
291
- <Coverage
292
- label="primary"
293
- value={project.keywordCoverage.withPrimary}
294
- total={project.keywordCoverage.total}
295
- />
296
- <Coverage
297
- label="secondary"
298
- value={project.keywordCoverage.withSecondary}
299
- total={project.keywordCoverage.total}
300
- />
301
- </div>
268
+ {built.agentGuidanceFindings.length > 0 && (
269
+ <Panel title="Agent guidance" icon={<Bot className="size-4" />}>
270
+ <FileFindings root={built.root} findings={built.agentGuidanceFindings} />
271
+ </Panel>
302
272
  )}
303
- </Panel>
304
- </aside>
305
- </section>
306
- </main>
307
- )
308
- }
309
-
310
- function FileRow({ file }: { file: StudioFileSummary }) {
311
- return (
312
- <Link
313
- to="/document"
314
- search={{ path: file.path }}
315
- className="grid grid-cols-[1.4fr_0.6fr_0.6fr_0.6fr_2rem] gap-px bg-border text-sm transition-colors hover:bg-foreground/20"
316
- >
317
- <div className="min-w-0 bg-background px-3 py-3">
318
- <p className="truncate font-medium">{file.title}</p>
319
- <p className="truncate font-mono text-xs text-muted-foreground">{file.relativePath}</p>
320
- </div>
321
- <div className="bg-background px-3 py-3">
322
- <StatusBadge status={file.status} />
323
- </div>
324
- <div className="bg-background px-3 py-3 font-mono text-xs">{file.blocks}</div>
325
- <div className="bg-background px-3 py-3 text-xs text-muted-foreground">
326
- {file.keywords?.primary ? 'primary' : 'missing'}
327
- </div>
328
- <div className="flex items-center justify-center bg-background px-2 py-3">
329
- <ArrowRight className="size-4 text-muted-foreground" />
330
- </div>
331
- </Link>
332
- )
333
- }
334
-
335
- function Metric({
336
- label,
337
- value,
338
- icon,
339
- tone,
340
- }: {
341
- label: string
342
- value: number | string
343
- icon: ReactNode
344
- tone?: 'bad' | 'warn' | 'ok'
345
- }) {
346
- const color =
347
- tone === 'bad'
348
- ? 'text-destructive'
349
- : tone === 'warn'
350
- ? 'text-amber-600'
351
- : tone === 'ok'
352
- ? 'text-emerald-600'
353
- : 'text-foreground'
354
- return (
355
- <div className="bg-background p-4">
356
- <div className="mb-3 flex items-center justify-between text-muted-foreground">
357
- <span className="text-xs uppercase">{label}</span>
358
- {icon}
359
- </div>
360
- <div className={`font-mono text-3xl font-semibold ${color}`}>{value}</div>
361
- </div>
362
- )
363
- }
364
-
365
- function TinyMetric({ value, label }: { value: number | string; label: string }) {
366
- return (
367
- <div className="bg-background px-2 py-2">
368
- <div className="font-mono text-lg font-semibold">{value}</div>
369
- <div className="text-[0.65rem] uppercase text-muted-foreground">{label}</div>
370
- </div>
371
- )
372
- }
373
273
 
374
- function Panel({ title, children }: { title: string; children: ReactNode }) {
375
- return (
376
- <section className="border bg-background p-4">
377
- <h2 className="mb-3 text-sm font-semibold">{title}</h2>
378
- {children}
379
- </section>
380
- )
381
- }
274
+ <Panel title="Unlinked pages" icon={<Link2Off className="size-4" />}>
275
+ <p className="mb-2 text-xs text-muted-foreground">
276
+ Indexable pages, other than the home page, that no content link on another page
277
+ points to.
278
+ </p>
279
+ {built.context.unlinked.length === 0 ? (
280
+ <p className="text-sm text-muted-foreground">None.</p>
281
+ ) : (
282
+ <ul className="max-h-64 space-y-1 overflow-auto text-sm">
283
+ {built.context.unlinked.map((path) => (
284
+ <li key={path}>
285
+ <Link
286
+ to="/page"
287
+ search={{ path }}
288
+ className="break-all font-mono text-xs hover:underline"
289
+ >
290
+ {path}
291
+ </Link>
292
+ </li>
293
+ ))}
294
+ </ul>
295
+ )}
296
+ </Panel>
382
297
 
383
- function Coverage({ label, value, total }: { label: string; value: number; total: number }) {
384
- const pct = total === 0 ? 0 : Math.round((value / total) * 100)
385
- return (
386
- <div>
387
- <div className="mb-1 flex justify-between text-xs">
388
- <span className="text-muted-foreground">{label}</span>
389
- <span className="font-mono">{pct}%</span>
390
- </div>
391
- <div className="h-2 bg-muted">
392
- <div className="h-full bg-foreground" style={{ width: `${pct}%` }} />
393
- </div>
394
- </div>
298
+ <Panel title="Primary keywords" icon={<KeyRound className="size-4" />}>
299
+ <CompetingKeywords keywords={built.context.keywords} />
300
+ </Panel>
301
+ </aside>
302
+ )}
303
+ </section>
304
+ </main>
395
305
  )
396
306
  }
397
307
 
398
- function StatusBadge({ status }: { status: StudioStatus }) {
399
- const cls =
400
- status === 'error'
401
- ? 'border-destructive/40 bg-destructive/10 text-destructive'
402
- : status === 'warning'
403
- ? 'border-amber-500/40 bg-amber-500/10 text-amber-700'
404
- : status === 'suggestion'
405
- ? 'border-blue-500/40 bg-blue-500/10 text-blue-700'
406
- : 'border-emerald-500/40 bg-emerald-500/10 text-emerald-700'
407
- return <span className={`inline-flex border px-2 py-0.5 text-xs ${cls}`}>{status}</span>
408
- }
409
-
410
- function isStatus(value: unknown): value is StatusFilter {
308
+ function FindingCount({ counts }: { counts?: FindingCounts }) {
309
+ if (!counts) return <span className="text-emerald-700">none</span>
411
310
  return (
412
- value === 'all' ||
413
- value === 'error' ||
414
- value === 'warning' ||
415
- value === 'suggestion' ||
416
- value === 'healthy'
311
+ <>
312
+ {counts.errors > 0 && (
313
+ <span className="block text-destructive">{plural(counts.errors, 'error')}</span>
314
+ )}
315
+ {counts.warnings > 0 && (
316
+ <span className="block text-amber-700">{plural(counts.warnings, 'warning')}</span>
317
+ )}
318
+ </>
417
319
  )
418
320
  }
419
321
 
420
- function SortHeader({
421
- label,
422
- active,
423
- onClick,
322
+ function CompetingKeywords({
323
+ keywords,
424
324
  }: {
425
- label: string
426
- active: boolean
427
- onClick(): void
325
+ keywords: Extract<StudioSite, { kind: 'built' }>['context']['keywords']
428
326
  }) {
429
- return (
430
- <button
431
- className={
432
- active
433
- ? 'flex items-center gap-1 bg-muted px-3 py-2 text-foreground'
434
- : 'flex items-center gap-1 bg-muted/50 px-3 py-2 hover:text-foreground'
435
- }
436
- onClick={onClick}
437
- >
438
- {label}
439
- <ChevronsUpDown className="size-3" />
440
- </button>
441
- )
442
- }
443
-
444
- function compareFiles(a: StudioFileSummary, b: StudioFileSummary, sort: SortKey, dir: SortDir) {
445
- const direction = dir === 'asc' ? 1 : -1
446
- const statusOrder: Record<StudioStatus, number> = {
447
- error: 0,
448
- warning: 1,
449
- suggestion: 2,
450
- healthy: 3,
327
+ const competing = keywords.filter(({ pages }) => pages.length > 1)
328
+ if (keywords.length === 0) {
329
+ return <p className="text-sm text-muted-foreground">No page declares a primary keyword.</p>
330
+ }
331
+ if (competing.length === 0) {
332
+ return (
333
+ <p className="text-sm text-muted-foreground">
334
+ {plural(keywords.length, 'primary keyword')}, each declared by one page.
335
+ </p>
336
+ )
451
337
  }
452
- const result =
453
- sort === 'status'
454
- ? statusOrder[a.status] - statusOrder[b.status]
455
- : sort === 'blocks'
456
- ? a.blocks - b.blocks
457
- : sort === 'keywords'
458
- ? keywordScore(a) - keywordScore(b)
459
- : sort === 'findings'
460
- ? findingScore(a) - findingScore(b)
461
- : a.relativePath.localeCompare(b.relativePath)
462
- return (result || a.relativePath.localeCompare(b.relativePath)) * direction
463
- }
464
-
465
- function keywordScore(file: StudioFileSummary): number {
466
- return (
467
- (file.keywords?.primary ? 1 : 0) +
468
- (file.keywords?.secondary?.length ? 1 : 0) +
469
- (file.keywords?.lsi?.length ? 1 : 0)
470
- )
471
- }
472
-
473
- function findingScore(file: StudioFileSummary): number {
474
- return file.findings.errors * 100 + file.findings.warnings * 10 + file.findings.suggestions
475
- }
476
-
477
- function isSortKey(value: unknown): value is SortKey {
478
338
  return (
479
- value === 'document' ||
480
- value === 'status' ||
481
- value === 'blocks' ||
482
- value === 'keywords' ||
483
- value === 'findings'
339
+ <div className="space-y-2 text-sm">
340
+ <p className="text-xs text-muted-foreground">
341
+ {plural(keywords.length, 'primary keyword')}, {competing.length} declared by more than one
342
+ page:
343
+ </p>
344
+ <ul className="max-h-64 space-y-2 overflow-auto">
345
+ {competing.map(({ keyword, locale, pages }) => (
346
+ <li key={`${locale ?? ''}-${keyword}`} className="border bg-muted/30 px-2 py-1.5">
347
+ <p className="font-medium">
348
+ {keyword}
349
+ {locale && <span className="ml-1 text-xs text-muted-foreground">({locale})</span>}
350
+ </p>
351
+ {pages.map((path) => (
352
+ <Link
353
+ key={path}
354
+ to="/page"
355
+ search={{ path }}
356
+ className="block break-all font-mono text-xs text-muted-foreground hover:underline"
357
+ >
358
+ {path}
359
+ </Link>
360
+ ))}
361
+ </li>
362
+ ))}
363
+ </ul>
364
+ </div>
484
365
  )
485
366
  }