contentbit 0.2.0 → 0.4.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 +41 -6
- package/dist/bin.js +1115 -74
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +77 -22
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +215 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +62 -8
- package/dist/commands/links.d.ts +3 -0
- package/dist/commands/links.d.ts.map +1 -0
- package/dist/commands/links.js +97 -0
- package/dist/commands/render.d.ts.map +1 -1
- package/dist/commands/render.js +2 -2
- package/dist/commands/studio.d.ts +3 -0
- package/dist/commands/studio.d.ts.map +1 -0
- package/dist/commands/studio.js +76 -0
- package/dist/commands/validate.d.ts.map +1 -1
- package/dist/commands/validate.js +20 -1
- package/dist/link-options.d.ts +10 -0
- package/dist/link-options.d.ts.map +1 -0
- package/dist/link-options.js +31 -0
- package/dist/links-io.d.ts +3 -0
- package/dist/links-io.d.ts.map +1 -0
- package/dist/links-io.js +14 -0
- package/dist/run.d.ts +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +1115 -74
- package/package.json +6 -5
package/dist/run.js
CHANGED
|
@@ -371,12 +371,58 @@ function parseValue(value, indented) {
|
|
|
371
371
|
if (indented.length === 0)
|
|
372
372
|
return null;
|
|
373
373
|
const items = dedent(indented);
|
|
374
|
-
|
|
375
|
-
|
|
374
|
+
const list = parseDashList(items);
|
|
375
|
+
if (list)
|
|
376
|
+
return list;
|
|
377
|
+
const mapping = parseNestedMapping(items);
|
|
378
|
+
if (mapping)
|
|
379
|
+
return mapping;
|
|
376
380
|
return items.join("\n");
|
|
377
381
|
}
|
|
378
382
|
return parseScalar(value);
|
|
379
383
|
}
|
|
384
|
+
function parseNestedMapping(items) {
|
|
385
|
+
const out = {};
|
|
386
|
+
for (const line of items) {
|
|
387
|
+
if (/^[ \t]/.test(line))
|
|
388
|
+
return null;
|
|
389
|
+
const m = line.match(KEY_RE2);
|
|
390
|
+
if (!m)
|
|
391
|
+
return null;
|
|
392
|
+
const [, key, rawValue] = m;
|
|
393
|
+
const v = rawValue.trim();
|
|
394
|
+
if (v === "")
|
|
395
|
+
return null;
|
|
396
|
+
out[key] = parseScalar(v);
|
|
397
|
+
}
|
|
398
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
399
|
+
}
|
|
400
|
+
function parseDashList(items) {
|
|
401
|
+
const groups = [];
|
|
402
|
+
let current = null;
|
|
403
|
+
for (const line of items) {
|
|
404
|
+
if (line.startsWith("- ")) {
|
|
405
|
+
if (current)
|
|
406
|
+
groups.push(current);
|
|
407
|
+
current = [line.slice(2)];
|
|
408
|
+
} else if (current && /^[ \t]/.test(line)) {
|
|
409
|
+
current.push(line);
|
|
410
|
+
} else {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (current)
|
|
415
|
+
groups.push(current);
|
|
416
|
+
return groups.map((group) => parseDashItem(group));
|
|
417
|
+
}
|
|
418
|
+
function parseDashItem(lines) {
|
|
419
|
+
const first = lines[0].trim();
|
|
420
|
+
if (lines.length === 1)
|
|
421
|
+
return parseNestedMapping([first]) ?? parseScalar(first);
|
|
422
|
+
const rest = dedent(lines.slice(1));
|
|
423
|
+
const mapping = parseNestedMapping([first, ...rest]);
|
|
424
|
+
return mapping ?? lines.join("\n");
|
|
425
|
+
}
|
|
380
426
|
function dedent(lines) {
|
|
381
427
|
const indent = Math.min(...lines.map((l) => l.match(/^[ \t]*/)[0].length));
|
|
382
428
|
return lines.map((l) => l.slice(indent));
|
|
@@ -408,6 +454,20 @@ function parseScalar(value) {
|
|
|
408
454
|
return [];
|
|
409
455
|
return splitInlineItems(inner).map((item) => parseScalar(item.trim()));
|
|
410
456
|
}
|
|
457
|
+
if (value.startsWith("{") && value.endsWith("}")) {
|
|
458
|
+
const inner = value.slice(1, -1).trim();
|
|
459
|
+
if (inner === "")
|
|
460
|
+
return {};
|
|
461
|
+
const out = {};
|
|
462
|
+
for (const item of splitInlineItems(inner)) {
|
|
463
|
+
const m = item.trim().match(KEY_RE2);
|
|
464
|
+
if (!m)
|
|
465
|
+
return value;
|
|
466
|
+
const [, key, rawValue] = m;
|
|
467
|
+
out[key] = parseScalar(rawValue.trim());
|
|
468
|
+
}
|
|
469
|
+
return out;
|
|
470
|
+
}
|
|
411
471
|
return value;
|
|
412
472
|
}
|
|
413
473
|
function splitInlineItems(inner) {
|
|
@@ -1096,21 +1156,6 @@ var init_render_markdown = __esm({
|
|
|
1096
1156
|
}
|
|
1097
1157
|
});
|
|
1098
1158
|
|
|
1099
|
-
// ../core/dist/index.js
|
|
1100
|
-
var init_dist = __esm({
|
|
1101
|
-
"../core/dist/index.js"() {
|
|
1102
|
-
"use strict";
|
|
1103
|
-
init_diagnostics();
|
|
1104
|
-
init_parser();
|
|
1105
|
-
init_frontmatter();
|
|
1106
|
-
init_analyze();
|
|
1107
|
-
init_registry();
|
|
1108
|
-
init_content_models();
|
|
1109
|
-
init_validate();
|
|
1110
|
-
init_render_markdown();
|
|
1111
|
-
}
|
|
1112
|
-
});
|
|
1113
|
-
|
|
1114
1159
|
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
|
|
1115
1160
|
// @__NO_SIDE_EFFECTS__
|
|
1116
1161
|
function $constructor(name, initializer3, params) {
|
|
@@ -1175,7 +1220,7 @@ var init_core = __esm({
|
|
|
1175
1220
|
NEVER = /* @__PURE__ */ Object.freeze({
|
|
1176
1221
|
status: "aborted"
|
|
1177
1222
|
});
|
|
1178
|
-
$brand = Symbol("zod_brand");
|
|
1223
|
+
$brand = /* @__PURE__ */ Symbol("zod_brand");
|
|
1179
1224
|
$ZodAsyncError = class extends Error {
|
|
1180
1225
|
constructor() {
|
|
1181
1226
|
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
@@ -11344,8 +11389,8 @@ function registry() {
|
|
|
11344
11389
|
var _a2, $output, $input, $ZodRegistry, globalRegistry;
|
|
11345
11390
|
var init_registries = __esm({
|
|
11346
11391
|
"../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/registries.js"() {
|
|
11347
|
-
$output = Symbol("ZodOutput");
|
|
11348
|
-
$input = Symbol("ZodInput");
|
|
11392
|
+
$output = /* @__PURE__ */ Symbol("ZodOutput");
|
|
11393
|
+
$input = /* @__PURE__ */ Symbol("ZodInput");
|
|
11349
11394
|
$ZodRegistry = class {
|
|
11350
11395
|
constructor() {
|
|
11351
11396
|
this._map = /* @__PURE__ */ new WeakMap();
|
|
@@ -16192,6 +16237,435 @@ var init_zod = __esm({
|
|
|
16192
16237
|
}
|
|
16193
16238
|
});
|
|
16194
16239
|
|
|
16240
|
+
// ../core/dist/links.js
|
|
16241
|
+
function parseLinkFrontmatter(data, options = {}) {
|
|
16242
|
+
const normalized = normalizeFrontmatter(data, options);
|
|
16243
|
+
if (!("slug" in normalized))
|
|
16244
|
+
return { ok: true, value: null };
|
|
16245
|
+
const parsed = LinkFrontmatter.safeParse(normalized);
|
|
16246
|
+
if (parsed.success)
|
|
16247
|
+
return { ok: true, value: parsed.data };
|
|
16248
|
+
return { ok: false, errors: parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`) };
|
|
16249
|
+
}
|
|
16250
|
+
function buildLinkIndex(inputs, options = {}) {
|
|
16251
|
+
const resolvedOptions = { ...DEFAULT_OPTIONS, ...options };
|
|
16252
|
+
const pages = /* @__PURE__ */ new Map();
|
|
16253
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
16254
|
+
const aliasEntries = [];
|
|
16255
|
+
for (const { path, data } of inputs) {
|
|
16256
|
+
const parsed = parseLinkFrontmatter(data, resolvedOptions);
|
|
16257
|
+
if (!parsed.ok || parsed.value === null)
|
|
16258
|
+
continue;
|
|
16259
|
+
const fm = parsed.value;
|
|
16260
|
+
const page = {
|
|
16261
|
+
slug: fm.slug,
|
|
16262
|
+
key: fm.key,
|
|
16263
|
+
locale: effectiveLocale(fm, resolvedOptions),
|
|
16264
|
+
path,
|
|
16265
|
+
title: fm.title,
|
|
16266
|
+
keywords: fm.keywords,
|
|
16267
|
+
linksTo: [],
|
|
16268
|
+
linkedFrom: [],
|
|
16269
|
+
aliases: fm.aliases ?? [],
|
|
16270
|
+
linkRefs: [],
|
|
16271
|
+
linkedFromRefs: []
|
|
16272
|
+
};
|
|
16273
|
+
pages.set(pageMapKey(page, resolvedOptions), page);
|
|
16274
|
+
}
|
|
16275
|
+
for (const page of pages.values()) {
|
|
16276
|
+
for (const alias of page.aliases) {
|
|
16277
|
+
const replacement = replacementFor(page, resolvedOptions);
|
|
16278
|
+
const key = aliasMapKey(alias, page.locale, resolvedOptions);
|
|
16279
|
+
aliases.set(key, replacement);
|
|
16280
|
+
aliasEntries.push({ alias, locale: page.locale, replacement, page });
|
|
16281
|
+
}
|
|
16282
|
+
}
|
|
16283
|
+
const lookup = buildLookup(pages, resolvedOptions);
|
|
16284
|
+
for (const page of pages.values()) {
|
|
16285
|
+
const source = parseLinkFrontmatter(inputForPage(page, inputs, resolvedOptions), resolvedOptions);
|
|
16286
|
+
if (!source.ok || source.value === null)
|
|
16287
|
+
continue;
|
|
16288
|
+
for (const rawTarget of source.value.linksTo ?? []) {
|
|
16289
|
+
const resolved = resolveTarget(rawTarget, page, lookup, resolvedOptions);
|
|
16290
|
+
if (!resolved.page) {
|
|
16291
|
+
page.linksTo.push(resolved.target);
|
|
16292
|
+
continue;
|
|
16293
|
+
}
|
|
16294
|
+
page.linksTo.push(replacementFor(resolved.page, resolvedOptions));
|
|
16295
|
+
page.linkRefs.push(referenceFor(resolved.page, resolved.target));
|
|
16296
|
+
if (resolved.page === page)
|
|
16297
|
+
continue;
|
|
16298
|
+
const from = replacementFor(page, resolvedOptions);
|
|
16299
|
+
if (!resolved.page.linkedFrom.includes(from))
|
|
16300
|
+
resolved.page.linkedFrom.push(from);
|
|
16301
|
+
if (!resolved.page.linkedFromRefs.some((r) => sameReference(r, page))) {
|
|
16302
|
+
resolved.page.linkedFromRefs.push(referenceFor(page));
|
|
16303
|
+
}
|
|
16304
|
+
}
|
|
16305
|
+
}
|
|
16306
|
+
return { pages, aliases, aliasEntries, options: resolvedOptions };
|
|
16307
|
+
}
|
|
16308
|
+
function serializeLinkIndex(index) {
|
|
16309
|
+
const scoped = [...index.pages.values()].some((page) => page.locale || page.key);
|
|
16310
|
+
const pages = [...index.pages.values()].map((p) => {
|
|
16311
|
+
const base = {
|
|
16312
|
+
slug: p.slug,
|
|
16313
|
+
...p.key ? { key: p.key } : {},
|
|
16314
|
+
...p.locale ? { locale: p.locale } : {},
|
|
16315
|
+
path: p.path,
|
|
16316
|
+
...p.title ? { title: p.title } : {},
|
|
16317
|
+
...p.keywords ? { keywords: p.keywords } : {},
|
|
16318
|
+
linksTo: scoped ? p.linkRefs : [...p.linksTo],
|
|
16319
|
+
linkedFrom: scoped ? sortedRefs(p.linkedFromRefs) : [...p.linkedFrom].sort(),
|
|
16320
|
+
aliases: [...p.aliases]
|
|
16321
|
+
};
|
|
16322
|
+
return base;
|
|
16323
|
+
}).sort((a, b) => sortIdentity(a.locale, a.slug).localeCompare(sortIdentity(b.locale, b.slug)));
|
|
16324
|
+
const aliases = {};
|
|
16325
|
+
if (scoped) {
|
|
16326
|
+
for (const entry of [...index.aliasEntries].sort((a, b) => sortIdentity(a.locale, a.alias).localeCompare(sortIdentity(b.locale, b.alias)))) {
|
|
16327
|
+
aliases[aliasMapKey(entry.alias, entry.locale, index.options)] = referenceFor(entry.page);
|
|
16328
|
+
}
|
|
16329
|
+
} else {
|
|
16330
|
+
for (const key of [...index.aliases.keys()].sort())
|
|
16331
|
+
aliases[key] = index.aliases.get(key);
|
|
16332
|
+
}
|
|
16333
|
+
return { pages, aliases };
|
|
16334
|
+
}
|
|
16335
|
+
function aliasReplacementsForPage(index, data) {
|
|
16336
|
+
const parsed = parseLinkFrontmatter(data, index.options);
|
|
16337
|
+
const out = /* @__PURE__ */ new Map();
|
|
16338
|
+
if (!parsed.ok || parsed.value === null)
|
|
16339
|
+
return out;
|
|
16340
|
+
const locale = effectiveLocale(parsed.value, index.options);
|
|
16341
|
+
for (const entry of index.aliasEntries) {
|
|
16342
|
+
if (index.options.resolve === "global-slug" || entry.locale === locale) {
|
|
16343
|
+
out.set(entry.alias, entry.replacement);
|
|
16344
|
+
}
|
|
16345
|
+
}
|
|
16346
|
+
return out;
|
|
16347
|
+
}
|
|
16348
|
+
function validateLinks(inputs, options = {}) {
|
|
16349
|
+
const resolvedOptions = { ...DEFAULT_OPTIONS, ...options };
|
|
16350
|
+
const out = [];
|
|
16351
|
+
const validInputs = [];
|
|
16352
|
+
const seenSlug = /* @__PURE__ */ new Map();
|
|
16353
|
+
const seenKey = /* @__PURE__ */ new Map();
|
|
16354
|
+
const seenAlias = /* @__PURE__ */ new Map();
|
|
16355
|
+
for (const { path, data } of inputs) {
|
|
16356
|
+
const parsed = parseLinkFrontmatter(data, resolvedOptions);
|
|
16357
|
+
if (!parsed.ok) {
|
|
16358
|
+
for (const e of parsed.errors)
|
|
16359
|
+
out.push(diag(path, "CB_LINK_SHAPE", "error", `invalid link frontmatter: ${e}`));
|
|
16360
|
+
continue;
|
|
16361
|
+
}
|
|
16362
|
+
if (parsed.value === null)
|
|
16363
|
+
continue;
|
|
16364
|
+
const fm = parsed.value;
|
|
16365
|
+
const locale = effectiveLocale(fm, resolvedOptions);
|
|
16366
|
+
validInputs.push({ path, fm });
|
|
16367
|
+
const slugKey = scopedKey(fm.slug, locale, resolvedOptions);
|
|
16368
|
+
const prior = seenSlug.get(slugKey);
|
|
16369
|
+
if (prior)
|
|
16370
|
+
out.push(diag(path, "CB_SLUG_DUPLICATE", "error", `slug "${fm.slug}" also used by ${prior}`));
|
|
16371
|
+
else
|
|
16372
|
+
seenSlug.set(slugKey, path);
|
|
16373
|
+
if (usesKeyResolution(resolvedOptions) && !fm.key) {
|
|
16374
|
+
out.push(diag(path, "CB_KEY_MISSING", "error", `page "${fm.slug}" is missing key`));
|
|
16375
|
+
}
|
|
16376
|
+
if (fm.key) {
|
|
16377
|
+
const keyKey = scopedKey(fm.key, locale, resolvedOptions);
|
|
16378
|
+
const priorKey = seenKey.get(keyKey);
|
|
16379
|
+
if (priorKey)
|
|
16380
|
+
out.push(diag(path, "CB_KEY_DUPLICATE", "error", `key "${fm.key}" also used by ${priorKey}`));
|
|
16381
|
+
else
|
|
16382
|
+
seenKey.set(keyKey, path);
|
|
16383
|
+
}
|
|
16384
|
+
for (const alias of fm.aliases ?? []) {
|
|
16385
|
+
const aliasKey = scopedKey(alias, locale, resolvedOptions);
|
|
16386
|
+
if (seenAlias.has(aliasKey))
|
|
16387
|
+
out.push(diag(path, "CB_ALIAS_CONFLICT", "error", `alias "${alias}" already declared by ${seenAlias.get(aliasKey)}`));
|
|
16388
|
+
else
|
|
16389
|
+
seenAlias.set(aliasKey, path);
|
|
16390
|
+
}
|
|
16391
|
+
}
|
|
16392
|
+
const index = buildLinkIndex(inputs, resolvedOptions);
|
|
16393
|
+
const lookup = buildLookup(index.pages, resolvedOptions);
|
|
16394
|
+
for (const { fm } of validInputs) {
|
|
16395
|
+
const page = index.pages.get(pageMapKey(frontmatterIdentity(fm, resolvedOptions), resolvedOptions));
|
|
16396
|
+
if (!page)
|
|
16397
|
+
continue;
|
|
16398
|
+
for (const alias of page.aliases) {
|
|
16399
|
+
if (collidesWithPageIdentity(alias, page.locale, lookup, resolvedOptions))
|
|
16400
|
+
out.push(diag(page.path, "CB_ALIAS_CONFLICT", "error", `alias "${alias}" collides with an existing page identity`));
|
|
16401
|
+
}
|
|
16402
|
+
for (const target of fm.linksTo ?? []) {
|
|
16403
|
+
const resolved = resolveTarget(target, page, lookup, resolvedOptions);
|
|
16404
|
+
if (resolved.page === page) {
|
|
16405
|
+
out.push(diag(page.path, "CB_LINK_SELF", "warning", `page "${page.slug}" links to itself`));
|
|
16406
|
+
continue;
|
|
16407
|
+
}
|
|
16408
|
+
if (resolved.page && resolved.crossLocale) {
|
|
16409
|
+
out.push(diag(page.path, "CB_LINK_CROSS_LOCALE", "warning", `linksTo "${resolved.target}" resolves to locale "${resolved.page.locale}"`));
|
|
16410
|
+
continue;
|
|
16411
|
+
}
|
|
16412
|
+
if (!resolved.page) {
|
|
16413
|
+
if (targetExistsOutsideLocale(resolved.target, page.locale, lookup, resolvedOptions)) {
|
|
16414
|
+
out.push(diag(page.path, "CB_LINK_LOCALE_MISSING", "error", `linksTo "${resolved.target}" exists in another locale but not "${page.locale ?? "default"}"`));
|
|
16415
|
+
continue;
|
|
16416
|
+
}
|
|
16417
|
+
const hint = closest(resolved.target, candidatesFor(page.locale, lookup, resolvedOptions));
|
|
16418
|
+
out.push(diag(page.path, "CB_LINK_UNRESOLVED", "error", `linksTo "${resolved.target}" does not resolve to any page`, hint ? `Did you mean "${hint}"?` : void 0));
|
|
16419
|
+
}
|
|
16420
|
+
}
|
|
16421
|
+
if (page.linkedFrom.length === 0)
|
|
16422
|
+
out.push(diag(page.path, "CB_LINK_ORPHAN", "warning", `page "${page.slug}" has no inbound links`));
|
|
16423
|
+
}
|
|
16424
|
+
return out;
|
|
16425
|
+
}
|
|
16426
|
+
function normalizeFrontmatter(data, options) {
|
|
16427
|
+
const out = { ...data };
|
|
16428
|
+
copyConfiguredField(out, data, options.slugField, "slug");
|
|
16429
|
+
copyConfiguredField(out, data, options.keyField, "key");
|
|
16430
|
+
copyConfiguredField(out, data, options.localeField, "locale");
|
|
16431
|
+
return out;
|
|
16432
|
+
}
|
|
16433
|
+
function copyConfiguredField(out, data, from, to) {
|
|
16434
|
+
if (!from || from === to || !(from in data) || to in out)
|
|
16435
|
+
return;
|
|
16436
|
+
out[to] = data[from];
|
|
16437
|
+
}
|
|
16438
|
+
function effectiveLocale(fm, options) {
|
|
16439
|
+
return fm.locale ?? options.defaultLocale;
|
|
16440
|
+
}
|
|
16441
|
+
function frontmatterIdentity(fm, options) {
|
|
16442
|
+
return { slug: fm.slug, key: fm.key, locale: effectiveLocale(fm, options) };
|
|
16443
|
+
}
|
|
16444
|
+
function pageMapKey(page, options) {
|
|
16445
|
+
if (options.resolve === "global-slug")
|
|
16446
|
+
return page.slug;
|
|
16447
|
+
return scopedKey(page.slug, page.locale, options);
|
|
16448
|
+
}
|
|
16449
|
+
function scopedKey(value, locale, options) {
|
|
16450
|
+
if (options.resolve === "global-slug")
|
|
16451
|
+
return value;
|
|
16452
|
+
return `${locale ?? ""}\0${value}`;
|
|
16453
|
+
}
|
|
16454
|
+
function aliasMapKey(alias, locale, options) {
|
|
16455
|
+
return options.resolve === "global-slug" ? alias : `${locale ?? ""}:${alias}`;
|
|
16456
|
+
}
|
|
16457
|
+
function replacementFor(page, options) {
|
|
16458
|
+
if (options.resolve === "same-locale-key")
|
|
16459
|
+
return page.key ?? page.slug;
|
|
16460
|
+
if (options.resolve === "prefer-same-locale-key-fallback-slug")
|
|
16461
|
+
return page.key ?? page.slug;
|
|
16462
|
+
return page.slug;
|
|
16463
|
+
}
|
|
16464
|
+
function referenceFor(page, target) {
|
|
16465
|
+
return {
|
|
16466
|
+
...target ? { target } : {},
|
|
16467
|
+
...page.locale ? { locale: page.locale } : {},
|
|
16468
|
+
slug: page.slug,
|
|
16469
|
+
...page.key ? { key: page.key } : {}
|
|
16470
|
+
};
|
|
16471
|
+
}
|
|
16472
|
+
function sameReference(ref, page) {
|
|
16473
|
+
return ref.slug === page.slug && ref.locale === page.locale && ref.key === page.key;
|
|
16474
|
+
}
|
|
16475
|
+
function sortedRefs(refs) {
|
|
16476
|
+
return [...refs].sort((a, b) => sortIdentity(a.locale, a.key ?? a.slug).localeCompare(sortIdentity(b.locale, b.key ?? b.slug)));
|
|
16477
|
+
}
|
|
16478
|
+
function sortIdentity(locale, value) {
|
|
16479
|
+
return `${locale ?? ""}\0${value}`;
|
|
16480
|
+
}
|
|
16481
|
+
function buildLookup(pages, options) {
|
|
16482
|
+
const lookup = {
|
|
16483
|
+
bySlug: /* @__PURE__ */ new Map(),
|
|
16484
|
+
byScopedSlug: /* @__PURE__ */ new Map(),
|
|
16485
|
+
byKey: /* @__PURE__ */ new Map(),
|
|
16486
|
+
byScopedKey: /* @__PURE__ */ new Map(),
|
|
16487
|
+
aliasBySlug: /* @__PURE__ */ new Map(),
|
|
16488
|
+
aliasByScopedSlug: /* @__PURE__ */ new Map(),
|
|
16489
|
+
aliasByKey: /* @__PURE__ */ new Map(),
|
|
16490
|
+
aliasByScopedKey: /* @__PURE__ */ new Map()
|
|
16491
|
+
};
|
|
16492
|
+
for (const page of pages.values()) {
|
|
16493
|
+
pushMulti(lookup.bySlug, page.slug, page);
|
|
16494
|
+
lookup.byScopedSlug.set(scopedKey(page.slug, page.locale, options), page);
|
|
16495
|
+
if (page.key) {
|
|
16496
|
+
pushMulti(lookup.byKey, page.key, page);
|
|
16497
|
+
lookup.byScopedKey.set(scopedKey(page.key, page.locale, options), page);
|
|
16498
|
+
}
|
|
16499
|
+
for (const alias of page.aliases) {
|
|
16500
|
+
lookup.aliasBySlug.set(alias, page);
|
|
16501
|
+
lookup.aliasByScopedSlug.set(scopedKey(alias, page.locale, options), page);
|
|
16502
|
+
if (page.key) {
|
|
16503
|
+
lookup.aliasByKey.set(alias, page);
|
|
16504
|
+
lookup.aliasByScopedKey.set(scopedKey(alias, page.locale, options), page);
|
|
16505
|
+
}
|
|
16506
|
+
}
|
|
16507
|
+
}
|
|
16508
|
+
return lookup;
|
|
16509
|
+
}
|
|
16510
|
+
function pushMulti(map2, key, page) {
|
|
16511
|
+
const existing = map2.get(key);
|
|
16512
|
+
if (existing)
|
|
16513
|
+
existing.push(page);
|
|
16514
|
+
else
|
|
16515
|
+
map2.set(key, [page]);
|
|
16516
|
+
}
|
|
16517
|
+
function resolveTarget(rawTarget, source, lookup, options) {
|
|
16518
|
+
if (typeof rawTarget !== "string") {
|
|
16519
|
+
const locale2 = rawTarget.locale ?? source.locale;
|
|
16520
|
+
const page2 = rawTarget.key ? lookup.byScopedKey.get(scopedKey(rawTarget.key, locale2, options)) : rawTarget.slug ? lookup.byScopedSlug.get(scopedKey(rawTarget.slug, locale2, options)) : void 0;
|
|
16521
|
+
const target = rawTarget.key ?? rawTarget.slug ?? "";
|
|
16522
|
+
return {
|
|
16523
|
+
page: page2,
|
|
16524
|
+
target,
|
|
16525
|
+
explicitLocale: rawTarget.locale,
|
|
16526
|
+
crossLocale: Boolean(page2 && rawTarget.locale && rawTarget.locale !== source.locale),
|
|
16527
|
+
matchedBy: rawTarget.key ? "key" : "slug"
|
|
16528
|
+
};
|
|
16529
|
+
}
|
|
16530
|
+
const locale = source.locale;
|
|
16531
|
+
if (options.resolve === "global-slug") {
|
|
16532
|
+
const page2 = lookup.aliasBySlug.get(rawTarget) ?? single(lookup.bySlug.get(rawTarget));
|
|
16533
|
+
return { page: page2, target: rawTarget, crossLocale: false, matchedBy: page2 ? "slug" : void 0 };
|
|
16534
|
+
}
|
|
16535
|
+
if (options.resolve === "same-locale-key") {
|
|
16536
|
+
const scoped2 = scopedKey(rawTarget, locale, options);
|
|
16537
|
+
const page2 = lookup.byScopedKey.get(scoped2) ?? lookup.aliasByScopedKey.get(scoped2);
|
|
16538
|
+
return { page: page2, target: rawTarget, crossLocale: false, matchedBy: page2 ? "key" : void 0 };
|
|
16539
|
+
}
|
|
16540
|
+
if (options.resolve === "prefer-same-locale-key-fallback-slug") {
|
|
16541
|
+
const scoped2 = scopedKey(rawTarget, locale, options);
|
|
16542
|
+
const page2 = lookup.byScopedKey.get(scoped2) ?? lookup.aliasByScopedKey.get(scoped2) ?? lookup.byScopedSlug.get(scoped2) ?? lookup.aliasByScopedSlug.get(scoped2);
|
|
16543
|
+
return { page: page2, target: rawTarget, crossLocale: false, matchedBy: page2 ? "key" : void 0 };
|
|
16544
|
+
}
|
|
16545
|
+
const scoped = scopedKey(rawTarget, locale, options);
|
|
16546
|
+
const page = lookup.byScopedSlug.get(scoped) ?? lookup.aliasByScopedSlug.get(scoped);
|
|
16547
|
+
return { page, target: rawTarget, crossLocale: false, matchedBy: page ? "slug" : void 0 };
|
|
16548
|
+
}
|
|
16549
|
+
function single(values) {
|
|
16550
|
+
return values?.length === 1 ? values[0] : void 0;
|
|
16551
|
+
}
|
|
16552
|
+
function usesKeyResolution(options) {
|
|
16553
|
+
return options.resolve === "same-locale-key";
|
|
16554
|
+
}
|
|
16555
|
+
function collidesWithPageIdentity(alias, locale, lookup, options) {
|
|
16556
|
+
if (options.resolve === "global-slug")
|
|
16557
|
+
return lookup.bySlug.has(alias);
|
|
16558
|
+
const scoped = scopedKey(alias, locale, options);
|
|
16559
|
+
return lookup.byScopedSlug.has(scoped) || usesKeyResolution(options) && lookup.byScopedKey.has(scoped);
|
|
16560
|
+
}
|
|
16561
|
+
function targetExistsOutsideLocale(target, locale, lookup, options) {
|
|
16562
|
+
if (options.resolve === "global-slug")
|
|
16563
|
+
return false;
|
|
16564
|
+
const byIdentity = usesKeyResolution(options) ? lookup.byKey : lookup.bySlug;
|
|
16565
|
+
return (byIdentity.get(target) ?? []).some((page) => page.locale !== locale);
|
|
16566
|
+
}
|
|
16567
|
+
function candidatesFor(locale, lookup, options) {
|
|
16568
|
+
if (options.resolve === "global-slug")
|
|
16569
|
+
return [...lookup.bySlug.keys()];
|
|
16570
|
+
const out = [];
|
|
16571
|
+
for (const page of lookup.byScopedSlug.values()) {
|
|
16572
|
+
if (page.locale === locale)
|
|
16573
|
+
out.push(usesKeyResolution(options) && page.key ? page.key : page.slug);
|
|
16574
|
+
}
|
|
16575
|
+
return out;
|
|
16576
|
+
}
|
|
16577
|
+
function inputForPage(page, inputs, options) {
|
|
16578
|
+
for (const input of inputs) {
|
|
16579
|
+
const parsed = parseLinkFrontmatter(input.data, options);
|
|
16580
|
+
if (!parsed.ok || parsed.value === null)
|
|
16581
|
+
continue;
|
|
16582
|
+
const identity = frontmatterIdentity(parsed.value, options);
|
|
16583
|
+
if (pageMapKey(identity, options) === pageMapKey(page, options))
|
|
16584
|
+
return input.data;
|
|
16585
|
+
}
|
|
16586
|
+
return {};
|
|
16587
|
+
}
|
|
16588
|
+
function diag(file2, code, severity, message, hint) {
|
|
16589
|
+
return { file: file2, diagnostic: { code, severity, message, hint, position: FM_POSITION } };
|
|
16590
|
+
}
|
|
16591
|
+
function editDistance(a, b) {
|
|
16592
|
+
const dp = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
|
|
16593
|
+
for (let j = 0; j <= b.length; j++)
|
|
16594
|
+
dp[0][j] = j;
|
|
16595
|
+
for (let i = 1; i <= a.length; i++) {
|
|
16596
|
+
for (let j = 1; j <= b.length; j++) {
|
|
16597
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
16598
|
+
dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost);
|
|
16599
|
+
}
|
|
16600
|
+
}
|
|
16601
|
+
return dp[a.length][b.length];
|
|
16602
|
+
}
|
|
16603
|
+
function closest(target, candidates) {
|
|
16604
|
+
let best;
|
|
16605
|
+
let bestD = Infinity;
|
|
16606
|
+
for (const c of candidates) {
|
|
16607
|
+
const d = editDistance(target, c);
|
|
16608
|
+
if (d < bestD) {
|
|
16609
|
+
bestD = d;
|
|
16610
|
+
best = c;
|
|
16611
|
+
}
|
|
16612
|
+
}
|
|
16613
|
+
return best && bestD <= Math.max(2, Math.floor(target.length / 3)) ? best : void 0;
|
|
16614
|
+
}
|
|
16615
|
+
var Keywords, LinkTarget, LinkFrontmatter, DEFAULT_OPTIONS, FM_POSITION;
|
|
16616
|
+
var init_links = __esm({
|
|
16617
|
+
"../core/dist/links.js"() {
|
|
16618
|
+
"use strict";
|
|
16619
|
+
init_zod();
|
|
16620
|
+
Keywords = external_exports.object({
|
|
16621
|
+
primary: external_exports.string().optional(),
|
|
16622
|
+
secondary: external_exports.array(external_exports.string()).optional()
|
|
16623
|
+
});
|
|
16624
|
+
LinkTarget = external_exports.union([
|
|
16625
|
+
external_exports.string(),
|
|
16626
|
+
external_exports.object({
|
|
16627
|
+
slug: external_exports.string().min(1).optional(),
|
|
16628
|
+
key: external_exports.string().min(1).optional(),
|
|
16629
|
+
locale: external_exports.string().min(1).optional()
|
|
16630
|
+
}).refine((target) => target.slug || target.key, {
|
|
16631
|
+
message: "object linksTo targets must include slug or key"
|
|
16632
|
+
})
|
|
16633
|
+
]);
|
|
16634
|
+
LinkFrontmatter = external_exports.object({
|
|
16635
|
+
slug: external_exports.string().min(1),
|
|
16636
|
+
key: external_exports.string().min(1).optional(),
|
|
16637
|
+
locale: external_exports.string().min(1).optional(),
|
|
16638
|
+
title: external_exports.string().optional(),
|
|
16639
|
+
linksTo: external_exports.array(LinkTarget).optional(),
|
|
16640
|
+
aliases: external_exports.array(external_exports.string()).optional(),
|
|
16641
|
+
keywords: Keywords.optional()
|
|
16642
|
+
});
|
|
16643
|
+
DEFAULT_OPTIONS = {
|
|
16644
|
+
resolve: "global-slug"
|
|
16645
|
+
};
|
|
16646
|
+
FM_POSITION = {
|
|
16647
|
+
start: { line: 1, column: 1, offset: 0 },
|
|
16648
|
+
end: { line: 1, column: 1, offset: 0 }
|
|
16649
|
+
};
|
|
16650
|
+
}
|
|
16651
|
+
});
|
|
16652
|
+
|
|
16653
|
+
// ../core/dist/index.js
|
|
16654
|
+
var init_dist = __esm({
|
|
16655
|
+
"../core/dist/index.js"() {
|
|
16656
|
+
"use strict";
|
|
16657
|
+
init_diagnostics();
|
|
16658
|
+
init_parser();
|
|
16659
|
+
init_frontmatter();
|
|
16660
|
+
init_analyze();
|
|
16661
|
+
init_registry();
|
|
16662
|
+
init_content_models();
|
|
16663
|
+
init_validate();
|
|
16664
|
+
init_render_markdown();
|
|
16665
|
+
init_links();
|
|
16666
|
+
}
|
|
16667
|
+
});
|
|
16668
|
+
|
|
16195
16669
|
// ../blocks/dist/blocks/callout.js
|
|
16196
16670
|
var calloutBlock, calloutMarkdown;
|
|
16197
16671
|
var init_callout = __esm({
|
|
@@ -16616,7 +17090,7 @@ var TEMPLATE_VERSION, AUTHOR_SKILL, AUDIT_SKILL, AGENTS_MD_BLOCK, START, END;
|
|
|
16616
17090
|
var init_agents = __esm({
|
|
16617
17091
|
"src/commands/agents.ts"() {
|
|
16618
17092
|
"use strict";
|
|
16619
|
-
TEMPLATE_VERSION =
|
|
17093
|
+
TEMPLATE_VERSION = 3;
|
|
16620
17094
|
AUTHOR_SKILL = `---
|
|
16621
17095
|
name: contentbit-author
|
|
16622
17096
|
description: |
|
|
@@ -16639,6 +17113,8 @@ Check \`package.json\` for a \`content:check\` script. It holds the canonical
|
|
|
16639
17113
|
validate invocation for this project: the content glob and, if present, the
|
|
16640
17114
|
\`--registry <path>\` flag pointing at custom block definitions. Reuse both
|
|
16641
17115
|
below. No script? Default to \`content/**/*.md\` with no \`--registry\` flag.
|
|
17116
|
+
If the project has a \`content:links\` script, use it for the internal-link
|
|
17117
|
+
index; otherwise run \`contentbit links <content glob>\` directly.
|
|
16642
17118
|
|
|
16643
17119
|
## The loop
|
|
16644
17120
|
|
|
@@ -16653,7 +17129,19 @@ below. No script? Default to \`content/**/*.md\` with no \`--registry\` flag.
|
|
|
16653
17129
|
|
|
16654
17130
|
2. **Write the document.** Plain Markdown everywhere; blocks only where the
|
|
16655
17131
|
guide's use-when guidance fits. Keep frontmatter consistent with sibling
|
|
16656
|
-
documents in the same folder.
|
|
17132
|
+
documents in the same folder. If sibling documents use \`slug\`, \`linksTo\`,
|
|
17133
|
+
\`aliases\`, or \`keywords\`, run the link index first:
|
|
17134
|
+
|
|
17135
|
+
\`\`\`sh
|
|
17136
|
+
contentbit links <content glob>
|
|
17137
|
+
\`\`\`
|
|
17138
|
+
|
|
17139
|
+
Read \`.contentbit/link-index.json\` to pick existing slugs and related
|
|
17140
|
+
pages. Author only \`slug\`, \`linksTo\`, \`aliases\`, and \`keywords\` in
|
|
17141
|
+
frontmatter; never write derived \`linkedFrom\` into source files. When
|
|
17142
|
+
creating a linked page, include \`keywords.primary\` and
|
|
17143
|
+
\`keywords.secondary\` with search-intent phrases that would help future
|
|
17144
|
+
agents choose this page as a \`linksTo\` target.
|
|
16657
17145
|
|
|
16658
17146
|
3. **Validate and fix until clean:**
|
|
16659
17147
|
|
|
@@ -16663,8 +17151,19 @@ below. No script? Default to \`content/**/*.md\` with no \`--registry\` flag.
|
|
|
16663
17151
|
|
|
16664
17152
|
Diagnostics print to stderr as \`file:line:col severity CODE message\`, often
|
|
16665
17153
|
with a \`hint:\` line suggesting the fix. Exit 0 means clean; exit 1 means
|
|
16666
|
-
errors remain.
|
|
16667
|
-
|
|
17154
|
+
errors remain. If the document has link frontmatter, validate the full
|
|
17155
|
+
content glob so cross-file links are checked against the whole graph. Fix
|
|
17156
|
+
every diagnostic and re-run. Never finish with a failing validate.
|
|
17157
|
+
|
|
17158
|
+
4. **Refresh internal links when present:**
|
|
17159
|
+
|
|
17160
|
+
\`\`\`sh
|
|
17161
|
+
contentbit links <content glob> --fix
|
|
17162
|
+
\`\`\`
|
|
17163
|
+
|
|
17164
|
+
\`--fix\` only rewrites \`linksTo\` values that point at known aliases. It
|
|
17165
|
+
does not invent links, remove aliases, or write backlinks. Re-run validate
|
|
17166
|
+
after it changes files.
|
|
16668
17167
|
|
|
16669
17168
|
## Failure modes
|
|
16670
17169
|
|
|
@@ -16684,33 +17183,48 @@ version: ${TEMPLATE_VERSION}
|
|
|
16684
17183
|
|
|
16685
17184
|
# Auditing contentbit content
|
|
16686
17185
|
|
|
16687
|
-
\`contentbit
|
|
16688
|
-
|
|
17186
|
+
\`contentbit doctor\` is the first audit command. It reads content once, runs
|
|
17187
|
+
block validation, link validation, and document stats, then prints a ranked
|
|
17188
|
+
repair plan. It is read-only: it does not write the link index and never edits
|
|
17189
|
+
source files. \`contentbit stats\` remains useful when you need raw JSON metrics.
|
|
17190
|
+
\`contentbit links\` builds the frontmatter-authored internal-link graph and can
|
|
17191
|
+
heal alias references with \`--fix\`.
|
|
16689
17192
|
|
|
16690
17193
|
## Gather
|
|
16691
17194
|
|
|
16692
|
-
Check \`package.json\` for
|
|
16693
|
-
|
|
17195
|
+
Check \`package.json\` for \`content:doctor\` first. If it exists, run it. If it
|
|
17196
|
+
does not, use \`content:check\` to find this project's content glob and
|
|
17197
|
+
\`--registry\` flag, then run:
|
|
16694
17198
|
|
|
16695
17199
|
\`\`\`sh
|
|
17200
|
+
contentbit doctor "content/**/*.md" [--registry <path>]
|
|
17201
|
+
contentbit doctor "content/**/*.md" [--registry <path>] --json
|
|
16696
17202
|
contentbit stats "content/**/*.md" [--registry <path>]
|
|
17203
|
+
contentbit links "content/**/*.md"
|
|
16697
17204
|
\`\`\`
|
|
16698
17205
|
|
|
16699
|
-
|
|
16700
|
-
|
|
16701
|
-
per-section word counts, \`blocks.byName\` usage counts,
|
|
16702
|
-
a \`validation\` summary (\`errors\`/\`warnings\`).
|
|
17206
|
+
\`doctor --json\` prints a stable report with summary counts and ranked
|
|
17207
|
+
findings. \`stats\` prints per-file metrics: frontmatter data, a heading
|
|
17208
|
+
\`outline\` with per-section word counts, \`blocks.byName\` usage counts,
|
|
17209
|
+
\`links.domains\`, and a \`validation\` summary (\`errors\`/\`warnings\`).
|
|
17210
|
+
\`contentbit links\` writes \`.contentbit/link-index.json\`, whose pages contain
|
|
17211
|
+
\`slug\`, resolved \`linksTo\`, derived \`linkedFrom\`, \`aliases\`, and
|
|
17212
|
+
\`keywords\`.
|
|
16703
17213
|
|
|
16704
17214
|
## Interpret
|
|
16705
17215
|
|
|
16706
|
-
Prioritize findings in
|
|
17216
|
+
Prioritize findings in the order \`doctor\` reports them:
|
|
16707
17217
|
|
|
16708
17218
|
1. **Validation errors and warnings** \u2014 broken content ships broken pages.
|
|
16709
|
-
2. **
|
|
16710
|
-
|
|
17219
|
+
2. **Internal-link errors** \u2014 unresolved links, duplicate slugs, and alias
|
|
17220
|
+
conflicts from \`contentbit links\`.
|
|
17221
|
+
3. **Orphans and self-links** \u2014 link warnings that point to isolated or noisy
|
|
17222
|
+
pages.
|
|
17223
|
+
4. **Thin documents** \u2014 outline sections with very low word counts.
|
|
17224
|
+
5. **Block-less documents** \u2014 \`blocks.byName\` empty where sibling documents
|
|
16711
17225
|
use blocks; structure (steps, callouts, comparisons, faq) may be missing.
|
|
16712
|
-
|
|
16713
|
-
|
|
17226
|
+
6. **Missing or inconsistent frontmatter** compared to sibling documents.
|
|
17227
|
+
7. **Structural imbalance** \u2014 skipped heading levels, single-section walls of text.
|
|
16714
17228
|
|
|
16715
17229
|
## Report
|
|
16716
17230
|
|
|
@@ -16726,21 +17240,36 @@ This project validates Markdown content with contentbit. Documents are plain
|
|
|
16726
17240
|
Markdown plus directive blocks (\`:::name{props} ... :::\`), each with a schema.
|
|
16727
17241
|
The \`content:check\` script in package.json holds the canonical validate
|
|
16728
17242
|
command \u2014 the content glob and the \`--registry\` flag \u2014 reuse its arguments.
|
|
17243
|
+
If the project has a \`content:links\` script, use it to build the internal-link
|
|
17244
|
+
index; otherwise run \`contentbit links <content glob>\`.
|
|
16729
17245
|
|
|
16730
17246
|
When writing or editing content:
|
|
16731
17247
|
|
|
16732
17248
|
1. Fetch the live authoring guide first \u2014 never guess block syntax:
|
|
16733
17249
|
\`contentbit instructions --audience llm [--registry <path>]\`
|
|
16734
17250
|
2. Write plain Markdown; use blocks where the guide's use-when guidance fits.
|
|
16735
|
-
3.
|
|
17251
|
+
3. If sibling documents use \`slug\` / \`linksTo\`, read
|
|
17252
|
+
\`.contentbit/link-index.json\` from \`contentbit links <content glob>\` and
|
|
17253
|
+
author frontmatter links with existing slugs. When creating a linked page,
|
|
17254
|
+
include \`keywords.primary\` and \`keywords.secondary\` with search-intent
|
|
17255
|
+
phrases future agents can use to choose related pages.
|
|
17256
|
+
4. Validate until clean (exit 0): \`contentbit validate <file> [--registry <path>]\`.
|
|
16736
17257
|
Diagnostics print as \`file:line:col severity CODE message\` with fix hints.
|
|
17258
|
+
For link frontmatter, validate the full content glob so cross-file checks run.
|
|
16737
17259
|
|
|
16738
17260
|
When auditing content health:
|
|
16739
17261
|
|
|
16740
|
-
- \`contentbit
|
|
16741
|
-
|
|
16742
|
-
|
|
16743
|
-
|
|
17262
|
+
- \`contentbit doctor "content/**/*.md" [--registry <path>]\` prints a ranked,
|
|
17263
|
+
read-only repair plan: validation issues, link issues, thin sections,
|
|
17264
|
+
block-less long documents, and missing image alt text.
|
|
17265
|
+
- \`contentbit doctor "content/**/*.md" [--registry <path>] --json\` prints the
|
|
17266
|
+
same findings as structured JSON for agents and CI.
|
|
17267
|
+
- \`contentbit stats "content/**/*.md" [--registry <path>]\` prints raw JSON
|
|
17268
|
+
stats: outline word counts, block usage, link domains, and validation
|
|
17269
|
+
error/warning counts.
|
|
17270
|
+
- \`contentbit links "content/**/*.md" [--fix]\` builds
|
|
17271
|
+
\`.contentbit/link-index.json\`, reports dangling links/orphans, and rewrites
|
|
17272
|
+
alias references in \`linksTo\` when \`--fix\` is used.
|
|
16744
17273
|
|
|
16745
17274
|
If \`contentbit\` is unavailable, suggest \`npx contentbit@latest init\` instead
|
|
16746
17275
|
of inventing block syntax.
|
|
@@ -16808,7 +17337,7 @@ import { ContentRenderer } from '@/components/content-blocks/content-renderer'`
|
|
|
16808
17337
|
return `'use client'
|
|
16809
17338
|
|
|
16810
17339
|
import { genericBlocks } from '@contentbit/blocks'
|
|
16811
|
-
import { createBlockRegistry, parseDocument, validateDocument } from '@contentbit/core'
|
|
17340
|
+
import { createBlockRegistry, parseDocument, stripFrontmatter, validateDocument } from '@contentbit/core'
|
|
16812
17341
|
${reactImport}${mdImport}${rendererImport}
|
|
16813
17342
|
// Everything block-related lives in the blocks/ folder: definitions in
|
|
16814
17343
|
// registry.ts (shared with the validate CLI), components in components.tsx.
|
|
@@ -16818,7 +17347,7 @@ import { blockComponents } from '${blocksImport}/components'
|
|
|
16818
17347
|
const registry = createBlockRegistry().use(genericBlocks()).use(customBlocks)
|
|
16819
17348
|
|
|
16820
17349
|
export function Content({ source }: { source: string }) {
|
|
16821
|
-
const result = validateDocument(parseDocument(source), registry)
|
|
17350
|
+
const result = validateDocument(parseDocument(stripFrontmatter(source)), registry)
|
|
16822
17351
|
return (
|
|
16823
17352
|
<${renderer}
|
|
16824
17353
|
document={result.document}
|
|
@@ -16838,14 +17367,14 @@ const renderMarkdown = (md) => mdIt.render(md)` : `// TODO: plug a Markdown libr
|
|
|
16838
17367
|
const renderMarkdown = undefined`;
|
|
16839
17368
|
return `// Render content/example.md to example.html. Run: node scripts/render-example.mjs
|
|
16840
17369
|
import { genericBlocks } from '@contentbit/blocks'
|
|
16841
|
-
import { createBlockRegistry, parseDocument, validateDocument } from '@contentbit/core'
|
|
17370
|
+
import { createBlockRegistry, parseDocument, stripFrontmatter, validateDocument } from '@contentbit/core'
|
|
16842
17371
|
import { renderToHtml } from '@contentbit/html'
|
|
16843
17372
|
import { readFile, writeFile } from 'node:fs/promises'
|
|
16844
17373
|
${wiring}
|
|
16845
17374
|
|
|
16846
17375
|
const source = await readFile('content/example.md', 'utf8')
|
|
16847
17376
|
const registry = createBlockRegistry().use(genericBlocks())
|
|
16848
|
-
const result = validateDocument(parseDocument(source), registry)
|
|
17377
|
+
const result = validateDocument(parseDocument(stripFrontmatter(source)), registry)
|
|
16849
17378
|
const html = renderToHtml(result.document, { renderMarkdown })
|
|
16850
17379
|
await writeFile('example.html', html, 'utf8')
|
|
16851
17380
|
console.log('wrote example.html')
|
|
@@ -17058,7 +17587,8 @@ async function initCommand(args, io) {
|
|
|
17058
17587
|
}
|
|
17059
17588
|
const files = [
|
|
17060
17589
|
["blocks/registry.ts", REGISTRY_TEMPLATE],
|
|
17061
|
-
["content/example.md", EXAMPLE_CONTENT]
|
|
17590
|
+
["content/example.md", EXAMPLE_CONTENT],
|
|
17591
|
+
["content/related.md", RELATED_CONTENT]
|
|
17062
17592
|
];
|
|
17063
17593
|
const layout = detectFramework(cwd, { ...pkg.dependencies, ...pkg.devDependencies });
|
|
17064
17594
|
let styled = false;
|
|
@@ -17112,9 +17642,23 @@ async function initCommand(args, io) {
|
|
|
17112
17642
|
fresh.scripts ??= {};
|
|
17113
17643
|
if (!fresh.scripts["content:check"]) {
|
|
17114
17644
|
fresh.scripts["content:check"] = 'contentbit validate "content/**/*.md" --registry ./blocks/registry.ts';
|
|
17645
|
+
io.stdout("added script: content:check");
|
|
17646
|
+
}
|
|
17647
|
+
if (!fresh.scripts["content:links"]) {
|
|
17648
|
+
fresh.scripts["content:links"] = 'contentbit links "content/**/*.md"';
|
|
17649
|
+
io.stdout("added script: content:links");
|
|
17650
|
+
}
|
|
17651
|
+
if (!fresh.scripts["content:doctor"]) {
|
|
17652
|
+
fresh.scripts["content:doctor"] = 'contentbit doctor "content/**/*.md" --registry ./blocks/registry.ts';
|
|
17653
|
+
io.stdout("added script: content:doctor");
|
|
17654
|
+
}
|
|
17655
|
+
if (!fresh.scripts.studio) {
|
|
17656
|
+
fresh.scripts.studio = 'contentbit studio "content/**/*.md" --registry ./blocks/registry.ts';
|
|
17657
|
+
io.stdout("added script: studio");
|
|
17658
|
+
}
|
|
17659
|
+
if (!pkg.scripts?.["content:check"] || !pkg.scripts?.["content:links"] || !pkg.scripts?.["content:doctor"] || !pkg.scripts?.studio) {
|
|
17115
17660
|
await writeFile2(pkgPath, `${JSON.stringify(fresh, null, 2)}
|
|
17116
17661
|
`, "utf8");
|
|
17117
|
-
io.stdout("added script: content:check");
|
|
17118
17662
|
}
|
|
17119
17663
|
let registry2;
|
|
17120
17664
|
try {
|
|
@@ -17132,7 +17676,10 @@ async function initCommand(args, io) {
|
|
|
17132
17676
|
}
|
|
17133
17677
|
io.stdout("");
|
|
17134
17678
|
io.stdout("Done. Next steps:");
|
|
17135
|
-
io.stdout(` 1.
|
|
17679
|
+
io.stdout(` 1. Browse content locally: ${detectPackageManager(cwd)} run studio`);
|
|
17680
|
+
io.stdout(` Inspect content health: ${detectPackageManager(cwd)} run content:doctor`);
|
|
17681
|
+
io.stdout(` Validate the starter content: ${detectPackageManager(cwd)} run content:check`);
|
|
17682
|
+
io.stdout(` Build the link index: ${detectPackageManager(cwd)} run content:links`);
|
|
17136
17683
|
if (target === "react") {
|
|
17137
17684
|
if (!values["no-page"] && layout.pagePath) {
|
|
17138
17685
|
io.stdout(" 2. Start the dev server and open /example to see the article rendered.");
|
|
@@ -17152,7 +17699,7 @@ async function initCommand(args, io) {
|
|
|
17152
17699
|
io.stdout(" Docs: https://contentbit.dev/docs");
|
|
17153
17700
|
return 0;
|
|
17154
17701
|
}
|
|
17155
|
-
var TARGETS, MD_CHOICES, REGISTRY_TEMPLATE, EXAMPLE_CONTENT, TANSTACK_PAGE, NEXT_PAGE, ASTRO_CONTENT_CONFIG, ASTRO_QUOTE_BLOCK;
|
|
17702
|
+
var TARGETS, MD_CHOICES, REGISTRY_TEMPLATE, EXAMPLE_CONTENT, RELATED_CONTENT, TANSTACK_PAGE, NEXT_PAGE, ASTRO_CONTENT_CONFIG, ASTRO_QUOTE_BLOCK;
|
|
17156
17703
|
var init_init = __esm({
|
|
17157
17704
|
"src/commands/init.ts"() {
|
|
17158
17705
|
"use strict";
|
|
@@ -17194,7 +17741,18 @@ export const quote = defineBlock({
|
|
|
17194
17741
|
|
|
17195
17742
|
export default [quote] satisfies BlockDefinition<unknown>[]
|
|
17196
17743
|
`;
|
|
17197
|
-
EXAMPLE_CONTENT =
|
|
17744
|
+
EXAMPLE_CONTENT = `---
|
|
17745
|
+
slug: hello-content-blocks
|
|
17746
|
+
linksTo:
|
|
17747
|
+
- related-contentbit-workflows
|
|
17748
|
+
aliases:
|
|
17749
|
+
- getting-started-contentbit
|
|
17750
|
+
keywords:
|
|
17751
|
+
primary: validated Markdown blocks
|
|
17752
|
+
secondary: [content workflow, agent writing]
|
|
17753
|
+
---
|
|
17754
|
+
|
|
17755
|
+
# Hello, Content Blocks
|
|
17198
17756
|
|
|
17199
17757
|
Regular Markdown works everywhere. Blocks add validated structure:
|
|
17200
17758
|
|
|
@@ -17215,6 +17773,27 @@ by the \`QuoteBlock\` component, in about twenty lines:
|
|
|
17215
17773
|
The Analytical Engine weaves algebraic patterns just as the Jacquard loom
|
|
17216
17774
|
weaves flowers and leaves.
|
|
17217
17775
|
:::
|
|
17776
|
+
`;
|
|
17777
|
+
RELATED_CONTENT = `---
|
|
17778
|
+
slug: related-contentbit-workflows
|
|
17779
|
+
linksTo:
|
|
17780
|
+
- hello-content-blocks
|
|
17781
|
+
keywords:
|
|
17782
|
+
primary: contentbit workflow
|
|
17783
|
+
secondary: [validation loop, internal links]
|
|
17784
|
+
---
|
|
17785
|
+
|
|
17786
|
+
# Related contentbit workflows
|
|
17787
|
+
|
|
17788
|
+
This supporting page exists to show internal links in frontmatter. The link
|
|
17789
|
+
graph is authored once with \`slug\` and \`linksTo\`, then contentbit derives
|
|
17790
|
+
\`linkedFrom\` in \`.contentbit/link-index.json\`.
|
|
17791
|
+
|
|
17792
|
+
:::callout{type="note"}
|
|
17793
|
+
Run \`contentbit links "content/**/*.md" --fix\` after renaming a page. Alias
|
|
17794
|
+
references in \`linksTo\` are rewritten to the current slug, while \`aliases\`
|
|
17795
|
+
stays as the rename record.
|
|
17796
|
+
:::
|
|
17218
17797
|
`;
|
|
17219
17798
|
TANSTACK_PAGE = `import { createFileRoute } from '@tanstack/react-router'
|
|
17220
17799
|
|
|
@@ -17279,6 +17858,36 @@ const { author, role } = Astro.props
|
|
|
17279
17858
|
}
|
|
17280
17859
|
});
|
|
17281
17860
|
|
|
17861
|
+
// src/link-options.ts
|
|
17862
|
+
function linkResolverOptions(values) {
|
|
17863
|
+
const out = {};
|
|
17864
|
+
const resolve = stringValue(values["link-resolve"]);
|
|
17865
|
+
if (resolve) {
|
|
17866
|
+
if (!isResolveMode(resolve)) throw new Error(`invalid --link-resolve ${resolve}`);
|
|
17867
|
+
out.resolve = resolve;
|
|
17868
|
+
}
|
|
17869
|
+
const localeField = stringValue(values["locale-field"]);
|
|
17870
|
+
const slugField = stringValue(values["slug-field"]);
|
|
17871
|
+
const keyField = stringValue(values["key-field"]);
|
|
17872
|
+
const defaultLocale = stringValue(values["default-locale"]);
|
|
17873
|
+
if (localeField) out.localeField = localeField;
|
|
17874
|
+
if (slugField) out.slugField = slugField;
|
|
17875
|
+
if (keyField) out.keyField = keyField;
|
|
17876
|
+
if (defaultLocale) out.defaultLocale = defaultLocale;
|
|
17877
|
+
return out;
|
|
17878
|
+
}
|
|
17879
|
+
function stringValue(value) {
|
|
17880
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
17881
|
+
}
|
|
17882
|
+
function isResolveMode(value) {
|
|
17883
|
+
return value === "global-slug" || value === "same-locale-slug" || value === "same-locale-key" || value === "prefer-same-locale-key-fallback-slug";
|
|
17884
|
+
}
|
|
17885
|
+
var init_link_options = __esm({
|
|
17886
|
+
"src/link-options.ts"() {
|
|
17887
|
+
"use strict";
|
|
17888
|
+
}
|
|
17889
|
+
});
|
|
17890
|
+
|
|
17282
17891
|
// src/commands/validate.ts
|
|
17283
17892
|
var validate_exports = {};
|
|
17284
17893
|
__export(validate_exports, {
|
|
@@ -17293,7 +17902,12 @@ async function validateCommand(args, io) {
|
|
|
17293
17902
|
allowPositionals: true,
|
|
17294
17903
|
options: {
|
|
17295
17904
|
registry: { type: "string" },
|
|
17296
|
-
"strict-warnings": { type: "boolean", default: false }
|
|
17905
|
+
"strict-warnings": { type: "boolean", default: false },
|
|
17906
|
+
"link-resolve": { type: "string" },
|
|
17907
|
+
"locale-field": { type: "string" },
|
|
17908
|
+
"slug-field": { type: "string" },
|
|
17909
|
+
"key-field": { type: "string" },
|
|
17910
|
+
"default-locale": { type: "string" }
|
|
17297
17911
|
}
|
|
17298
17912
|
});
|
|
17299
17913
|
if (positionals.length === 0) {
|
|
@@ -17306,10 +17920,13 @@ async function validateCommand(args, io) {
|
|
|
17306
17920
|
return 2;
|
|
17307
17921
|
}
|
|
17308
17922
|
const registry2 = await loadRegistry(values.registry);
|
|
17923
|
+
const linkOptions = linkResolverOptions(values);
|
|
17309
17924
|
let errors = 0;
|
|
17310
17925
|
let warnings = 0;
|
|
17926
|
+
const linkInputs = [];
|
|
17311
17927
|
for (const file2 of files.sort()) {
|
|
17312
17928
|
const source = await readFile3(file2, "utf8");
|
|
17929
|
+
linkInputs.push({ path: file2, data: extractFrontmatter(source)?.data ?? {} });
|
|
17313
17930
|
const result = validateDocument(parseDocument(stripFrontmatter(source)), registry2);
|
|
17314
17931
|
for (const d of result.diagnostics) {
|
|
17315
17932
|
io.stderr(formatDiagnostic(d, file2));
|
|
@@ -17317,6 +17934,13 @@ async function validateCommand(args, io) {
|
|
|
17317
17934
|
else if (d.severity === "warning") warnings++;
|
|
17318
17935
|
}
|
|
17319
17936
|
}
|
|
17937
|
+
if (linkInputs.some((i) => "slug" in i.data)) {
|
|
17938
|
+
for (const { file: file2, diagnostic } of validateLinks(linkInputs, linkOptions)) {
|
|
17939
|
+
io.stderr(formatDiagnostic(diagnostic, file2));
|
|
17940
|
+
if (diagnostic.severity === "error") errors++;
|
|
17941
|
+
else if (diagnostic.severity === "warning") warnings++;
|
|
17942
|
+
}
|
|
17943
|
+
}
|
|
17320
17944
|
io.stdout(`${files.length} file(s): ${errors} errors, ${warnings} warnings`);
|
|
17321
17945
|
if (errors > 0) return 1;
|
|
17322
17946
|
if (warnings > 0 && values["strict-warnings"]) return 1;
|
|
@@ -17326,7 +17950,303 @@ var init_validate2 = __esm({
|
|
|
17326
17950
|
"src/commands/validate.ts"() {
|
|
17327
17951
|
"use strict";
|
|
17328
17952
|
init_dist();
|
|
17953
|
+
init_link_options();
|
|
17954
|
+
init_load_registry();
|
|
17955
|
+
}
|
|
17956
|
+
});
|
|
17957
|
+
|
|
17958
|
+
// src/commands/doctor.ts
|
|
17959
|
+
var doctor_exports = {};
|
|
17960
|
+
__export(doctor_exports, {
|
|
17961
|
+
doctorCommand: () => doctorCommand
|
|
17962
|
+
});
|
|
17963
|
+
import { readFile as readFile4 } from "node:fs/promises";
|
|
17964
|
+
import { parseArgs as parseArgs4 } from "node:util";
|
|
17965
|
+
import { glob as glob2 } from "tinyglobby";
|
|
17966
|
+
async function doctorCommand(args, io) {
|
|
17967
|
+
const { values, positionals } = parseArgs4({
|
|
17968
|
+
args,
|
|
17969
|
+
allowPositionals: true,
|
|
17970
|
+
options: {
|
|
17971
|
+
registry: { type: "string" },
|
|
17972
|
+
"strict-warnings": { type: "boolean", default: false },
|
|
17973
|
+
json: { type: "boolean", default: false },
|
|
17974
|
+
"min-section-words": { type: "string" },
|
|
17975
|
+
"link-resolve": { type: "string" },
|
|
17976
|
+
"locale-field": { type: "string" },
|
|
17977
|
+
"slug-field": { type: "string" },
|
|
17978
|
+
"key-field": { type: "string" },
|
|
17979
|
+
"default-locale": { type: "string" }
|
|
17980
|
+
}
|
|
17981
|
+
});
|
|
17982
|
+
if (positionals.length === 0) {
|
|
17983
|
+
io.stderr("doctor: provide at least one file or glob.");
|
|
17984
|
+
return 2;
|
|
17985
|
+
}
|
|
17986
|
+
const minSectionWords = parseMinSectionWords(values["min-section-words"]);
|
|
17987
|
+
if (minSectionWords === null) {
|
|
17988
|
+
io.stderr("doctor: --min-section-words must be a non-negative integer.");
|
|
17989
|
+
return 2;
|
|
17990
|
+
}
|
|
17991
|
+
const files = (await glob2(positionals, { absolute: true })).sort();
|
|
17992
|
+
if (files.length === 0) {
|
|
17993
|
+
io.stderr(`doctor: no files matched ${positionals.join(" ")}`);
|
|
17994
|
+
return 2;
|
|
17995
|
+
}
|
|
17996
|
+
const registry2 = await loadRegistry(values.registry);
|
|
17997
|
+
const linkOptions = linkResolverOptions(values);
|
|
17998
|
+
const findings = [];
|
|
17999
|
+
const linkInputs = [];
|
|
18000
|
+
for (const file2 of files) {
|
|
18001
|
+
const source = await readFile4(file2, "utf8");
|
|
18002
|
+
const frontmatter = extractFrontmatter(source);
|
|
18003
|
+
linkInputs.push({ path: file2, data: frontmatter?.data ?? {} });
|
|
18004
|
+
const validation = validateDocument(parseDocument(stripFrontmatter(source)), registry2);
|
|
18005
|
+
for (const diagnostic of validation.diagnostics) {
|
|
18006
|
+
findings.push(findingFromDiagnostic("validation", file2, diagnostic));
|
|
18007
|
+
}
|
|
18008
|
+
const stats = analyzeDocument(source, { path: file2 });
|
|
18009
|
+
for (const section of stats.outline) {
|
|
18010
|
+
if (section.words < minSectionWords) {
|
|
18011
|
+
findings.push({
|
|
18012
|
+
severity: "info",
|
|
18013
|
+
source: "stats",
|
|
18014
|
+
code: "CB_THIN_SECTION",
|
|
18015
|
+
file: file2,
|
|
18016
|
+
line: section.line,
|
|
18017
|
+
column: 1,
|
|
18018
|
+
message: `section "${section.text}" has ${section.words} words`,
|
|
18019
|
+
hint: `Add detail or merge it with a nearby section. Threshold: ${minSectionWords} words.`
|
|
18020
|
+
});
|
|
18021
|
+
}
|
|
18022
|
+
}
|
|
18023
|
+
if (stats.length.words >= BLOCKLESS_WORDS && stats.blocks.total === 0) {
|
|
18024
|
+
findings.push({
|
|
18025
|
+
severity: "info",
|
|
18026
|
+
source: "stats",
|
|
18027
|
+
code: "CB_BLOCKLESS_DOCUMENT",
|
|
18028
|
+
file: file2,
|
|
18029
|
+
message: `document has ${stats.length.words} words and no structured blocks`,
|
|
18030
|
+
hint: "Consider a callout, steps, comparison, FAQ, or another registered block if it clarifies the page."
|
|
18031
|
+
});
|
|
18032
|
+
}
|
|
18033
|
+
if (stats.images.missingAlt > 0) {
|
|
18034
|
+
findings.push({
|
|
18035
|
+
severity: "info",
|
|
18036
|
+
source: "stats",
|
|
18037
|
+
code: "CB_IMAGE_ALT_MISSING",
|
|
18038
|
+
file: file2,
|
|
18039
|
+
message: `${stats.images.missingAlt} image(s) are missing alt text`,
|
|
18040
|
+
hint: "Add descriptive alt text for meaningful images; use empty alt only for decorative images."
|
|
18041
|
+
});
|
|
18042
|
+
}
|
|
18043
|
+
}
|
|
18044
|
+
let linkGraph;
|
|
18045
|
+
if (hasLinkFrontmatter(linkInputs, linkOptions.slugField)) {
|
|
18046
|
+
for (const { file: file2, diagnostic } of validateLinks(linkInputs, linkOptions)) {
|
|
18047
|
+
findings.push(findingFromDiagnostic("links", file2, diagnostic));
|
|
18048
|
+
}
|
|
18049
|
+
const index = buildLinkIndex(linkInputs, linkOptions);
|
|
18050
|
+
let links = 0;
|
|
18051
|
+
for (const page of index.pages.values()) links += page.linksTo.length;
|
|
18052
|
+
linkGraph = {
|
|
18053
|
+
pages: index.pages.size,
|
|
18054
|
+
links,
|
|
18055
|
+
orphans: [...index.pages.values()].filter((page) => page.linkedFrom.length === 0).length
|
|
18056
|
+
};
|
|
18057
|
+
}
|
|
18058
|
+
findings.sort(compareFindings);
|
|
18059
|
+
const report = {
|
|
18060
|
+
files: files.length,
|
|
18061
|
+
summary: summarize(findings),
|
|
18062
|
+
...linkGraph ? { linkGraph } : {},
|
|
18063
|
+
findings
|
|
18064
|
+
};
|
|
18065
|
+
if (values.json) io.stdout(JSON.stringify(report, null, 2));
|
|
18066
|
+
else io.stdout(formatReport(report, positionals, values.registry, hasAliases(linkInputs)));
|
|
18067
|
+
if (report.summary.errors > 0) return 1;
|
|
18068
|
+
if (report.summary.warnings > 0 && values["strict-warnings"]) return 1;
|
|
18069
|
+
return 0;
|
|
18070
|
+
}
|
|
18071
|
+
function parseMinSectionWords(value) {
|
|
18072
|
+
if (value === void 0) return DEFAULT_MIN_SECTION_WORDS;
|
|
18073
|
+
if (!/^\d+$/.test(value)) return null;
|
|
18074
|
+
return Number(value);
|
|
18075
|
+
}
|
|
18076
|
+
function findingFromDiagnostic(source, file2, diagnostic) {
|
|
18077
|
+
return {
|
|
18078
|
+
severity: diagnostic.severity,
|
|
18079
|
+
source,
|
|
18080
|
+
code: diagnostic.code,
|
|
18081
|
+
file: file2,
|
|
18082
|
+
line: diagnostic.position.start.line,
|
|
18083
|
+
column: diagnostic.position.start.column,
|
|
18084
|
+
message: diagnostic.message,
|
|
18085
|
+
...diagnostic.hint ? { hint: diagnostic.hint } : {}
|
|
18086
|
+
};
|
|
18087
|
+
}
|
|
18088
|
+
function hasLinkFrontmatter(inputs, configuredSlugField) {
|
|
18089
|
+
const slugField = configuredSlugField ?? "slug";
|
|
18090
|
+
return inputs.some((input) => Object.prototype.hasOwnProperty.call(input.data, slugField));
|
|
18091
|
+
}
|
|
18092
|
+
function hasAliases(inputs) {
|
|
18093
|
+
return inputs.some((input) => Array.isArray(input.data.aliases) && input.data.aliases.length > 0);
|
|
18094
|
+
}
|
|
18095
|
+
function summarize(findings) {
|
|
18096
|
+
return {
|
|
18097
|
+
errors: findings.filter((f) => f.severity === "error").length,
|
|
18098
|
+
warnings: findings.filter((f) => f.severity === "warning").length,
|
|
18099
|
+
suggestions: findings.filter((f) => f.severity === "info").length
|
|
18100
|
+
};
|
|
18101
|
+
}
|
|
18102
|
+
function compareFindings(a, b) {
|
|
18103
|
+
return rank(a) - rank(b) || a.file.localeCompare(b.file) || (a.line ?? 0) - (b.line ?? 0) || (a.column ?? 0) - (b.column ?? 0) || a.code.localeCompare(b.code);
|
|
18104
|
+
}
|
|
18105
|
+
function rank(finding) {
|
|
18106
|
+
if (finding.severity === "error" && finding.source === "validation") return 0;
|
|
18107
|
+
if (finding.severity === "error" && finding.source === "links") return 1;
|
|
18108
|
+
if (finding.severity === "warning") return 2;
|
|
18109
|
+
if (finding.code === "CB_THIN_SECTION") return 3;
|
|
18110
|
+
if (finding.code === "CB_BLOCKLESS_DOCUMENT") return 4;
|
|
18111
|
+
if (finding.code === "CB_IMAGE_ALT_MISSING") return 5;
|
|
18112
|
+
return 6;
|
|
18113
|
+
}
|
|
18114
|
+
function formatReport(report, globs, registryPath, aliasFixMayApply) {
|
|
18115
|
+
const lines = [];
|
|
18116
|
+
lines.push("contentbit doctor");
|
|
18117
|
+
lines.push(
|
|
18118
|
+
`${report.files} file(s): ${report.summary.errors} errors, ${report.summary.warnings} warnings, ${report.summary.suggestions} suggestions`
|
|
18119
|
+
);
|
|
18120
|
+
if (report.linkGraph) {
|
|
18121
|
+
lines.push(
|
|
18122
|
+
`${report.linkGraph.pages} linked page(s), ${report.linkGraph.links} link(s), ${report.linkGraph.orphans} orphan(s)`
|
|
18123
|
+
);
|
|
18124
|
+
}
|
|
18125
|
+
lines.push("");
|
|
18126
|
+
if (report.findings.length === 0) {
|
|
18127
|
+
lines.push("No findings. Content looks healthy.");
|
|
18128
|
+
} else {
|
|
18129
|
+
lines.push("Repair plan:");
|
|
18130
|
+
report.findings.forEach((finding, index) => {
|
|
18131
|
+
lines.push(`${index + 1}. ${formatFinding(finding)}`);
|
|
18132
|
+
if (finding.hint) lines.push(` hint: ${finding.hint}`);
|
|
18133
|
+
});
|
|
18134
|
+
}
|
|
18135
|
+
lines.push("");
|
|
18136
|
+
lines.push("Next commands:");
|
|
18137
|
+
lines.push(
|
|
18138
|
+
`- contentbit validate ${formatGlobs(globs)}${registryPath ? ` --registry ${formatArg(registryPath)}` : ""}`
|
|
18139
|
+
);
|
|
18140
|
+
if (report.linkGraph) {
|
|
18141
|
+
lines.push(`- contentbit links ${formatGlobs(globs)}`);
|
|
18142
|
+
if (aliasFixMayApply && report.summary.errors === 0)
|
|
18143
|
+
lines.push(`- contentbit links ${formatGlobs(globs)} --fix`);
|
|
18144
|
+
}
|
|
18145
|
+
lines.push(`- contentbit doctor ${formatGlobs(globs)} --json`);
|
|
18146
|
+
return lines.join("\n");
|
|
18147
|
+
}
|
|
18148
|
+
function formatFinding(finding) {
|
|
18149
|
+
const location = finding.line !== void 0 && finding.column !== void 0 ? `${finding.file}:${finding.line}:${finding.column}` : finding.file;
|
|
18150
|
+
return `[${finding.severity}] ${finding.source} ${finding.code} ${location} - ${finding.message}`;
|
|
18151
|
+
}
|
|
18152
|
+
function formatGlobs(globs) {
|
|
18153
|
+
return globs.map(formatArg).join(" ");
|
|
18154
|
+
}
|
|
18155
|
+
function formatArg(value) {
|
|
18156
|
+
return /\s/.test(value) ? JSON.stringify(value) : value;
|
|
18157
|
+
}
|
|
18158
|
+
var DEFAULT_MIN_SECTION_WORDS, BLOCKLESS_WORDS;
|
|
18159
|
+
var init_doctor = __esm({
|
|
18160
|
+
"src/commands/doctor.ts"() {
|
|
18161
|
+
"use strict";
|
|
18162
|
+
init_dist();
|
|
18163
|
+
init_link_options();
|
|
17329
18164
|
init_load_registry();
|
|
18165
|
+
DEFAULT_MIN_SECTION_WORDS = 25;
|
|
18166
|
+
BLOCKLESS_WORDS = 250;
|
|
18167
|
+
}
|
|
18168
|
+
});
|
|
18169
|
+
|
|
18170
|
+
// src/commands/studio.ts
|
|
18171
|
+
var studio_exports = {};
|
|
18172
|
+
__export(studio_exports, {
|
|
18173
|
+
studioCommand: () => studioCommand
|
|
18174
|
+
});
|
|
18175
|
+
import { parseArgs as parseArgs5 } from "node:util";
|
|
18176
|
+
import { glob as glob3 } from "tinyglobby";
|
|
18177
|
+
async function studioCommand(args, io) {
|
|
18178
|
+
const { values, positionals } = parseArgs5({
|
|
18179
|
+
args,
|
|
18180
|
+
allowPositionals: true,
|
|
18181
|
+
options: {
|
|
18182
|
+
registry: { type: "string" },
|
|
18183
|
+
port: { type: "string" },
|
|
18184
|
+
host: { type: "string" },
|
|
18185
|
+
"no-open": { type: "boolean", default: false },
|
|
18186
|
+
"min-section-words": { type: "string" },
|
|
18187
|
+
"link-resolve": { type: "string" },
|
|
18188
|
+
"locale-field": { type: "string" },
|
|
18189
|
+
"slug-field": { type: "string" },
|
|
18190
|
+
"key-field": { type: "string" },
|
|
18191
|
+
"default-locale": { type: "string" }
|
|
18192
|
+
}
|
|
18193
|
+
});
|
|
18194
|
+
if (positionals.length === 0) {
|
|
18195
|
+
io.stderr("studio: provide at least one file or glob.");
|
|
18196
|
+
return 2;
|
|
18197
|
+
}
|
|
18198
|
+
const port = parsePort(values.port);
|
|
18199
|
+
if (port === null) {
|
|
18200
|
+
io.stderr("studio: --port must be an integer between 0 and 65535.");
|
|
18201
|
+
return 2;
|
|
18202
|
+
}
|
|
18203
|
+
const minSectionWords = parseMinSectionWords2(values["min-section-words"]);
|
|
18204
|
+
if (minSectionWords === null) {
|
|
18205
|
+
io.stderr("studio: --min-section-words must be a non-negative integer.");
|
|
18206
|
+
return 2;
|
|
18207
|
+
}
|
|
18208
|
+
const files = await glob3(positionals, { absolute: true });
|
|
18209
|
+
if (files.length === 0) {
|
|
18210
|
+
io.stderr(`studio: no files matched ${positionals.join(" ")}`);
|
|
18211
|
+
return 2;
|
|
18212
|
+
}
|
|
18213
|
+
const { startStudio } = await import("@contentbit/studio");
|
|
18214
|
+
const server = await startStudio({
|
|
18215
|
+
globs: positionals,
|
|
18216
|
+
registryPath: values.registry,
|
|
18217
|
+
host: values.host,
|
|
18218
|
+
...port !== void 0 ? { port } : {},
|
|
18219
|
+
open: !values["no-open"],
|
|
18220
|
+
linkOptions: linkResolverOptions(values),
|
|
18221
|
+
minSectionWords
|
|
18222
|
+
});
|
|
18223
|
+
io.stdout(`contentbit studio running at ${server.url}`);
|
|
18224
|
+
io.stdout("Press Ctrl+C to stop.");
|
|
18225
|
+
const close = () => {
|
|
18226
|
+
void server.close();
|
|
18227
|
+
};
|
|
18228
|
+
process.once("SIGINT", close);
|
|
18229
|
+
process.once("SIGTERM", close);
|
|
18230
|
+
await server.closed;
|
|
18231
|
+
process.off("SIGINT", close);
|
|
18232
|
+
process.off("SIGTERM", close);
|
|
18233
|
+
return 0;
|
|
18234
|
+
}
|
|
18235
|
+
function parsePort(value) {
|
|
18236
|
+
if (value === void 0) return void 0;
|
|
18237
|
+
if (!/^\d+$/.test(value)) return null;
|
|
18238
|
+
const port = Number(value);
|
|
18239
|
+
return port >= 0 && port <= 65535 ? port : null;
|
|
18240
|
+
}
|
|
18241
|
+
function parseMinSectionWords2(value) {
|
|
18242
|
+
if (value === void 0) return void 0;
|
|
18243
|
+
if (!/^\d+$/.test(value)) return null;
|
|
18244
|
+
return Number(value);
|
|
18245
|
+
}
|
|
18246
|
+
var init_studio = __esm({
|
|
18247
|
+
"src/commands/studio.ts"() {
|
|
18248
|
+
"use strict";
|
|
18249
|
+
init_link_options();
|
|
17330
18250
|
}
|
|
17331
18251
|
});
|
|
17332
18252
|
|
|
@@ -17335,11 +18255,11 @@ var stats_exports = {};
|
|
|
17335
18255
|
__export(stats_exports, {
|
|
17336
18256
|
statsCommand: () => statsCommand
|
|
17337
18257
|
});
|
|
17338
|
-
import { readFile as
|
|
17339
|
-
import { parseArgs as
|
|
17340
|
-
import { glob as
|
|
18258
|
+
import { readFile as readFile5 } from "node:fs/promises";
|
|
18259
|
+
import { parseArgs as parseArgs6 } from "node:util";
|
|
18260
|
+
import { glob as glob4 } from "tinyglobby";
|
|
17341
18261
|
async function fileStats(file2, registry2) {
|
|
17342
|
-
const source = await
|
|
18262
|
+
const source = await readFile5(file2, "utf8");
|
|
17343
18263
|
const stats = analyzeDocument(source, { path: file2 });
|
|
17344
18264
|
if (registry2) {
|
|
17345
18265
|
const result = validateDocument(parseDocument(stripFrontmatter(source)), registry2);
|
|
@@ -17354,7 +18274,7 @@ async function fileStats(file2, registry2) {
|
|
|
17354
18274
|
return stats;
|
|
17355
18275
|
}
|
|
17356
18276
|
async function statsCommand(args, io) {
|
|
17357
|
-
const { values, positionals } =
|
|
18277
|
+
const { values, positionals } = parseArgs6({
|
|
17358
18278
|
args,
|
|
17359
18279
|
allowPositionals: true,
|
|
17360
18280
|
options: {
|
|
@@ -17366,7 +18286,7 @@ async function statsCommand(args, io) {
|
|
|
17366
18286
|
io.stderr("stats: provide at least one file or glob.");
|
|
17367
18287
|
return 2;
|
|
17368
18288
|
}
|
|
17369
|
-
const files = await
|
|
18289
|
+
const files = await glob4(positionals, { absolute: true });
|
|
17370
18290
|
if (files.length === 0) {
|
|
17371
18291
|
io.stderr(`stats: no files matched ${positionals.join(" ")}`);
|
|
17372
18292
|
return 2;
|
|
@@ -17524,10 +18444,10 @@ var render_exports = {};
|
|
|
17524
18444
|
__export(render_exports, {
|
|
17525
18445
|
renderCommand: () => renderCommand
|
|
17526
18446
|
});
|
|
17527
|
-
import { readFile as
|
|
17528
|
-
import { parseArgs as
|
|
18447
|
+
import { readFile as readFile6 } from "node:fs/promises";
|
|
18448
|
+
import { parseArgs as parseArgs7 } from "node:util";
|
|
17529
18449
|
async function renderCommand(args, io) {
|
|
17530
|
-
const { values, positionals } =
|
|
18450
|
+
const { values, positionals } = parseArgs7({
|
|
17531
18451
|
args,
|
|
17532
18452
|
allowPositionals: true,
|
|
17533
18453
|
options: {
|
|
@@ -17542,8 +18462,8 @@ async function renderCommand(args, io) {
|
|
|
17542
18462
|
return 2;
|
|
17543
18463
|
}
|
|
17544
18464
|
const registry2 = await loadRegistry(values.registry);
|
|
17545
|
-
const source = await
|
|
17546
|
-
const result = validateDocument(parseDocument(source), registry2);
|
|
18465
|
+
const source = await readFile6(file2, "utf8");
|
|
18466
|
+
const result = validateDocument(parseDocument(stripFrontmatter(source)), registry2);
|
|
17547
18467
|
if (!result.ok) {
|
|
17548
18468
|
for (const d of result.diagnostics) io.stderr(formatDiagnostic(d, file2));
|
|
17549
18469
|
return 1;
|
|
@@ -17568,9 +18488,9 @@ var instructions_exports = {};
|
|
|
17568
18488
|
__export(instructions_exports, {
|
|
17569
18489
|
instructionsCommand: () => instructionsCommand
|
|
17570
18490
|
});
|
|
17571
|
-
import { parseArgs as
|
|
18491
|
+
import { parseArgs as parseArgs8 } from "node:util";
|
|
17572
18492
|
async function instructionsCommand(args, io) {
|
|
17573
|
-
const { values } =
|
|
18493
|
+
const { values } = parseArgs8({
|
|
17574
18494
|
args,
|
|
17575
18495
|
options: {
|
|
17576
18496
|
audience: { type: "string", default: "llm" },
|
|
@@ -17600,9 +18520,9 @@ var docs_exports = {};
|
|
|
17600
18520
|
__export(docs_exports, {
|
|
17601
18521
|
docsCommand: () => docsCommand
|
|
17602
18522
|
});
|
|
17603
|
-
import { parseArgs as
|
|
18523
|
+
import { parseArgs as parseArgs9 } from "node:util";
|
|
17604
18524
|
async function docsCommand(args, io) {
|
|
17605
|
-
const { values } =
|
|
18525
|
+
const { values } = parseArgs9({
|
|
17606
18526
|
args,
|
|
17607
18527
|
options: {
|
|
17608
18528
|
registry: { type: "string" },
|
|
@@ -17622,25 +18542,146 @@ var init_docs = __esm({
|
|
|
17622
18542
|
}
|
|
17623
18543
|
});
|
|
17624
18544
|
|
|
18545
|
+
// src/links-io.ts
|
|
18546
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
18547
|
+
async function collectLinkInputs(files) {
|
|
18548
|
+
const inputs = [];
|
|
18549
|
+
for (const path of files) {
|
|
18550
|
+
const source = await readFile7(path, "utf8");
|
|
18551
|
+
const fm = extractFrontmatter(source);
|
|
18552
|
+
inputs.push({ path, data: fm?.data ?? {} });
|
|
18553
|
+
}
|
|
18554
|
+
return inputs;
|
|
18555
|
+
}
|
|
18556
|
+
var init_links_io = __esm({
|
|
18557
|
+
"src/links-io.ts"() {
|
|
18558
|
+
"use strict";
|
|
18559
|
+
init_dist();
|
|
18560
|
+
}
|
|
18561
|
+
});
|
|
18562
|
+
|
|
18563
|
+
// src/commands/links.ts
|
|
18564
|
+
var links_exports = {};
|
|
18565
|
+
__export(links_exports, {
|
|
18566
|
+
linksCommand: () => linksCommand
|
|
18567
|
+
});
|
|
18568
|
+
import { mkdir as mkdir3, readFile as readFile8 } from "node:fs/promises";
|
|
18569
|
+
import { dirname, join as join3 } from "node:path";
|
|
18570
|
+
import { parseArgs as parseArgs10 } from "node:util";
|
|
18571
|
+
import { glob as glob5 } from "tinyglobby";
|
|
18572
|
+
async function linksCommand(args, io) {
|
|
18573
|
+
const { values, positionals } = parseArgs10({
|
|
18574
|
+
args,
|
|
18575
|
+
allowPositionals: true,
|
|
18576
|
+
options: {
|
|
18577
|
+
out: { type: "string" },
|
|
18578
|
+
fix: { type: "boolean", default: false },
|
|
18579
|
+
"link-resolve": { type: "string" },
|
|
18580
|
+
"locale-field": { type: "string" },
|
|
18581
|
+
"slug-field": { type: "string" },
|
|
18582
|
+
"key-field": { type: "string" },
|
|
18583
|
+
"default-locale": { type: "string" }
|
|
18584
|
+
}
|
|
18585
|
+
});
|
|
18586
|
+
if (positionals.length === 0) {
|
|
18587
|
+
io.stderr("links: provide at least one file or glob.");
|
|
18588
|
+
return 2;
|
|
18589
|
+
}
|
|
18590
|
+
const files = (await glob5(positionals, { absolute: true })).sort();
|
|
18591
|
+
if (files.length === 0) {
|
|
18592
|
+
io.stderr(`links: no files matched ${positionals.join(" ")}`);
|
|
18593
|
+
return 2;
|
|
18594
|
+
}
|
|
18595
|
+
const inputs = await collectLinkInputs(files);
|
|
18596
|
+
const linkOptions = linkResolverOptions(values);
|
|
18597
|
+
let errors = 0;
|
|
18598
|
+
let warnings = 0;
|
|
18599
|
+
for (const { file: file2, diagnostic } of validateLinks(inputs, linkOptions)) {
|
|
18600
|
+
io.stderr(formatDiagnostic(diagnostic, file2));
|
|
18601
|
+
if (diagnostic.severity === "error") errors++;
|
|
18602
|
+
else if (diagnostic.severity === "warning") warnings++;
|
|
18603
|
+
}
|
|
18604
|
+
const index = buildLinkIndex(inputs, linkOptions);
|
|
18605
|
+
if (values.fix && errors > 0) {
|
|
18606
|
+
io.stderr("links: --fix skipped because link errors must be resolved first.");
|
|
18607
|
+
} else if (values.fix && index.aliases.size > 0) {
|
|
18608
|
+
for (const file2 of files) {
|
|
18609
|
+
const source = await readFile8(file2, "utf8");
|
|
18610
|
+
const fm = extractFrontmatter(source);
|
|
18611
|
+
if (!fm) continue;
|
|
18612
|
+
const lines = source.split("\n");
|
|
18613
|
+
let changed = false;
|
|
18614
|
+
let inLinksTo = false;
|
|
18615
|
+
for (let i = 0; i < fm.lines.end && i < lines.length; i++) {
|
|
18616
|
+
const line = lines[i];
|
|
18617
|
+
const topKey = line.match(/^([A-Za-z0-9_.-]+):(.*)$/);
|
|
18618
|
+
if (topKey) inLinksTo = topKey[1] === "linksTo";
|
|
18619
|
+
if (!inLinksTo) continue;
|
|
18620
|
+
let next = line;
|
|
18621
|
+
for (const [alias, current] of aliasReplacementsForPage(index, fm.data)) {
|
|
18622
|
+
const re = new RegExp(`(^|[\\s\\[,'"-])${escapeRe(alias)}($|[\\s\\],'"])`, "g");
|
|
18623
|
+
next = next.replace(re, (_m, p1, p2) => `${p1}${current}${p2}`);
|
|
18624
|
+
}
|
|
18625
|
+
if (next !== line) {
|
|
18626
|
+
lines[i] = next;
|
|
18627
|
+
changed = true;
|
|
18628
|
+
}
|
|
18629
|
+
}
|
|
18630
|
+
if (changed) {
|
|
18631
|
+
await io.writeFile(file2, lines.join("\n"));
|
|
18632
|
+
io.stdout(`fixed alias references in ${file2}`);
|
|
18633
|
+
}
|
|
18634
|
+
}
|
|
18635
|
+
}
|
|
18636
|
+
const outPath = values.out ?? join3(process.cwd(), ".contentbit", "link-index.json");
|
|
18637
|
+
await mkdir3(dirname(outPath), { recursive: true });
|
|
18638
|
+
await io.writeFile(outPath, JSON.stringify(serializeLinkIndex(index), null, 2) + "\n");
|
|
18639
|
+
let edges = 0;
|
|
18640
|
+
for (const p of index.pages.values()) edges += p.linksTo.length;
|
|
18641
|
+
const orphans = [...index.pages.values()].filter((p) => p.linkedFrom.length === 0).length;
|
|
18642
|
+
io.stdout(
|
|
18643
|
+
`${index.pages.size} page(s), ${edges} link(s), ${orphans} orphan(s): ${errors} errors, ${warnings} warnings`
|
|
18644
|
+
);
|
|
18645
|
+
io.stdout(`index written to ${outPath}`);
|
|
18646
|
+
return errors > 0 ? 1 : 0;
|
|
18647
|
+
}
|
|
18648
|
+
function escapeRe(s) {
|
|
18649
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
18650
|
+
}
|
|
18651
|
+
var init_links2 = __esm({
|
|
18652
|
+
"src/commands/links.ts"() {
|
|
18653
|
+
"use strict";
|
|
18654
|
+
init_dist();
|
|
18655
|
+
init_link_options();
|
|
18656
|
+
init_links_io();
|
|
18657
|
+
}
|
|
18658
|
+
});
|
|
18659
|
+
|
|
17625
18660
|
// src/run.ts
|
|
17626
|
-
var USAGE = `Usage: contentbit <init|validate|stats|render|instructions|docs|agents> [options]
|
|
18661
|
+
var USAGE = `Usage: contentbit <init|validate|doctor|studio|stats|render|instructions|docs|agents|links> [options]
|
|
17627
18662
|
|
|
17628
18663
|
init [-t react|html|markdown|astro] [--md ...] [-y] [--no-install] [--no-page] [--no-agents]
|
|
17629
18664
|
agents [--claude] [--no-agents-md]
|
|
17630
18665
|
|
|
17631
|
-
validate <globs...> [--registry <module.
|
|
17632
|
-
|
|
17633
|
-
|
|
17634
|
-
|
|
17635
|
-
|
|
18666
|
+
validate <globs...> [--registry <module.ts>] [--strict-warnings] [--link-resolve <mode>]
|
|
18667
|
+
doctor <globs...> [--registry <module.ts>] [--strict-warnings] [--json] [--min-section-words <n>] [--link-resolve <mode>]
|
|
18668
|
+
studio <globs...> [--registry <module.ts>] [--port <n>] [--host <host>] [--no-open] [--link-resolve <mode>]
|
|
18669
|
+
stats <globs...> [--registry <module.ts>] [--no-validate]
|
|
18670
|
+
render <file> --target html|markdown [--registry <module.ts>] [--out <file>]
|
|
18671
|
+
instructions [--audience llm|human] [--no-examples] [--registry <module.ts>] [--out <file>]
|
|
18672
|
+
docs [--registry <module.ts>] [--out <file>]
|
|
18673
|
+
links <globs...> [--fix] [--out <file>] [--link-resolve <mode>]`;
|
|
17636
18674
|
var commands = {
|
|
17637
18675
|
init: async () => (await Promise.resolve().then(() => (init_init(), init_exports))).initCommand,
|
|
17638
18676
|
validate: async () => (await Promise.resolve().then(() => (init_validate2(), validate_exports))).validateCommand,
|
|
18677
|
+
doctor: async () => (await Promise.resolve().then(() => (init_doctor(), doctor_exports))).doctorCommand,
|
|
18678
|
+
studio: async () => (await Promise.resolve().then(() => (init_studio(), studio_exports))).studioCommand,
|
|
17639
18679
|
stats: async () => (await Promise.resolve().then(() => (init_stats(), stats_exports))).statsCommand,
|
|
17640
18680
|
render: async () => (await Promise.resolve().then(() => (init_render2(), render_exports))).renderCommand,
|
|
17641
18681
|
instructions: async () => (await Promise.resolve().then(() => (init_instructions(), instructions_exports))).instructionsCommand,
|
|
17642
18682
|
docs: async () => (await Promise.resolve().then(() => (init_docs(), docs_exports))).docsCommand,
|
|
17643
|
-
agents: async () => (await Promise.resolve().then(() => (init_agents(), agents_exports))).agentsCommand
|
|
18683
|
+
agents: async () => (await Promise.resolve().then(() => (init_agents(), agents_exports))).agentsCommand,
|
|
18684
|
+
links: async () => (await Promise.resolve().then(() => (init_links2(), links_exports))).linksCommand
|
|
17644
18685
|
};
|
|
17645
18686
|
async function run(argv, io) {
|
|
17646
18687
|
const [name, ...rest] = argv;
|