@takazudo/zudo-doc 5.14.0 → 5.16.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/CHANGELOG.md +40 -0
- package/dist/asset-components/asset-card.js +3 -1
- package/dist/asset-components/asset-code.js +2 -0
- package/dist/asset-components/shared.d.ts +5 -0
- package/dist/asset-components/shared.js +7 -0
- package/dist/asset-index-page/index.d.ts +1 -0
- package/dist/asset-index-page/index.js +10 -9
- package/dist/asset-page/index.d.ts +20 -2
- package/dist/asset-page/index.js +43 -24
- package/dist/asset-path/index.d.ts +2 -0
- package/dist/asset-path/index.js +11 -1
- package/dist/chrome/derive.js +31 -6
- package/dist/compiled.css +12 -0
- package/dist/config.d.ts +15 -6
- package/dist/config.js +2 -0
- package/dist/content/content-link.d.ts +5 -1
- package/dist/content/content-link.js +4 -1
- package/dist/doc-content-header/index.js +1 -1
- package/dist/doc-page-shell/index.js +1 -1
- package/dist/factory-context/index.d.ts +7 -3
- package/dist/header-with-defaults/index.js +2 -0
- package/dist/home-page/index.js +1 -1
- package/dist/html-preview-wrapper/html-preview-wrapper.d.ts +41 -7
- package/dist/html-preview-wrapper/html-preview-wrapper.js +86 -2
- package/dist/html-preview-wrapper/html-preview.d.ts +29 -4
- package/dist/html-preview-wrapper/html-preview.js +64 -6
- package/dist/html-preview-wrapper/index.d.ts +1 -1
- package/dist/html-preview-wrapper/preview-auto-height.d.ts +24 -0
- package/dist/html-preview-wrapper/preview-auto-height.js +120 -0
- package/dist/html-preview-wrapper/preview-base.d.ts +21 -1
- package/dist/html-preview-wrapper/preview-base.js +99 -50
- package/dist/i18n-defaults/index.d.ts +5 -3
- package/dist/i18n-defaults/index.js +89 -0
- package/dist/i18n-version/language-switcher.d.ts +10 -5
- package/dist/i18n-version/language-switcher.js +115 -22
- package/dist/i18n-version/types.d.ts +1 -1
- package/dist/mdx-components/index.d.ts +4 -0
- package/dist/mdx-components/index.js +11 -2
- package/dist/nav-indexing/versions-page-content.js +1 -1
- package/dist/plugins/claude-resources.js +15 -1
- package/dist/plugins/codex-resources.js +15 -1
- package/dist/plugins/internal/asset-viewer/asset-pages.d.ts +53 -0
- package/dist/plugins/internal/asset-viewer/asset-pages.js +98 -0
- package/dist/plugins/internal/asset-viewer/scan.d.ts +18 -1
- package/dist/plugins/internal/asset-viewer/scan.js +34 -27
- package/dist/plugins/internal/claude-resources/generate.d.ts +9 -0
- package/dist/plugins/internal/claude-resources/generate.js +188 -18
- package/dist/plugins/internal/claude-resources/index.d.ts +9 -0
- package/dist/plugins/internal/claude-resources/index.js +13 -1
- package/dist/plugins/internal/codex-resources/agents-md.js +15 -2
- package/dist/plugins/internal/codex-resources/agents.js +15 -2
- package/dist/plugins/internal/codex-resources/config.js +15 -2
- package/dist/plugins/internal/codex-resources/generate.d.ts +9 -0
- package/dist/plugins/internal/codex-resources/generate.js +19 -7
- package/dist/plugins/internal/codex-resources/hooks.js +15 -2
- package/dist/plugins/internal/codex-resources/index.d.ts +9 -0
- package/dist/plugins/internal/codex-resources/index.js +13 -1
- package/dist/plugins/internal/codex-resources/overview.js +136 -7
- package/dist/plugins/internal/codex-resources/rules.js +15 -2
- package/dist/plugins/internal/codex-resources/skills.js +16 -3
- package/dist/plugins/internal/llms-txt/assets.d.ts +24 -0
- package/dist/plugins/internal/llms-txt/assets.js +65 -0
- package/dist/plugins/internal/llms-txt/dev-middleware.d.ts +5 -0
- package/dist/plugins/internal/llms-txt/dev-middleware.js +9 -1
- package/dist/plugins/internal/llms-txt/emit.js +21 -5
- package/dist/plugins/internal/llms-txt/generate.d.ts +3 -3
- package/dist/plugins/internal/llms-txt/generate.js +55 -2
- package/dist/plugins/internal/llms-txt/index.d.ts +4 -1
- package/dist/plugins/internal/llms-txt/index.js +4 -0
- package/dist/plugins/internal/llms-txt/types.d.ts +24 -0
- package/dist/plugins/internal/llms-txt/types.js +4 -0
- package/dist/plugins/internal/resource-docs-shared/fs.d.ts +33 -0
- package/dist/plugins/internal/resource-docs-shared/fs.js +82 -1
- package/dist/plugins/internal/resource-docs-shared/index.d.ts +4 -2
- package/dist/plugins/internal/resource-docs-shared/index.js +21 -1
- package/dist/plugins/internal/resource-docs-shared/labels.d.ts +24 -0
- package/dist/plugins/internal/resource-docs-shared/labels.js +14 -0
- package/dist/plugins/internal/resource-docs-shared/locale-routes.d.ts +16 -0
- package/dist/plugins/internal/resource-docs-shared/locale-routes.js +14 -0
- package/dist/plugins/internal/resource-docs-shared/mdx.d.ts +7 -1
- package/dist/plugins/internal/resource-docs-shared/mdx.js +2 -2
- package/dist/plugins/internal/search-index/collect.js +46 -1
- package/dist/plugins/internal/search-index/types.d.ts +6 -1
- package/dist/plugins/llms-txt.js +9 -1
- package/dist/plugins/routes.js +14 -0
- package/dist/plugins/search-index.js +10 -1
- package/dist/preset.d.ts +9 -1
- package/dist/preset.js +25 -4
- package/dist/route-context/index.js +5 -17
- package/dist/route-enumerators/index.d.ts +14 -1
- package/dist/route-enumerators/index.js +38 -0
- package/dist/routes/locale-files-path.d.ts +29 -0
- package/dist/routes/locale-files-path.js +52 -0
- package/dist/safelist.css +1 -1
- package/dist/settings.d.ts +15 -0
- package/dist/tag-pages/index.js +2 -2
- package/eject/asset-components/asset-card.tsx +2 -0
- package/eject/asset-components/asset-code.tsx +2 -0
- package/eject/asset-components/shared.tsx +16 -0
- package/package.json +13 -9
- package/routes-src/locale-files-path.tsx +73 -0
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { generateLlmsFullTxt, generateLlmsTxt } from "./generate.js";
|
|
4
|
+
import { loadLlmsAssetEntries } from "./assets.js";
|
|
4
5
|
import { loadDocEntries } from "./load.js";
|
|
6
|
+
function assetsForLocale(assets, locale) {
|
|
7
|
+
return assets.filter(
|
|
8
|
+
(asset) => locale === null ? asset.locale === void 0 : asset.locale === locale
|
|
9
|
+
);
|
|
10
|
+
}
|
|
5
11
|
function emitLlmsTxt(options) {
|
|
6
12
|
const {
|
|
7
13
|
outDir,
|
|
@@ -11,10 +17,13 @@ function emitLlmsTxt(options) {
|
|
|
11
17
|
siteDescription,
|
|
12
18
|
defaultLocaleDir,
|
|
13
19
|
locales = [],
|
|
14
|
-
logger
|
|
20
|
+
logger,
|
|
21
|
+
projectRoot,
|
|
22
|
+
assetScan
|
|
15
23
|
} = options;
|
|
16
24
|
const meta = { siteName, siteDescription };
|
|
17
25
|
const written = [];
|
|
26
|
+
const assetEntries = loadLlmsAssetEntries({ projectRoot, assetScan, siteUrl });
|
|
18
27
|
const defaultEntries = loadDocEntries({
|
|
19
28
|
contentDir: defaultLocaleDir,
|
|
20
29
|
locale: null,
|
|
@@ -24,8 +33,14 @@ function emitLlmsTxt(options) {
|
|
|
24
33
|
mkdirSync(outDir, { recursive: true });
|
|
25
34
|
const defaultIndexPath = join(outDir, "llms.txt");
|
|
26
35
|
const defaultFullPath = join(outDir, "llms-full.txt");
|
|
27
|
-
writeFileSync(
|
|
28
|
-
|
|
36
|
+
writeFileSync(
|
|
37
|
+
defaultIndexPath,
|
|
38
|
+
generateLlmsTxt(defaultEntries, meta, assetsForLocale(assetEntries, null))
|
|
39
|
+
);
|
|
40
|
+
writeFileSync(
|
|
41
|
+
defaultFullPath,
|
|
42
|
+
generateLlmsFullTxt(defaultEntries, meta, assetsForLocale(assetEntries, null))
|
|
43
|
+
);
|
|
29
44
|
written.push(defaultIndexPath, defaultFullPath);
|
|
30
45
|
logger?.info(
|
|
31
46
|
`Generated llms.txt and llms-full.txt (${defaultEntries.length} pages)`
|
|
@@ -41,8 +56,9 @@ function emitLlmsTxt(options) {
|
|
|
41
56
|
mkdirSync(localeDir, { recursive: true });
|
|
42
57
|
const indexPath = join(localeDir, "llms.txt");
|
|
43
58
|
const fullPath = join(localeDir, "llms-full.txt");
|
|
44
|
-
|
|
45
|
-
writeFileSync(
|
|
59
|
+
const localeAssets = assetsForLocale(assetEntries, code);
|
|
60
|
+
writeFileSync(indexPath, generateLlmsTxt(localeEntries, meta, localeAssets));
|
|
61
|
+
writeFileSync(fullPath, generateLlmsFullTxt(localeEntries, meta, localeAssets));
|
|
46
62
|
written.push(indexPath, fullPath);
|
|
47
63
|
logger?.info(
|
|
48
64
|
`Generated ${code}/llms.txt and ${code}/llms-full.txt (${localeEntries.length} pages)`
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
* Output format must remain byte-identical to the legacy Astro emitter
|
|
10
10
|
* — the file shape is part of the project's public surface.
|
|
11
11
|
*/
|
|
12
|
-
import type
|
|
12
|
+
import { type LlmsAssetEntry, type LlmsDocEntry, type LlmsTxtSiteMeta } from "./types.js";
|
|
13
13
|
/**
|
|
14
14
|
* Slim index — site header followed by a markdown bullet per page with
|
|
15
15
|
* `[title](url): description`.
|
|
16
16
|
*/
|
|
17
|
-
export declare function generateLlmsTxt(entries: readonly LlmsDocEntry[], meta: LlmsTxtSiteMeta): string;
|
|
17
|
+
export declare function generateLlmsTxt(entries: readonly LlmsDocEntry[], meta: LlmsTxtSiteMeta, assets?: readonly LlmsAssetEntry[]): string;
|
|
18
18
|
/**
|
|
19
19
|
* Full content concatenation — site header followed by every page's
|
|
20
20
|
* stripped body separated by `---` rules.
|
|
21
21
|
*/
|
|
22
|
-
export declare function generateLlmsFullTxt(entries: readonly LlmsDocEntry[], meta: LlmsTxtSiteMeta): string;
|
|
22
|
+
export declare function generateLlmsFullTxt(entries: readonly LlmsDocEntry[], meta: LlmsTxtSiteMeta, assets?: readonly LlmsAssetEntry[]): string;
|
|
@@ -1,4 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
LLMS_ASSET_TEXT_CAP_BYTES
|
|
3
|
+
} from "./types.js";
|
|
4
|
+
const BINARY_ASSET_STUB = "(binary asset, not inlined)";
|
|
5
|
+
const TRUNCATED_ASSET_MARKER = "\u2026 (truncated)";
|
|
6
|
+
function utf8Width(codePoint) {
|
|
7
|
+
if (codePoint <= 127) return 1;
|
|
8
|
+
if (codePoint <= 2047) return 2;
|
|
9
|
+
if (codePoint <= 65535) return 3;
|
|
10
|
+
return 4;
|
|
11
|
+
}
|
|
12
|
+
function truncateAssetText(text, explicitlyTruncated) {
|
|
13
|
+
let bytes = 0;
|
|
14
|
+
let end = 0;
|
|
15
|
+
for (const character of text) {
|
|
16
|
+
const width = utf8Width(character.codePointAt(0) ?? 0);
|
|
17
|
+
if (bytes + width > LLMS_ASSET_TEXT_CAP_BYTES) {
|
|
18
|
+
return { content: text.slice(0, end), truncated: true };
|
|
19
|
+
}
|
|
20
|
+
bytes += width;
|
|
21
|
+
end += character.length;
|
|
22
|
+
}
|
|
23
|
+
return { content: text, truncated: explicitlyTruncated };
|
|
24
|
+
}
|
|
25
|
+
function renderAssetBody(entry) {
|
|
26
|
+
if (!entry.isText) return BINARY_ASSET_STUB;
|
|
27
|
+
const result = truncateAssetText(
|
|
28
|
+
entry.content ?? "",
|
|
29
|
+
entry.truncated === true
|
|
30
|
+
);
|
|
31
|
+
const content = result.content.trimEnd();
|
|
32
|
+
if (!result.truncated) return content;
|
|
33
|
+
return `${content}
|
|
34
|
+
${TRUNCATED_ASSET_MARKER}`;
|
|
35
|
+
}
|
|
36
|
+
function generateLlmsTxt(entries, meta, assets = []) {
|
|
2
37
|
const lines = [];
|
|
3
38
|
lines.push(`# ${meta.siteName}`);
|
|
4
39
|
lines.push("");
|
|
@@ -10,9 +45,17 @@ function generateLlmsTxt(entries, meta) {
|
|
|
10
45
|
lines.push(`- [${entry.title}](${entry.url}): ${entry.description}`);
|
|
11
46
|
}
|
|
12
47
|
lines.push("");
|
|
48
|
+
if (assets.length > 0) {
|
|
49
|
+
lines.push("## Files");
|
|
50
|
+
lines.push("");
|
|
51
|
+
for (const asset of assets) {
|
|
52
|
+
lines.push(`- [${asset.path}](${asset.url})`);
|
|
53
|
+
}
|
|
54
|
+
lines.push("");
|
|
55
|
+
}
|
|
13
56
|
return lines.join("\n");
|
|
14
57
|
}
|
|
15
|
-
function generateLlmsFullTxt(entries, meta) {
|
|
58
|
+
function generateLlmsFullTxt(entries, meta, assets = []) {
|
|
16
59
|
const lines = [];
|
|
17
60
|
lines.push(`# ${meta.siteName}`);
|
|
18
61
|
lines.push("");
|
|
@@ -27,6 +70,16 @@ function generateLlmsFullTxt(entries, meta) {
|
|
|
27
70
|
lines.push("");
|
|
28
71
|
lines.push(entry.content);
|
|
29
72
|
}
|
|
73
|
+
for (const asset of assets) {
|
|
74
|
+
lines.push("");
|
|
75
|
+
lines.push("---");
|
|
76
|
+
lines.push("");
|
|
77
|
+
lines.push(`# ${asset.path}`);
|
|
78
|
+
lines.push("");
|
|
79
|
+
lines.push(`> Source: ${asset.url}`);
|
|
80
|
+
lines.push("");
|
|
81
|
+
lines.push(renderAssetBody(asset));
|
|
82
|
+
}
|
|
30
83
|
lines.push("");
|
|
31
84
|
return lines.join("\n");
|
|
32
85
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
export { loadLlmsAssetEntries } from "./assets.js";
|
|
2
|
+
export type { LlmsAssetLoadOptions } from "./assets.js";
|
|
1
3
|
export { createLlmsTxtDevMiddleware } from "./dev-middleware.js";
|
|
2
4
|
export type { LlmsTxtDevMiddlewareOptions, LlmsTxtMiddleware, LlmsTxtMiddlewareLogger, LlmsTxtNextFn, } from "./dev-middleware.js";
|
|
3
5
|
export { emitLlmsTxt } from "./emit.js";
|
|
4
6
|
export { generateLlmsFullTxt, generateLlmsTxt, } from "./generate.js";
|
|
5
7
|
export { collectMdFiles, isExcluded, loadDocEntries, parseMarkdownFile, slugToUrl, } from "./load.js";
|
|
6
8
|
export { stripImportsAndJsx, stripMarkdown } from "./strip.js";
|
|
7
|
-
export
|
|
9
|
+
export { LLMS_ASSET_TEXT_CAP_BYTES } from "./types.js";
|
|
10
|
+
export type { LlmsAssetEntry, LlmsDocEntry, LlmsTxtEmitOptions, LlmsTxtEmitResult, LlmsTxtFrontmatter, LlmsTxtLoadOptions, LlmsTxtLocaleConfig, LlmsTxtLogger, LlmsTxtSiteMeta, } from "./types.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { loadLlmsAssetEntries } from "./assets.js";
|
|
1
2
|
import { createLlmsTxtDevMiddleware } from "./dev-middleware.js";
|
|
2
3
|
import { emitLlmsTxt } from "./emit.js";
|
|
3
4
|
import {
|
|
@@ -12,7 +13,9 @@ import {
|
|
|
12
13
|
slugToUrl
|
|
13
14
|
} from "./load.js";
|
|
14
15
|
import { stripImportsAndJsx, stripMarkdown } from "./strip.js";
|
|
16
|
+
import { LLMS_ASSET_TEXT_CAP_BYTES } from "./types.js";
|
|
15
17
|
export {
|
|
18
|
+
LLMS_ASSET_TEXT_CAP_BYTES,
|
|
16
19
|
collectMdFiles,
|
|
17
20
|
createLlmsTxtDevMiddleware,
|
|
18
21
|
emitLlmsTxt,
|
|
@@ -20,6 +23,7 @@ export {
|
|
|
20
23
|
generateLlmsTxt,
|
|
21
24
|
isExcluded,
|
|
22
25
|
loadDocEntries,
|
|
26
|
+
loadLlmsAssetEntries,
|
|
23
27
|
parseMarkdownFile,
|
|
24
28
|
slugToUrl,
|
|
25
29
|
stripImportsAndJsx,
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* and plain Node test tooling can share the same emitter.
|
|
6
6
|
*/
|
|
7
7
|
import type { MdDocFrontmatter } from "../../../md-utils/index.js";
|
|
8
|
+
import type { AssetScanProjection } from "../asset-viewer/asset-pages.js";
|
|
9
|
+
/** Maximum number of UTF-8 bytes inlined for one text asset in llms-full.txt. */
|
|
10
|
+
export declare const LLMS_ASSET_TEXT_CAP_BYTES: number;
|
|
8
11
|
/**
|
|
9
12
|
* Frontmatter fields the loader reads off of each MDX/MD file. Callers
|
|
10
13
|
* are free to extend this; unrecognised fields are ignored. Re-export of the
|
|
@@ -39,6 +42,23 @@ export interface LlmsDocEntry {
|
|
|
39
42
|
/** `frontmatter.sidebar_position`, undefined when not declared. */
|
|
40
43
|
sidebarPosition: number | undefined;
|
|
41
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* One generated asset-viewer page in the llms outputs.
|
|
47
|
+
*
|
|
48
|
+
* The path is the normalized path relative to `assetViewerDir` and doubles as
|
|
49
|
+
* the display title. Binary entries intentionally omit `content`; generators
|
|
50
|
+
* render their fixed one-line stub instead of attempting to inline bytes.
|
|
51
|
+
*/
|
|
52
|
+
export interface LlmsAssetEntry {
|
|
53
|
+
path: string;
|
|
54
|
+
url: string;
|
|
55
|
+
/** Omitted for the default locale; present for localized outputs. */
|
|
56
|
+
locale?: string;
|
|
57
|
+
isText: boolean;
|
|
58
|
+
content?: string;
|
|
59
|
+
/** True when the source was longer than {@link LLMS_ASSET_TEXT_CAP_BYTES}. */
|
|
60
|
+
truncated?: boolean;
|
|
61
|
+
}
|
|
42
62
|
/**
|
|
43
63
|
* Site-level metadata threaded through the generators. Matches the
|
|
44
64
|
* current `siteName` / `siteDescription` settings one-for-one so callers can
|
|
@@ -103,6 +123,10 @@ export interface LlmsTxtEmitOptions extends LlmsTxtSiteMeta {
|
|
|
103
123
|
* `outDir/<code>/llms.txt` and `outDir/<code>/llms-full.txt`.
|
|
104
124
|
*/
|
|
105
125
|
locales?: LlmsTxtLocaleConfig[];
|
|
126
|
+
/** Runtime project root; injected by the zfb plugin wrapper, never serialized in the preset. */
|
|
127
|
+
projectRoot?: string;
|
|
128
|
+
/** Shared asset-viewer projection; consumed by the asset indexing wave. */
|
|
129
|
+
assetScan?: AssetScanProjection;
|
|
106
130
|
/**
|
|
107
131
|
* Optional logger. Defaults to a no-op so unit tests stay quiet; the zfb
|
|
108
132
|
* plugin can pipe its logger through.
|
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
export interface ResourceLocaleConfig {
|
|
2
|
+
dir: string;
|
|
3
|
+
}
|
|
4
|
+
export interface ResolveLocaleDirsOptions {
|
|
5
|
+
/** Project root used to resolve project-relative content directories. */
|
|
6
|
+
projectRoot: string;
|
|
7
|
+
/** Default-locale content directory, already resolved or project-relative. */
|
|
8
|
+
docsDir: string;
|
|
9
|
+
/** Additional locale directories, keyed by locale code. */
|
|
10
|
+
locales?: Record<string, ResourceLocaleConfig>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolve additional locale content roots using the same rules as the
|
|
14
|
+
* generator's default `docsDir`: absolute values pass through, while relative
|
|
15
|
+
* values resolve against `projectRoot`.
|
|
16
|
+
*
|
|
17
|
+
* Generated locale indexes are written into these roots by a later emission
|
|
18
|
+
* step. Rejecting duplicate roots here is important because a recursive clean
|
|
19
|
+
* or a generated index for one locale must never target another locale's tree.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveLocaleDirs({ projectRoot, docsDir, locales, }: ResolveLocaleDirsOptions): Record<string, ResourceLocaleConfig> | undefined;
|
|
1
22
|
export declare function ensureDir(dir: string): void;
|
|
2
23
|
export declare function cleanDir(dir: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Write one generated locale index without deleting or overwriting authored
|
|
26
|
+
* content. A missing file is created; an existing file is only replaced when
|
|
27
|
+
* its frontmatter explicitly carries `generated: true`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function writeGeneratedIndex(absPath: string, mdx: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Remove a generated locale index that is no longer backed by a source
|
|
32
|
+
* category. Authored files are intentionally left untouched: locale trees
|
|
33
|
+
* can contain downstream overrides and are never recursively cleaned.
|
|
34
|
+
*/
|
|
35
|
+
export declare function removeGeneratedIndex(absPath: string): void;
|
|
3
36
|
export declare function listFiles(dir: string): string[];
|
|
@@ -1,4 +1,48 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parseFrontmatter } from "./mdx.js";
|
|
4
|
+
function resolveLocaleDirs({
|
|
5
|
+
projectRoot,
|
|
6
|
+
docsDir,
|
|
7
|
+
locales
|
|
8
|
+
}) {
|
|
9
|
+
if (locales === void 0) return void 0;
|
|
10
|
+
const defaultDir = resolveConfiguredDir(projectRoot, docsDir);
|
|
11
|
+
const defaultRoot = canonicalExistingRoot(defaultDir);
|
|
12
|
+
const roots = /* @__PURE__ */ new Map([
|
|
13
|
+
[defaultRoot, { label: "default docsDir", dir: defaultDir }]
|
|
14
|
+
]);
|
|
15
|
+
const resolved = {};
|
|
16
|
+
for (const [locale, config] of Object.entries(locales)) {
|
|
17
|
+
if (config === null || typeof config !== "object" || typeof config.dir !== "string") {
|
|
18
|
+
throw new TypeError(
|
|
19
|
+
`resource-docs: locale "${locale}" must configure a content directory as { dir: string }`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
const dir = resolveConfiguredDir(projectRoot, config.dir);
|
|
23
|
+
const canonicalDir = canonicalExistingRoot(dir);
|
|
24
|
+
const previous = roots.get(canonicalDir);
|
|
25
|
+
if (previous !== void 0) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`resource-docs: locale "${locale}" directory "${dir}" overlaps ${previous.label} at "${canonicalDir}". Configure a distinct content directory (or remove/rename the conflicting locale).`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
roots.set(canonicalDir, { label: `locale "${locale}"`, dir });
|
|
31
|
+
resolved[locale] = { dir };
|
|
32
|
+
}
|
|
33
|
+
return resolved;
|
|
34
|
+
}
|
|
35
|
+
function resolveConfiguredDir(projectRoot, input) {
|
|
36
|
+
return path.isAbsolute(input) ? input : path.resolve(projectRoot, input);
|
|
37
|
+
}
|
|
38
|
+
function canonicalExistingRoot(dir) {
|
|
39
|
+
const normalized = path.normalize(dir);
|
|
40
|
+
try {
|
|
41
|
+
return path.normalize(fs.realpathSync.native(normalized));
|
|
42
|
+
} catch {
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
2
46
|
function ensureDir(dir) {
|
|
3
47
|
if (!fs.existsSync(dir)) {
|
|
4
48
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -8,6 +52,40 @@ function cleanDir(dir) {
|
|
|
8
52
|
if (!fs.existsSync(dir)) return;
|
|
9
53
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
10
54
|
}
|
|
55
|
+
function writeGeneratedIndex(absPath, mdx) {
|
|
56
|
+
if (fs.existsSync(absPath)) {
|
|
57
|
+
let existing;
|
|
58
|
+
try {
|
|
59
|
+
existing = fs.readFileSync(absPath, "utf8");
|
|
60
|
+
} catch (error) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`resource-docs: cannot inspect existing locale index "${absPath}" before writing (${error instanceof Error ? error.message : String(error)}). Remove or rename the file, then retry.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
const parsed = parseFrontmatter(existing);
|
|
66
|
+
if (parsed?.data.generated !== true) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`resource-docs: refusing to overwrite authored locale index "${absPath}" because its frontmatter does not contain generated: true. Remove or rename the file, then retry.`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
ensureDir(path.dirname(absPath));
|
|
73
|
+
fs.writeFileSync(absPath, mdx);
|
|
74
|
+
}
|
|
75
|
+
function removeGeneratedIndex(absPath) {
|
|
76
|
+
if (!fs.existsSync(absPath)) return;
|
|
77
|
+
let existing;
|
|
78
|
+
try {
|
|
79
|
+
existing = fs.readFileSync(absPath, "utf8");
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`resource-docs: cannot inspect existing locale index "${absPath}" before removing it (${error instanceof Error ? error.message : String(error)}). Remove or rename the file, then retry.`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (parseFrontmatter(existing)?.data.generated === true) {
|
|
86
|
+
fs.unlinkSync(absPath);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
11
89
|
function listFiles(dir) {
|
|
12
90
|
if (!fs.existsSync(dir)) return [];
|
|
13
91
|
return fs.readdirSync(dir, { withFileTypes: true }).filter((d) => d.isFile()).map((d) => d.name).sort();
|
|
@@ -15,5 +93,8 @@ function listFiles(dir) {
|
|
|
15
93
|
export {
|
|
16
94
|
cleanDir,
|
|
17
95
|
ensureDir,
|
|
18
|
-
listFiles
|
|
96
|
+
listFiles,
|
|
97
|
+
removeGeneratedIndex,
|
|
98
|
+
resolveLocaleDirs,
|
|
99
|
+
writeGeneratedIndex
|
|
19
100
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { escapeForMdx } from "./escape-for-mdx.js";
|
|
2
|
-
export { cleanDir, ensureDir, listFiles } from "./fs.js";
|
|
3
|
-
export {
|
|
2
|
+
export { cleanDir, ensureDir, listFiles, removeGeneratedIndex, resolveLocaleDirs, writeGeneratedIndex, type ResolveLocaleDirsOptions, type ResourceLocaleConfig, } from "./fs.js";
|
|
3
|
+
export { resolveLabel, resolveResourceLabel, type ResolveResourceLabelOptions, type ResourceTranslations, } from "./labels.js";
|
|
4
|
+
export { shouldEmitResourceLocaleRoute, type ResourceLocaleRouteOptions, } from "./locale-routes.js";
|
|
5
|
+
export { assertNotIndexReserved, escapeTitle, formatFrontmatterString, parseFrontmatter, type FrontmatterStringRenderer, type MdxFileWriter, writeCategoryIndex, writeUnlistedSubPage, } from "./mdx.js";
|
|
4
6
|
export { isRepoRelativeLink, downgradeRepoRelativeLinks } from "./links.js";
|
|
5
7
|
export { escapeMarkdownTableCell, renderCodeFence, } from "./markdown-structure.js";
|
|
6
8
|
export { EXCLUDED_DIR_NAMES, findNamedFiles } from "./walk.js";
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { escapeForMdx } from "./escape-for-mdx.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
cleanDir,
|
|
4
|
+
ensureDir,
|
|
5
|
+
listFiles,
|
|
6
|
+
removeGeneratedIndex,
|
|
7
|
+
resolveLocaleDirs,
|
|
8
|
+
writeGeneratedIndex
|
|
9
|
+
} from "./fs.js";
|
|
10
|
+
import {
|
|
11
|
+
resolveLabel,
|
|
12
|
+
resolveResourceLabel
|
|
13
|
+
} from "./labels.js";
|
|
14
|
+
import {
|
|
15
|
+
shouldEmitResourceLocaleRoute
|
|
16
|
+
} from "./locale-routes.js";
|
|
3
17
|
import {
|
|
4
18
|
assertNotIndexReserved,
|
|
5
19
|
escapeTitle,
|
|
@@ -38,7 +52,13 @@ export {
|
|
|
38
52
|
isRepoRelativeLink,
|
|
39
53
|
listFiles,
|
|
40
54
|
parseFrontmatter,
|
|
55
|
+
removeGeneratedIndex,
|
|
41
56
|
renderCodeFence,
|
|
57
|
+
resolveLabel,
|
|
58
|
+
resolveLocaleDirs,
|
|
59
|
+
resolveResourceLabel,
|
|
60
|
+
shouldEmitResourceLocaleRoute,
|
|
42
61
|
writeCategoryIndex,
|
|
62
|
+
writeGeneratedIndex,
|
|
43
63
|
writeUnlistedSubPage
|
|
44
64
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type ResourceTranslations = Record<string, Record<string, string>>;
|
|
2
|
+
export interface ResolveResourceLabelOptions {
|
|
3
|
+
/** UI-string translation table, keyed by locale then translation key. */
|
|
4
|
+
translations?: ResourceTranslations;
|
|
5
|
+
/** Locale for the page currently being generated. */
|
|
6
|
+
locale: string;
|
|
7
|
+
/** Configured default locale, if one was supplied by the caller. */
|
|
8
|
+
defaultLocale?: string;
|
|
9
|
+
/** Translation key to resolve. */
|
|
10
|
+
key: string;
|
|
11
|
+
/** English literal emitted by the pre-i18n generator. */
|
|
12
|
+
fallbackLiteral: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolve a generated-resource label with the same fallback order as `t()`.
|
|
16
|
+
*
|
|
17
|
+
* The caller must provide the English literal that the generator used before
|
|
18
|
+
* localization. Keeping that literal as the final fallback prevents a
|
|
19
|
+
* missing translation from leaking an implementation key such as
|
|
20
|
+
* `resource.claude.title` into frontmatter or page output.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveResourceLabel({ translations, locale, defaultLocale, key, fallbackLiteral, }: ResolveResourceLabelOptions): string;
|
|
23
|
+
/** Short alias for callers that already work in the resource-docs namespace. */
|
|
24
|
+
export declare const resolveLabel: typeof resolveResourceLabel;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function resolveResourceLabel({
|
|
2
|
+
translations,
|
|
3
|
+
locale,
|
|
4
|
+
defaultLocale,
|
|
5
|
+
key,
|
|
6
|
+
fallbackLiteral
|
|
7
|
+
}) {
|
|
8
|
+
return translations?.[locale]?.[key] ?? (defaultLocale === void 0 ? void 0 : translations?.[defaultLocale]?.[key]) ?? translations?.en?.[key] ?? fallbackLiteral;
|
|
9
|
+
}
|
|
10
|
+
const resolveLabel = resolveResourceLabel;
|
|
11
|
+
export {
|
|
12
|
+
resolveLabel,
|
|
13
|
+
resolveResourceLabel
|
|
14
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface ResourceLocaleRouteOptions {
|
|
2
|
+
/** Route slug below `/docs/`, without a locale prefix. */
|
|
3
|
+
slug: string;
|
|
4
|
+
/** Locale whose physical index would be emitted. */
|
|
5
|
+
locale: string;
|
|
6
|
+
/** Locale served from the unprefixed default docs root. */
|
|
7
|
+
defaultLocale?: string;
|
|
8
|
+
/** Default-locale-only route prefixes in their `/docs/.../` form. */
|
|
9
|
+
defaultLocaleOnlyPrefixes?: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Whether a generated resource index has a route in the requested locale.
|
|
13
|
+
* Matching deliberately mirrors `url-helpers.isDefaultLocaleOnlyPath`: the
|
|
14
|
+
* default-locale-shaped route gets a trailing slash and uses prefix matching.
|
|
15
|
+
*/
|
|
16
|
+
export declare function shouldEmitResourceLocaleRoute({ slug, locale, defaultLocale, defaultLocaleOnlyPrefixes, }: ResourceLocaleRouteOptions): boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function shouldEmitResourceLocaleRoute({
|
|
2
|
+
slug,
|
|
3
|
+
locale,
|
|
4
|
+
defaultLocale = "en",
|
|
5
|
+
defaultLocaleOnlyPrefixes = []
|
|
6
|
+
}) {
|
|
7
|
+
if (locale === defaultLocale) return true;
|
|
8
|
+
const normalizedSlug = slug.replace(/^\/+|\/+$/g, "");
|
|
9
|
+
const routePath = `/docs/${normalizedSlug}/`;
|
|
10
|
+
return !defaultLocaleOnlyPrefixes.some((prefix) => routePath.startsWith(prefix));
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
shouldEmitResourceLocaleRoute
|
|
14
|
+
};
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
export declare function parseFrontmatter(content: string): import("../../../frontmatter/index.js").ParsedFrontmatter | null;
|
|
2
2
|
export declare function escapeTitle(s: string): string;
|
|
3
3
|
export type FrontmatterStringRenderer = (value: string) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Write one generated MDX file. The callback seam lets locale indexes use
|
|
6
|
+
* `writeGeneratedIndex` (which protects authored files) while the default
|
|
7
|
+
* locale keeps the historical direct-write behaviour.
|
|
8
|
+
*/
|
|
9
|
+
export type MdxFileWriter = (absolutePath: string, content: string) => void;
|
|
4
10
|
export declare function formatFrontmatterString(value: string): string;
|
|
5
|
-
export declare function writeCategoryIndex(outputDir: string, label: string, position: number, description: string, renderString?: FrontmatterStringRenderer): void;
|
|
11
|
+
export declare function writeCategoryIndex(outputDir: string, label: string, position: number, description: string, renderString?: FrontmatterStringRenderer, writeFile?: MdxFileWriter): void;
|
|
6
12
|
/**
|
|
7
13
|
* Writes an unlisted sub-page MDX file. Used for skill references, scripts,
|
|
8
14
|
* and assets.
|
|
@@ -24,7 +24,7 @@ value: ${value}
|
|
|
24
24
|
}
|
|
25
25
|
return JSON.stringify(value);
|
|
26
26
|
}
|
|
27
|
-
function writeCategoryIndex(outputDir, label, position, description, renderString = (value) => `"${escapeTitle(value)}"
|
|
27
|
+
function writeCategoryIndex(outputDir, label, position, description, renderString = (value) => `"${escapeTitle(value)}"`, writeFile = (absolutePath, content) => fs.writeFileSync(absolutePath, content)) {
|
|
28
28
|
const mdx = `---
|
|
29
29
|
title: ${renderString(label)}
|
|
30
30
|
description: ${renderString(description)}
|
|
@@ -33,7 +33,7 @@ category_no_page: true
|
|
|
33
33
|
generated: true
|
|
34
34
|
---
|
|
35
35
|
`;
|
|
36
|
-
|
|
36
|
+
writeFile(path.join(outputDir, "index.mdx"), mdx);
|
|
37
37
|
}
|
|
38
38
|
function writeUnlistedSubPage(outputPath, title, body, renderString = (value) => `"${escapeTitle(value)}"`) {
|
|
39
39
|
fs.writeFileSync(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { closeSync, openSync, readSync } from "node:fs";
|
|
2
|
+
import { basename, resolve } from "node:path";
|
|
2
3
|
import {
|
|
3
4
|
collectMdFiles,
|
|
4
5
|
isExcluded,
|
|
@@ -6,12 +7,34 @@ import {
|
|
|
6
7
|
slugToUrl,
|
|
7
8
|
stripMarkdown
|
|
8
9
|
} from "../../../md-utils/index.js";
|
|
10
|
+
import { collectAssetPageDescriptors } from "../asset-viewer/asset-pages.js";
|
|
9
11
|
import {
|
|
10
12
|
MAX_BODY_LENGTH
|
|
11
13
|
} from "./types.js";
|
|
12
14
|
function truncateBody(text) {
|
|
13
15
|
return text.length > MAX_BODY_LENGTH ? text.substring(0, MAX_BODY_LENGTH) : text;
|
|
14
16
|
}
|
|
17
|
+
function readAssetExcerpt(filePath) {
|
|
18
|
+
const sample = Buffer.allocUnsafe(MAX_BODY_LENGTH * 4);
|
|
19
|
+
const fd = openSync(filePath, "r");
|
|
20
|
+
try {
|
|
21
|
+
let offset = 0;
|
|
22
|
+
while (offset < sample.length) {
|
|
23
|
+
const bytesRead = readSync(
|
|
24
|
+
fd,
|
|
25
|
+
sample,
|
|
26
|
+
offset,
|
|
27
|
+
sample.length - offset,
|
|
28
|
+
offset
|
|
29
|
+
);
|
|
30
|
+
if (bytesRead === 0) break;
|
|
31
|
+
offset += bytesRead;
|
|
32
|
+
}
|
|
33
|
+
return truncateBody(sample.subarray(0, offset).toString("utf8"));
|
|
34
|
+
} finally {
|
|
35
|
+
closeSync(fd);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
15
38
|
function buildEntries(contentDir, locale, base) {
|
|
16
39
|
const absDir = resolve(contentDir);
|
|
17
40
|
const files = collectMdFiles(absDir);
|
|
@@ -33,6 +56,27 @@ function buildEntries(contentDir, locale, base) {
|
|
|
33
56
|
}
|
|
34
57
|
return entries;
|
|
35
58
|
}
|
|
59
|
+
function buildAssetEntries(config) {
|
|
60
|
+
const { assetScan, projectRoot } = config;
|
|
61
|
+
if (assetScan === void 0 || projectRoot === void 0) return [];
|
|
62
|
+
const descriptors = collectAssetPageDescriptors({
|
|
63
|
+
projectRoot,
|
|
64
|
+
assetScan,
|
|
65
|
+
consumer: "search"
|
|
66
|
+
});
|
|
67
|
+
const assetRoot = resolve(projectRoot, "public", assetScan.assetViewerDir);
|
|
68
|
+
return descriptors.map((descriptor) => {
|
|
69
|
+
const localePrefix = descriptor.locale === void 0 ? "" : `${descriptor.locale}/`;
|
|
70
|
+
const body = descriptor.isText ? readAssetExcerpt(resolve(assetRoot, descriptor.path)) : "";
|
|
71
|
+
return {
|
|
72
|
+
id: `asset:${localePrefix}${assetScan.assetViewerRoutePrefix}/${descriptor.path}`,
|
|
73
|
+
title: basename(descriptor.path),
|
|
74
|
+
body,
|
|
75
|
+
url: descriptor.url,
|
|
76
|
+
description: descriptor.path
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
36
80
|
function collectSearchEntries(config) {
|
|
37
81
|
const base = config.base ?? "";
|
|
38
82
|
const entries = [];
|
|
@@ -42,6 +86,7 @@ function collectSearchEntries(config) {
|
|
|
42
86
|
entries.push(...buildEntries(locale.dir, code, base));
|
|
43
87
|
}
|
|
44
88
|
}
|
|
89
|
+
entries.push(...buildAssetEntries(config));
|
|
45
90
|
return entries;
|
|
46
91
|
}
|
|
47
92
|
export {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AssetScanProjection } from "../asset-viewer/asset-pages.js";
|
|
1
2
|
/**
|
|
2
3
|
* One page in the search index. The shape mirrors today's Astro
|
|
3
4
|
* integration output verbatim — keep it byte-identical so downstream
|
|
@@ -5,7 +6,7 @@
|
|
|
5
6
|
* MiniSearch) keep working unchanged after the zfb cutover.
|
|
6
7
|
*/
|
|
7
8
|
export interface SearchIndexEntry {
|
|
8
|
-
/** Stable
|
|
9
|
+
/** Stable document slug, locale-prefixed slug, or `asset:`-namespaced asset path. */
|
|
9
10
|
id: string;
|
|
10
11
|
/** Frontmatter title, falling back to the slug when missing. */
|
|
11
12
|
title: string;
|
|
@@ -29,6 +30,10 @@ export interface SearchIndexConfig {
|
|
|
29
30
|
locales?: Record<string, SearchIndexLocaleConfig>;
|
|
30
31
|
/** Site base path (e.g. `""`, `"/docs"`); trailing slash is normalised away. */
|
|
31
32
|
base?: string;
|
|
33
|
+
/** Runtime project root for asset scans; injected by the zfb plugin wrapper, never serialized in the preset. */
|
|
34
|
+
projectRoot?: string;
|
|
35
|
+
/** Shared asset-viewer projection; consumed by the asset indexing wave. */
|
|
36
|
+
assetScan?: AssetScanProjection;
|
|
32
37
|
}
|
|
33
38
|
/** Maximum body text stored per entry (display excerpt cap). */
|
|
34
39
|
export declare const MAX_BODY_LENGTH = 300;
|
package/dist/plugins/llms-txt.js
CHANGED
|
@@ -6,6 +6,9 @@ const plugin = {
|
|
|
6
6
|
async postBuild(ctx) {
|
|
7
7
|
await emitLlmsTxt({
|
|
8
8
|
...ctx.options,
|
|
9
|
+
// `projectRoot` is runtime-only: zfb supplies the authoritative value,
|
|
10
|
+
// while the preset's serialized asset projection deliberately omits it.
|
|
11
|
+
projectRoot: ctx.projectRoot,
|
|
9
12
|
outDir: ctx.outDir,
|
|
10
13
|
// siteUrl is normalised to undefined when falsy because the runner
|
|
11
14
|
// switches between absolute and root-relative URLs based on its
|
|
@@ -16,7 +19,12 @@ const plugin = {
|
|
|
16
19
|
},
|
|
17
20
|
devMiddleware(ctx) {
|
|
18
21
|
const middleware = createLlmsTxtDevMiddleware(
|
|
19
|
-
|
|
22
|
+
{
|
|
23
|
+
...ctx.options,
|
|
24
|
+
// Mirror postBuild so future asset consumers see the same project
|
|
25
|
+
// root in both synchronous dev and build paths.
|
|
26
|
+
projectRoot: ctx.projectRoot
|
|
27
|
+
},
|
|
20
28
|
ctx.logger
|
|
21
29
|
);
|
|
22
30
|
const handler = connectToZfbHandler(middleware);
|