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