@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.
Files changed (33) hide show
  1. package/dist/client/assets/api-DA8X6vBb.js +1 -0
  2. package/dist/client/assets/document-BJw10sM7.js +65 -0
  3. package/dist/client/assets/{index-DTXIZgkK.js → index-WzJZ-6CK.js} +2 -2
  4. package/dist/client/assets/routes-BWt7eK2V.js +1 -0
  5. package/dist/client/assets/styles-DogO4Wcf.css +2 -0
  6. package/dist/server/assets/{_tanstack-start-manifest_v-wPlN1Hjy.js → _tanstack-start-manifest_v-DyPYRepF.js} +4 -4
  7. package/dist/server/assets/{document-DjmCb_Rp.js → document-BB_UYqNL.js} +1 -1
  8. package/dist/server/assets/document-DSV89Ser.js +4704 -0
  9. package/dist/server/assets/{router-D4DnWGjU.js → router-BJiN6b7L.js} +3 -3
  10. package/dist/server/assets/{routes-BVJt9Z6a.js → routes-FGdym0e5.js} +28 -4
  11. package/dist/server/assets/{routes-6jOjWQ0D.js → routes-p0tk6PAr.js} +1 -1
  12. package/dist/server/index.d.ts.map +1 -1
  13. package/dist/server/index.js +475 -124
  14. package/dist/server/scan.d.ts.map +1 -1
  15. package/dist/server/server.js +2 -2
  16. package/dist/server/types.d.ts +20 -2
  17. package/dist/server/types.d.ts.map +1 -1
  18. package/package.json +6 -5
  19. package/src/routes/document.tsx +272 -1
  20. package/src/routes/index.tsx +21 -1
  21. package/src/server/index.ts +2 -0
  22. package/src/server/scan.test.ts +157 -1
  23. package/src/server/scan.ts +65 -131
  24. package/src/server/types.ts +20 -2
  25. package/dist/client/assets/api-MWiK2l_P.js +0 -1
  26. package/dist/client/assets/document-w62o-wDp.js +0 -1
  27. package/dist/client/assets/routes-Dg9spe-7.js +0 -1
  28. package/dist/client/assets/styles-DxZJz8Oi.css +0 -2
  29. package/dist/server/api.js +0 -47
  30. package/dist/server/assets/document-CxPFBdxd.js +0 -265
  31. package/dist/server/preview.js +0 -19
  32. package/dist/server/scan.js +0 -274
  33. package/dist/server/types.js +0 -1
@@ -1,265 +0,0 @@
1
- import { t as Route } from "./document-DjmCb_Rp.js";
2
- import { i as Button, t as fetchDocument } from "./api-Bqt_atjc.js";
3
- import { useEffect, useState } from "react";
4
- import { Link } from "@tanstack/react-router";
5
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
- import { AlertTriangle, ArrowLeft, BarChart3, Braces, FileCode2, Link2, RefreshCw, Search } from "lucide-react";
7
- //#region src/routes/document.tsx?tsr-split=component
8
- function DocumentDetail() {
9
- const search = Route.useSearch();
10
- const [document, setDocument] = useState(null);
11
- const [error, setError] = useState(null);
12
- const [refreshing, setRefreshing] = useState(false);
13
- async function refresh() {
14
- if (!search.path) {
15
- setError("Missing document path.");
16
- return;
17
- }
18
- setRefreshing(true);
19
- setError(null);
20
- try {
21
- setDocument(await fetchDocument(search.path));
22
- } catch (err) {
23
- setError(err instanceof Error ? err.message : String(err));
24
- } finally {
25
- setRefreshing(false);
26
- }
27
- }
28
- useEffect(() => {
29
- refresh();
30
- }, [search.path]);
31
- return /* @__PURE__ */ jsxs("main", {
32
- className: "min-h-svh bg-background text-foreground",
33
- children: [/* @__PURE__ */ jsx("header", {
34
- className: "border-b bg-muted/30",
35
- children: /* @__PURE__ */ jsxs("div", {
36
- className: "mx-auto flex max-w-7xl flex-col gap-5 px-5 py-5",
37
- children: [/* @__PURE__ */ jsxs("div", {
38
- className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between",
39
- children: [/* @__PURE__ */ jsx(Button, {
40
- asChild: true,
41
- variant: "outline",
42
- className: "w-fit gap-2",
43
- children: /* @__PURE__ */ jsxs(Link, {
44
- to: "/",
45
- search: {
46
- q: "",
47
- status: "all",
48
- sort: "status",
49
- dir: "asc"
50
- },
51
- children: [/* @__PURE__ */ jsx(ArrowLeft, { className: "size-4" }), "Dashboard"]
52
- })
53
- }), /* @__PURE__ */ jsxs(Button, {
54
- onClick: refresh,
55
- disabled: refreshing,
56
- className: "w-fit gap-2",
57
- children: [/* @__PURE__ */ jsx(RefreshCw, { className: refreshing ? "size-4 animate-spin" : "size-4" }), "Refresh"]
58
- })]
59
- }), document ? /* @__PURE__ */ jsxs("div", { children: [
60
- /* @__PURE__ */ jsx("p", {
61
- className: "font-mono text-xs text-muted-foreground",
62
- children: document.file.relativePath
63
- }),
64
- /* @__PURE__ */ jsx("h1", {
65
- className: "mt-1 break-words text-3xl font-semibold tracking-tight",
66
- children: document.file.title
67
- }),
68
- /* @__PURE__ */ jsxs("div", {
69
- className: "mt-3 flex flex-wrap gap-2 text-xs",
70
- children: [
71
- /* @__PURE__ */ jsx(Badge, { children: document.file.status }),
72
- /* @__PURE__ */ jsxs(Badge, { children: [document.file.words, " words"] }),
73
- /* @__PURE__ */ jsxs(Badge, { children: [document.file.blocks, " blocks"] }),
74
- /* @__PURE__ */ jsxs(Badge, { children: [document.file.links, " links"] })
75
- ]
76
- })
77
- ] }) : /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
78
- className: "font-mono text-xs text-muted-foreground",
79
- children: "contentbit studio"
80
- }), /* @__PURE__ */ jsx("h1", {
81
- className: "mt-1 text-3xl font-semibold tracking-tight",
82
- children: "Document detail"
83
- })] })]
84
- })
85
- }), /* @__PURE__ */ jsxs("section", {
86
- className: "mx-auto grid max-w-7xl gap-5 px-5 py-5 xl:grid-cols-[minmax(0,1fr)_360px]",
87
- children: [/* @__PURE__ */ jsxs("div", {
88
- className: "min-w-0 space-y-5",
89
- children: [
90
- error && /* @__PURE__ */ jsx(Panel, {
91
- title: "Error",
92
- icon: /* @__PURE__ */ jsx(AlertTriangle, { className: "size-4" }),
93
- children: error
94
- }),
95
- !document && !error && /* @__PURE__ */ jsx(Panel, {
96
- title: "Loading",
97
- icon: /* @__PURE__ */ jsx(RefreshCw, { className: "size-4" }),
98
- children: "Scanning document..."
99
- }),
100
- document && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Panel, {
101
- title: "Preview",
102
- icon: /* @__PURE__ */ jsx(Search, { className: "size-4" }),
103
- children: /* @__PURE__ */ jsx("div", {
104
- className: "studio-preview",
105
- dangerouslySetInnerHTML: { __html: document.previewHtml }
106
- })
107
- }), /* @__PURE__ */ jsx(Panel, {
108
- title: "Source",
109
- icon: /* @__PURE__ */ jsx(FileCode2, { className: "size-4" }),
110
- children: /* @__PURE__ */ jsx("pre", {
111
- className: "max-h-[34rem] overflow-auto whitespace-pre-wrap break-words bg-muted p-4 font-mono text-xs leading-5",
112
- children: document.source
113
- })
114
- })] })
115
- ]
116
- }), document && /* @__PURE__ */ jsxs("aside", {
117
- className: "space-y-5",
118
- children: [
119
- /* @__PURE__ */ jsx(Panel, {
120
- title: "Stats",
121
- icon: /* @__PURE__ */ jsx(BarChart3, { className: "size-4" }),
122
- children: /* @__PURE__ */ jsx(MetricGrid, { items: [
123
- ["words", document.stats.length.words],
124
- ["reading", `${document.stats.length.readingMinutes} min`],
125
- ["sections", document.stats.outline.length],
126
- ["images", document.stats.images.total],
127
- ["missing alt", document.stats.images.missingAlt],
128
- ["external", document.stats.links.external]
129
- ] })
130
- }),
131
- /* @__PURE__ */ jsxs(Panel, {
132
- title: "Links",
133
- icon: /* @__PURE__ */ jsx(Link2, { className: "size-4" }),
134
- children: [/* @__PURE__ */ jsx(LinkList, {
135
- title: "Outgoing",
136
- items: document.linksTo
137
- }), /* @__PURE__ */ jsx(LinkList, {
138
- title: "Backlinks",
139
- items: document.linkedFrom
140
- })]
141
- }),
142
- /* @__PURE__ */ jsx(Panel, {
143
- title: "Keywords",
144
- icon: /* @__PURE__ */ jsx(Braces, { className: "size-4" }),
145
- children: document.file.keywords ? /* @__PURE__ */ jsxs("div", {
146
- className: "space-y-3 text-sm",
147
- children: [document.file.keywords.primary && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
148
- className: "text-xs uppercase text-muted-foreground",
149
- children: "Primary"
150
- }), /* @__PURE__ */ jsx("p", {
151
- className: "mt-1 font-medium",
152
- children: document.file.keywords.primary
153
- })] }), (document.file.keywords.secondary?.length ?? 0) > 0 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
154
- className: "text-xs uppercase text-muted-foreground",
155
- children: "Secondary"
156
- }), /* @__PURE__ */ jsx("div", {
157
- className: "mt-2 flex flex-wrap gap-1",
158
- children: document.file.keywords.secondary?.map((keyword) => /* @__PURE__ */ jsx(Badge, { children: keyword }, keyword))
159
- })] })]
160
- }) : /* @__PURE__ */ jsx("p", {
161
- className: "text-sm text-muted-foreground",
162
- children: "No keyword frontmatter found."
163
- })
164
- }),
165
- /* @__PURE__ */ jsx(Panel, {
166
- title: "Findings",
167
- icon: /* @__PURE__ */ jsx(AlertTriangle, { className: "size-4" }),
168
- children: document.findings.length > 0 ? /* @__PURE__ */ jsx("ul", {
169
- className: "space-y-3",
170
- children: document.findings.map((finding, index) => /* @__PURE__ */ jsx(FindingItem, { finding }, `${finding.code}-${finding.line ?? 0}-${index}`))
171
- }) : /* @__PURE__ */ jsx("p", {
172
- className: "text-sm text-muted-foreground",
173
- children: "No findings for this document."
174
- })
175
- })
176
- ]
177
- })]
178
- })]
179
- });
180
- }
181
- function Panel({ title, icon, children }) {
182
- return /* @__PURE__ */ jsxs("section", {
183
- className: "border bg-background",
184
- children: [/* @__PURE__ */ jsxs("div", {
185
- className: "flex items-center gap-2 border-b bg-muted/40 px-4 py-3",
186
- children: [icon, /* @__PURE__ */ jsx("h2", {
187
- className: "text-sm font-semibold",
188
- children: title
189
- })]
190
- }), /* @__PURE__ */ jsx("div", {
191
- className: "p-4",
192
- children
193
- })]
194
- });
195
- }
196
- function Badge({ children }) {
197
- return /* @__PURE__ */ jsx("span", {
198
- className: "inline-flex border bg-background px-2 py-0.5 text-xs",
199
- children
200
- });
201
- }
202
- function MetricGrid({ items }) {
203
- return /* @__PURE__ */ jsx("div", {
204
- className: "grid grid-cols-2 gap-px overflow-hidden border bg-border",
205
- children: items.map(([label, value]) => /* @__PURE__ */ jsxs("div", {
206
- className: "bg-background p-3",
207
- children: [/* @__PURE__ */ jsx("div", {
208
- className: "font-mono text-lg font-semibold",
209
- children: value
210
- }), /* @__PURE__ */ jsx("div", {
211
- className: "text-[0.65rem] uppercase text-muted-foreground",
212
- children: label
213
- })]
214
- }, label))
215
- });
216
- }
217
- function LinkList({ title, items }) {
218
- return /* @__PURE__ */ jsxs("div", {
219
- className: "mb-4 last:mb-0",
220
- children: [/* @__PURE__ */ jsx("p", {
221
- className: "mb-2 text-xs uppercase text-muted-foreground",
222
- children: title
223
- }), items.length > 0 ? /* @__PURE__ */ jsx("ul", {
224
- className: "space-y-1 text-sm",
225
- children: items.map((item, index) => /* @__PURE__ */ jsx("li", {
226
- className: "truncate border bg-muted/40 px-2 py-1",
227
- children: linkLabel(item)
228
- }, `${linkLabel(item)}-${index}`))
229
- }) : /* @__PURE__ */ jsx("p", {
230
- className: "text-sm text-muted-foreground",
231
- children: "None"
232
- })]
233
- });
234
- }
235
- function FindingItem({ finding }) {
236
- return /* @__PURE__ */ jsxs("li", {
237
- className: "border bg-muted/30 p-3 text-sm",
238
- children: [
239
- /* @__PURE__ */ jsxs("div", {
240
- className: "flex items-start justify-between gap-3",
241
- children: [/* @__PURE__ */ jsx("span", {
242
- className: `font-medium ${finding.severity === "error" ? "text-destructive" : finding.severity === "warning" ? "text-amber-700" : "text-blue-700"}`,
243
- children: finding.code
244
- }), finding.line && /* @__PURE__ */ jsxs("span", {
245
- className: "font-mono text-xs text-muted-foreground",
246
- children: [":", finding.line]
247
- })]
248
- }),
249
- /* @__PURE__ */ jsx("p", {
250
- className: "mt-1",
251
- children: finding.message
252
- }),
253
- finding.hint && /* @__PURE__ */ jsx("p", {
254
- className: "mt-2 text-xs text-muted-foreground",
255
- children: finding.hint
256
- })
257
- ]
258
- });
259
- }
260
- function linkLabel(item) {
261
- if (typeof item === "string") return item;
262
- return item.target ?? item.key ?? item.slug;
263
- }
264
- //#endregion
265
- export { DocumentDetail as component };
@@ -1,19 +0,0 @@
1
- import { ContentBlocks } from '@contentbit/react';
2
- import { createElement } from 'react';
3
- import { renderToStaticMarkup } from 'react-dom/server';
4
- import ReactMarkdown from 'react-markdown';
5
- import remarkGfm from 'remark-gfm';
6
- export function renderStudioPreview(document, components = {}, _options = {}) {
7
- return renderToStaticMarkup(createElement(ContentBlocks, {
8
- document,
9
- components,
10
- renderMarkdown,
11
- fallback: CustomBlockFallback,
12
- }));
13
- }
14
- function renderMarkdown(markdown) {
15
- return createElement(ReactMarkdown, { remarkPlugins: [remarkGfm] }, markdown);
16
- }
17
- const CustomBlockFallback = ({ name, body }) => createElement('section', { className: 'cb-custom-block', 'data-cb-custom': name }, createElement('div', { className: 'cb-custom-block-label' }, name), createElement('div', { className: 'cb-custom-block-body' }, body.trim().length > 0
18
- ? renderMarkdown(body)
19
- : createElement('p', null, 'No preview component for this custom block yet.')));
@@ -1,274 +0,0 @@
1
- import { genericBlocks } from '@contentbit/blocks';
2
- import { createBlockRegistry, scanContentProject, } from '@contentbit/core';
3
- import { readFile } from 'node:fs/promises';
4
- import { basename, isAbsolute, join, relative } from 'node:path';
5
- import { pathToFileURL } from 'node:url';
6
- import { glob } from 'tinyglobby';
7
- import { renderStudioPreview } from './preview.js';
8
- export async function scanProject(options) {
9
- const context = await scanContext(options);
10
- const blockUsage = {};
11
- let words = 0;
12
- let blocks = 0;
13
- let links = 0;
14
- let missingAlt = 0;
15
- let withPrimary = 0;
16
- let withSecondary = 0;
17
- for (const file of context.summaries) {
18
- words += file.words;
19
- blocks += file.blocks;
20
- links += file.links;
21
- missingAlt += file.missingAlt;
22
- if (file.keywords?.primary)
23
- withPrimary++;
24
- if ((file.keywords?.secondary?.length ?? 0) > 0)
25
- withSecondary++;
26
- for (const [name, count] of Object.entries(file.blockNames)) {
27
- blockUsage[name] = (blockUsage[name] ?? 0) + count;
28
- }
29
- }
30
- const summary = summarize(context.findings);
31
- return {
32
- root: options.cwd ?? process.cwd(),
33
- files: context.summaries,
34
- summary: {
35
- files: context.summaries.length,
36
- errors: summary.errors,
37
- warnings: summary.warnings,
38
- suggestions: summary.suggestions,
39
- words,
40
- blocks,
41
- links,
42
- missingAlt,
43
- },
44
- blockUsage,
45
- keywordCoverage: {
46
- total: context.summaries.length,
47
- withPrimary,
48
- withSecondary,
49
- },
50
- ...(context.scan.linkGraph ? { linkGraph: context.scan.linkGraph } : {}),
51
- findings: context.findings,
52
- };
53
- }
54
- export async function scanDocument(options, requestedPath) {
55
- const context = await scanContext(options);
56
- const file = findAllowedFile(context, options.cwd ?? process.cwd(), requestedPath);
57
- if (!file)
58
- return null;
59
- const scanned = context.scan.files.find((item) => item.path === file);
60
- if (!scanned)
61
- return null;
62
- const summary = context.summaries.find((item) => item.path === file);
63
- if (!summary)
64
- return null;
65
- const previewHtml = renderStudioPreview(scanned.validation.document, (await options.previewComponents?.()) ?? {}, { includeGenericComponents: options.includeGenericBlocks !== false });
66
- const page = context.index
67
- ? [...context.index.pages.values()].find((entry) => entry.path === file)
68
- : undefined;
69
- return {
70
- file: summary,
71
- source: scanned.source,
72
- frontmatter: scanned.frontmatter,
73
- stats: scanned.stats,
74
- findings: context.findings.filter((finding) => finding.file === file),
75
- linksTo: page ? (page.linkRefs.length > 0 ? page.linkRefs : page.linksTo) : [],
76
- linkedFrom: page
77
- ? page.linkedFromRefs.length > 0
78
- ? page.linkedFromRefs
79
- : page.linkedFrom
80
- : [],
81
- previewHtml,
82
- };
83
- }
84
- export async function scanGraph(options) {
85
- const context = await scanContext(options);
86
- if (!context.index)
87
- return { nodes: [], edges: [] };
88
- const summaryByPath = new Map(context.summaries.map((summary) => [summary.path, summary]));
89
- const nodes = [...context.index.pages.values()].map((page) => ({
90
- id: pageIdentity(page),
91
- label: page.title ?? page.slug,
92
- path: page.path,
93
- status: summaryByPath.get(page.path)?.status ?? 'healthy',
94
- slug: page.slug,
95
- ...(page.key ? { key: page.key } : {}),
96
- ...(page.locale ? { locale: page.locale } : {}),
97
- }));
98
- const pageByPath = new Map([...context.index.pages.values()].map((page) => [page.path, page]));
99
- const edges = [];
100
- for (const page of context.index.pages.values()) {
101
- for (const ref of page.linkRefs) {
102
- const target = [...context.index.pages.values()].find((candidate) => candidate.slug === ref.slug &&
103
- candidate.key === ref.key &&
104
- candidate.locale === ref.locale);
105
- edges.push({
106
- from: pageIdentity(page),
107
- to: target ? pageIdentity(target) : undefined,
108
- target: ref.target ?? ref.key ?? ref.slug,
109
- status: target === page
110
- ? 'self'
111
- : ref.locale && ref.locale !== page.locale
112
- ? 'cross-locale'
113
- : 'resolved',
114
- });
115
- }
116
- }
117
- for (const finding of context.findings) {
118
- if (finding.source !== 'links')
119
- continue;
120
- if (finding.code !== 'CB_LINK_UNRESOLVED' && finding.code !== 'CB_LINK_LOCALE_MISSING')
121
- continue;
122
- const page = pageByPath.get(finding.file);
123
- if (!page)
124
- continue;
125
- edges.push({
126
- from: pageIdentity(page),
127
- target: targetFromMessage(finding.message) ?? 'unresolved',
128
- status: 'unresolved',
129
- });
130
- }
131
- return { nodes, edges };
132
- }
133
- async function scanContext(options) {
134
- if (options.globs.length === 0)
135
- throw new Error('studio: provide at least one file or glob.');
136
- const cwd = options.cwd ?? process.cwd();
137
- const files = (await glob(options.globs, { absolute: true, cwd })).sort();
138
- if (files.length === 0)
139
- throw new Error(`studio: no files matched ${options.globs.join(' ')}`);
140
- const registry = await loadStudioRegistry(options.registryPath, cwd, options.includeGenericBlocks);
141
- const sourceFiles = await Promise.all(files.map(async (file) => ({ path: file, source: await readFile(file, 'utf8') })));
142
- const scan = scanContentProject(sourceFiles, registry, {
143
- linkOptions: options.linkOptions,
144
- minSectionWords: options.minSectionWords,
145
- });
146
- const findings = scan.findings
147
- .map((finding) => findingFromProjectFinding(finding, cwd))
148
- .sort(compareFindings);
149
- const summaries = scan.files.map((file) => fileSummary(file.path, cwd, file.frontmatter, file.stats, findings.filter((finding) => finding.file === file.path), options));
150
- const index = scan.linkIndex;
151
- findings.sort(compareFindings);
152
- return { files, scan, findings, summaries, index };
153
- }
154
- async function loadStudioRegistry(registryPath, cwd = process.cwd(), includeGenericBlocks = true) {
155
- const registry = createBlockRegistry();
156
- if (includeGenericBlocks)
157
- registry.use(genericBlocks());
158
- if (!registryPath)
159
- return registry;
160
- const resolvedPath = isAbsolute(registryPath) ? registryPath : join(cwd, registryPath);
161
- const mod = (await import(pathToFileURL(resolvedPath).href));
162
- if (!Array.isArray(mod.default)) {
163
- throw new Error(`--registry module must default-export an array of block definitions: ${resolvedPath}`);
164
- }
165
- registry.use(mod.default);
166
- return registry;
167
- }
168
- function findingFromProjectFinding(finding, cwd) {
169
- return {
170
- severity: finding.severity,
171
- source: finding.source,
172
- code: finding.code,
173
- file: finding.file,
174
- relativePath: relativePath(cwd, finding.file),
175
- ...(finding.line !== undefined ? { line: finding.line } : {}),
176
- ...(finding.column !== undefined ? { column: finding.column } : {}),
177
- message: finding.message,
178
- ...(finding.hint ? { hint: finding.hint } : {}),
179
- };
180
- }
181
- function fileSummary(file, cwd, frontmatter, stats, findings, options) {
182
- const counts = summarize(findings);
183
- const keywords = keywordData(frontmatter.keywords);
184
- const slug = stringValue(frontmatter[options.linkOptions?.slugField ?? 'slug']);
185
- const key = stringValue(frontmatter[options.linkOptions?.keyField ?? 'key']);
186
- const locale = stringValue(frontmatter[options.linkOptions?.localeField ?? 'locale']);
187
- return {
188
- path: file,
189
- relativePath: relativePath(cwd, file),
190
- title: titleFor(file, frontmatter, stats),
191
- ...(slug ? { slug } : {}),
192
- ...(key ? { key } : {}),
193
- ...(locale ? { locale } : {}),
194
- ...(keywords ? { keywords } : {}),
195
- words: stats.length.words,
196
- readingMinutes: stats.length.readingMinutes,
197
- blocks: stats.blocks.total,
198
- blockNames: stats.blocks.byName,
199
- links: stats.links.total,
200
- externalLinks: stats.links.external,
201
- missingAlt: stats.images.missingAlt,
202
- findings: counts,
203
- status: statusFor(counts),
204
- };
205
- }
206
- function titleFor(file, frontmatter, stats) {
207
- return stringValue(frontmatter.title) ?? stats.outline[0]?.text ?? basename(file);
208
- }
209
- function keywordData(value) {
210
- if (!value || typeof value !== 'object')
211
- return undefined;
212
- const record = value;
213
- const primary = stringValue(record.primary);
214
- const secondary = Array.isArray(record.secondary)
215
- ? record.secondary.filter((item) => typeof item === 'string')
216
- : undefined;
217
- return primary || (secondary?.length ?? 0) > 0
218
- ? { ...(primary ? { primary } : {}), ...(secondary ? { secondary } : {}) }
219
- : undefined;
220
- }
221
- function summarize(findings) {
222
- return {
223
- errors: findings.filter((finding) => finding.severity === 'error').length,
224
- warnings: findings.filter((finding) => finding.severity === 'warning').length,
225
- suggestions: findings.filter((finding) => finding.severity === 'info').length,
226
- };
227
- }
228
- function statusFor(findings) {
229
- if (findings.errors > 0)
230
- return 'error';
231
- if (findings.warnings > 0)
232
- return 'warning';
233
- if (findings.suggestions > 0)
234
- return 'suggestion';
235
- return 'healthy';
236
- }
237
- function findAllowedFile(context, cwd, requestedPath) {
238
- return (context.files.find((file) => file === requestedPath || relativePath(cwd, file) === requestedPath) ?? null);
239
- }
240
- function compareFindings(a, b) {
241
- return (rank(a) - rank(b) ||
242
- a.relativePath.localeCompare(b.relativePath) ||
243
- (a.line ?? 0) - (b.line ?? 0) ||
244
- (a.column ?? 0) - (b.column ?? 0) ||
245
- a.code.localeCompare(b.code));
246
- }
247
- function rank(finding) {
248
- if (finding.severity === 'error' && finding.source === 'validation')
249
- return 0;
250
- if (finding.severity === 'error' && finding.source === 'links')
251
- return 1;
252
- if (finding.severity === 'warning')
253
- return 2;
254
- if (finding.code === 'CB_THIN_SECTION')
255
- return 3;
256
- if (finding.code === 'CB_BLOCKLESS_DOCUMENT')
257
- return 4;
258
- if (finding.code === 'CB_IMAGE_ALT_MISSING')
259
- return 5;
260
- return 6;
261
- }
262
- function pageIdentity(page) {
263
- return `${page.locale ?? ''}\0${page.key ?? page.slug}`;
264
- }
265
- function targetFromMessage(message) {
266
- return message.match(/linksTo "([^"]+)"/)?.[1];
267
- }
268
- function stringValue(value) {
269
- return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
270
- }
271
- function relativePath(cwd, file) {
272
- const rel = relative(cwd, file);
273
- return rel.startsWith('..') ? file : rel;
274
- }
@@ -1 +0,0 @@
1
- export {};