@contentbit/studio 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/client/assets/api-BX-WUPtV.js +1 -0
- package/dist/client/assets/document-BOMp4_F5.js +65 -0
- package/dist/client/assets/index-C0ybJ4zQ.js +12 -0
- package/dist/client/assets/routes-ACKdIhYm.js +1 -0
- package/dist/client/assets/styles-DogO4Wcf.css +2 -0
- package/dist/server/assets/{_tanstack-start-manifest_v-BSt6T4tK.js → _tanstack-start-manifest_v-BC1PNuB0.js} +4 -4
- package/dist/server/assets/{document-DlS34LM6.js → document-BB_UYqNL.js} +1 -1
- package/dist/server/assets/document-DSV89Ser.js +4704 -0
- package/dist/server/assets/{empty-plugin-adapters-DKUlnwwl.js → empty-plugin-adapters-De7E1vAI.js} +1 -1
- package/dist/server/assets/{router-734kIJxk.js → router-BJiN6b7L.js} +2 -2
- package/dist/server/assets/{start-q50h9Mc3.js → start-m8EQRpUf.js} +1 -1
- package/dist/server/index.js +475 -126
- package/dist/server/preview.d.ts +2 -2
- package/dist/server/server.js +57 -48
- package/dist/server/types.d.ts +1 -1
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/routes/document.tsx +261 -29
- package/src/server/preview.ts +2 -2
- package/src/server/scan.test.ts +61 -1
- package/src/server/types.ts +1 -1
- package/dist/client/assets/api-DbvlDnoO.js +0 -1
- package/dist/client/assets/document-RcoEgi0r.js +0 -1
- package/dist/client/assets/index-BOeG6kVU.js +0 -12
- package/dist/client/assets/routes-cJNV3NIG.js +0 -1
- package/dist/client/assets/styles-DxZJz8Oi.css +0 -2
- package/dist/server/api.js +0 -47
- package/dist/server/assets/document-G8TsI311.js +0 -299
- package/dist/server/preview.js +0 -19
- package/dist/server/scan.js +0 -214
- package/dist/server/types.js +0 -1
package/dist/server/scan.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { compareContentProjectFindings, createLinkGraphView, createSeoBrief, readContentPageFacts, summarizeContentProjectFindings, } from '@contentbit/core';
|
|
2
|
-
import { loadContentProject } from '@contentbit/project';
|
|
3
|
-
import { basename, relative } from 'node:path';
|
|
4
|
-
import { renderStudioPreview } from './preview.js';
|
|
5
|
-
export async function scanProject(options) {
|
|
6
|
-
const context = await scanContext(options);
|
|
7
|
-
const blockUsage = {};
|
|
8
|
-
let words = 0;
|
|
9
|
-
let blocks = 0;
|
|
10
|
-
let links = 0;
|
|
11
|
-
let missingAlt = 0;
|
|
12
|
-
let withPrimary = 0;
|
|
13
|
-
let withSecondary = 0;
|
|
14
|
-
for (const file of context.summaries) {
|
|
15
|
-
words += file.words;
|
|
16
|
-
blocks += file.blocks;
|
|
17
|
-
links += file.links;
|
|
18
|
-
missingAlt += file.missingAlt;
|
|
19
|
-
if (file.keywords?.primary)
|
|
20
|
-
withPrimary++;
|
|
21
|
-
if ((file.keywords?.secondary?.length ?? 0) > 0)
|
|
22
|
-
withSecondary++;
|
|
23
|
-
for (const [name, count] of Object.entries(file.blockNames)) {
|
|
24
|
-
blockUsage[name] = (blockUsage[name] ?? 0) + count;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const summary = summarize(context.findings);
|
|
28
|
-
return {
|
|
29
|
-
root: options.cwd ?? process.cwd(),
|
|
30
|
-
files: context.summaries,
|
|
31
|
-
summary: {
|
|
32
|
-
files: context.summaries.length,
|
|
33
|
-
errors: summary.errors,
|
|
34
|
-
warnings: summary.warnings,
|
|
35
|
-
suggestions: summary.suggestions,
|
|
36
|
-
words,
|
|
37
|
-
blocks,
|
|
38
|
-
links,
|
|
39
|
-
missingAlt,
|
|
40
|
-
},
|
|
41
|
-
blockUsage,
|
|
42
|
-
keywordCoverage: {
|
|
43
|
-
total: context.summaries.length,
|
|
44
|
-
withPrimary,
|
|
45
|
-
withSecondary,
|
|
46
|
-
},
|
|
47
|
-
...(context.scan.linkGraph ? { linkGraph: context.scan.linkGraph } : {}),
|
|
48
|
-
...(context.scan.seo
|
|
49
|
-
? {
|
|
50
|
-
seo: {
|
|
51
|
-
schemaVersion: context.scan.seo.schemaVersion,
|
|
52
|
-
pages: context.scan.seo.pages.length,
|
|
53
|
-
existing: context.scan.seo.pages.filter((page) => page.source === 'existing').length,
|
|
54
|
-
planned: context.scan.seo.pages.filter((page) => page.source === 'planned').length,
|
|
55
|
-
findings: context.scan.seo.findings.length,
|
|
56
|
-
},
|
|
57
|
-
}
|
|
58
|
-
: {}),
|
|
59
|
-
findings: context.findings,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
export async function scanDocument(options, requestedPath) {
|
|
63
|
-
const context = await scanContext(options);
|
|
64
|
-
const file = findAllowedFile(context, options.cwd ?? process.cwd(), requestedPath);
|
|
65
|
-
if (!file)
|
|
66
|
-
return null;
|
|
67
|
-
const scanned = context.scan.files.find((item) => item.path === file);
|
|
68
|
-
if (!scanned)
|
|
69
|
-
return null;
|
|
70
|
-
const summary = context.summaries.find((item) => item.path === file);
|
|
71
|
-
if (!summary)
|
|
72
|
-
return null;
|
|
73
|
-
const previewHtml = renderStudioPreview(scanned.validation.document, (await options.previewComponents?.()) ?? {}, { includeGenericComponents: options.includeGenericBlocks !== false });
|
|
74
|
-
const page = context.index
|
|
75
|
-
? [...context.index.pages.values()].find((entry) => entry.path === file)
|
|
76
|
-
: undefined;
|
|
77
|
-
const seoPage = context.scan.seo?.pages.find((entry) => entry.path === file);
|
|
78
|
-
const seoBrief = context.scan.seo && seoPage ? createSeoBrief(context.scan.seo, seoPage.id) : undefined;
|
|
79
|
-
return {
|
|
80
|
-
file: summary,
|
|
81
|
-
source: scanned.source,
|
|
82
|
-
frontmatter: scanned.frontmatter,
|
|
83
|
-
stats: scanned.stats,
|
|
84
|
-
findings: context.findings.filter((finding) => finding.file === file),
|
|
85
|
-
linksTo: page ? (page.linkRefs.length > 0 ? page.linkRefs : page.linksTo) : [],
|
|
86
|
-
linkedFrom: page
|
|
87
|
-
? page.linkedFromRefs.length > 0
|
|
88
|
-
? page.linkedFromRefs
|
|
89
|
-
: page.linkedFrom
|
|
90
|
-
: [],
|
|
91
|
-
...(seoBrief ? { seoBrief } : {}),
|
|
92
|
-
previewHtml,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
export async function scanGraph(options) {
|
|
96
|
-
const context = await scanContext(options);
|
|
97
|
-
if (!context.index)
|
|
98
|
-
return { nodes: [], edges: [] };
|
|
99
|
-
const summaryByPath = new Map(context.summaries.map((summary) => [summary.path, summary]));
|
|
100
|
-
const view = createLinkGraphView(context.index, context.scan.linkDiagnostics ?? []);
|
|
101
|
-
const nodes = view.nodes.map((node) => ({
|
|
102
|
-
id: node.id,
|
|
103
|
-
label: node.label,
|
|
104
|
-
path: node.path,
|
|
105
|
-
status: summaryByPath.get(node.path)?.status ?? 'healthy',
|
|
106
|
-
slug: node.slug,
|
|
107
|
-
...(node.key ? { key: node.key } : {}),
|
|
108
|
-
...(node.locale ? { locale: node.locale } : {}),
|
|
109
|
-
}));
|
|
110
|
-
const edges = view.edges;
|
|
111
|
-
return { nodes, edges };
|
|
112
|
-
}
|
|
113
|
-
async function scanContext(options) {
|
|
114
|
-
const cwd = options.cwd ?? process.cwd();
|
|
115
|
-
const project = await loadContentProject({
|
|
116
|
-
cmd: 'studio',
|
|
117
|
-
positionals: options.globs,
|
|
118
|
-
cwd,
|
|
119
|
-
registry: options.registryPath,
|
|
120
|
-
includeGenericBlocks: options.includeGenericBlocks,
|
|
121
|
-
linkOptions: options.linkOptions,
|
|
122
|
-
scan: {
|
|
123
|
-
minSectionWords: options.minSectionWords,
|
|
124
|
-
seoConfig: options.seoConfig,
|
|
125
|
-
seoConfigPath: options.seoConfigPath,
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
const { files, scan } = project;
|
|
129
|
-
const findings = scan.findings
|
|
130
|
-
.map((finding) => findingFromProjectFinding(finding, cwd))
|
|
131
|
-
.sort(compareFindings);
|
|
132
|
-
const summaries = scan.files.map((file) => fileSummary(file.path, cwd, file.frontmatter, file.stats, findings.filter((finding) => finding.file === file.path), options, scan.seo?.pages.find((page) => page.path === file.path)));
|
|
133
|
-
const index = scan.linkIndex;
|
|
134
|
-
findings.sort(compareFindings);
|
|
135
|
-
return { files, scan, findings, summaries, index };
|
|
136
|
-
}
|
|
137
|
-
function findingFromProjectFinding(finding, cwd) {
|
|
138
|
-
return {
|
|
139
|
-
severity: finding.severity,
|
|
140
|
-
source: finding.source,
|
|
141
|
-
code: finding.code,
|
|
142
|
-
file: finding.file,
|
|
143
|
-
relativePath: relativePath(cwd, finding.file),
|
|
144
|
-
...(finding.line !== undefined ? { line: finding.line } : {}),
|
|
145
|
-
...(finding.column !== undefined ? { column: finding.column } : {}),
|
|
146
|
-
message: finding.message,
|
|
147
|
-
...(finding.hint ? { hint: finding.hint } : {}),
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function fileSummary(file, cwd, frontmatter, stats, findings, options, seoPage) {
|
|
151
|
-
const counts = summarize(findings);
|
|
152
|
-
const facts = readContentPageFacts(frontmatter, options.linkOptions);
|
|
153
|
-
return {
|
|
154
|
-
path: file,
|
|
155
|
-
relativePath: relativePath(cwd, file),
|
|
156
|
-
title: titleFor(file, frontmatter, stats),
|
|
157
|
-
...(facts.slug ? { slug: facts.slug } : {}),
|
|
158
|
-
...(facts.key ? { key: facts.key } : {}),
|
|
159
|
-
...(facts.locale ? { locale: facts.locale } : {}),
|
|
160
|
-
...(facts.keywords ? { keywords: facts.keywords } : {}),
|
|
161
|
-
words: stats.length.words,
|
|
162
|
-
readingMinutes: stats.length.readingMinutes,
|
|
163
|
-
blocks: stats.blocks.total,
|
|
164
|
-
blockNames: stats.blocks.byName,
|
|
165
|
-
links: stats.links.total,
|
|
166
|
-
externalLinks: stats.links.external,
|
|
167
|
-
missingAlt: stats.images.missingAlt,
|
|
168
|
-
...(seoPage
|
|
169
|
-
? {
|
|
170
|
-
seo: {
|
|
171
|
-
id: seoPage.id,
|
|
172
|
-
source: seoPage.source,
|
|
173
|
-
...(seoPage.type ? { type: seoPage.type } : {}),
|
|
174
|
-
...(seoPage.intent ? { intent: seoPage.intent } : {}),
|
|
175
|
-
findings: findings.filter((finding) => finding.source === 'seo').length,
|
|
176
|
-
},
|
|
177
|
-
}
|
|
178
|
-
: {}),
|
|
179
|
-
findings: counts,
|
|
180
|
-
status: statusFor(counts),
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function titleFor(file, frontmatter, stats) {
|
|
184
|
-
return stringValue(frontmatter.title) ?? stats.outline[0]?.text ?? basename(file);
|
|
185
|
-
}
|
|
186
|
-
function summarize(findings) {
|
|
187
|
-
return summarizeContentProjectFindings(findings);
|
|
188
|
-
}
|
|
189
|
-
function statusFor(findings) {
|
|
190
|
-
if (findings.errors > 0)
|
|
191
|
-
return 'error';
|
|
192
|
-
if (findings.warnings > 0)
|
|
193
|
-
return 'warning';
|
|
194
|
-
if (findings.suggestions > 0)
|
|
195
|
-
return 'suggestion';
|
|
196
|
-
return 'healthy';
|
|
197
|
-
}
|
|
198
|
-
function findAllowedFile(context, cwd, requestedPath) {
|
|
199
|
-
return (context.files.find((file) => file === requestedPath || relativePath(cwd, file) === requestedPath) ?? null);
|
|
200
|
-
}
|
|
201
|
-
function compareFindings(a, b) {
|
|
202
|
-
return (compareContentProjectFindings(a, b) ||
|
|
203
|
-
a.relativePath.localeCompare(b.relativePath) ||
|
|
204
|
-
(a.line ?? 0) - (b.line ?? 0) ||
|
|
205
|
-
(a.column ?? 0) - (b.column ?? 0) ||
|
|
206
|
-
a.code.localeCompare(b.code));
|
|
207
|
-
}
|
|
208
|
-
function stringValue(value) {
|
|
209
|
-
return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
|
|
210
|
-
}
|
|
211
|
-
function relativePath(cwd, file) {
|
|
212
|
-
const rel = relative(cwd, file);
|
|
213
|
-
return rel.startsWith('..') ? file : rel;
|
|
214
|
-
}
|
package/dist/server/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|