@lexibase/rdx-core 3.0.0 → 3.1.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/dist/{chunk-GSIKV6MV.js → chunk-KPVVN2MN.js} +173 -5
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +11 -3
- package/dist/{index-2qiAhOwp.d.ts → index-CIBgPARs.d.ts} +6 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mdx/index.d.ts +4 -2
- package/dist/mdx/index.js +66 -3952
- package/package.json +5 -4
- package/dist/chunk-J674JOK2.js +0 -310
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexibase/rdx-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Content indexing and document utilities for RDX documentation projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -54,14 +54,15 @@
|
|
|
54
54
|
"remark-mdx": "^3.1.1",
|
|
55
55
|
"remark-parse": "^11.0.0",
|
|
56
56
|
"remark-stringify": "^11.0.0",
|
|
57
|
+
"shiki": "^4.5.0",
|
|
57
58
|
"unified": "^11.0.5",
|
|
58
|
-
"@lexibase/rdx-types": "2.
|
|
59
|
+
"@lexibase/rdx-types": "2.4.0"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@types/node": "^22.15.3",
|
|
62
63
|
"@types/react": "19.3.0",
|
|
63
|
-
"@rdx/
|
|
64
|
-
"@rdx/
|
|
64
|
+
"@rdx/typescript-config": "1.0.0",
|
|
65
|
+
"@rdx/eslint-config": "1.0.0"
|
|
65
66
|
},
|
|
66
67
|
"engines": {
|
|
67
68
|
"node": "^22.18.0 || ^24.11.0"
|
package/dist/chunk-J674JOK2.js
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_POSITION,
|
|
3
|
-
documentExtension,
|
|
4
|
-
orderedName,
|
|
5
|
-
slugFromRelativePath
|
|
6
|
-
} from "./chunk-L7FZDK6G.js";
|
|
7
|
-
|
|
8
|
-
// src/content/static-source.ts
|
|
9
|
-
import matter from "gray-matter";
|
|
10
|
-
function parseStaticDocument(source) {
|
|
11
|
-
const text = source.replace(/^\uFEFF/, "");
|
|
12
|
-
if (text.startsWith("---") && text[3] !== "-") {
|
|
13
|
-
const language = matter.language(text).name.toLowerCase();
|
|
14
|
-
if (language && !["yaml", "yml", "json"].includes(language))
|
|
15
|
-
throw new Error(
|
|
16
|
-
"rdx check accepts YAML or JSON frontmatter, without executing document code."
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
return matter(source, {});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// src/content/index.ts
|
|
23
|
-
import fs from "fs";
|
|
24
|
-
import path from "path";
|
|
25
|
-
import matter2 from "gray-matter";
|
|
26
|
-
function getDocsRoot(docsDir = "docs") {
|
|
27
|
-
return path.resolve(
|
|
28
|
-
/* turbopackIgnore: true */
|
|
29
|
-
process.cwd(),
|
|
30
|
-
docsDir
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
function toTitle(value) {
|
|
34
|
-
return value.replace(/[-_]/g, " ").replace(/\b\w/g, (character) => character.toUpperCase());
|
|
35
|
-
}
|
|
36
|
-
function isRecord(value) {
|
|
37
|
-
return typeof value === "object" && value !== null;
|
|
38
|
-
}
|
|
39
|
-
function stringValue(value, fallback) {
|
|
40
|
-
return typeof value === "string" && value.trim() ? value : fallback;
|
|
41
|
-
}
|
|
42
|
-
function numberValue(value, fallback = DEFAULT_POSITION) {
|
|
43
|
-
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
44
|
-
}
|
|
45
|
-
function readCategoryMeta(categoryPath, fallbackTitle, position = DEFAULT_POSITION) {
|
|
46
|
-
const metaPath = path.join(categoryPath, "_category.json");
|
|
47
|
-
if (!fs.existsSync(
|
|
48
|
-
/* turbopackIgnore: true */
|
|
49
|
-
metaPath
|
|
50
|
-
)) {
|
|
51
|
-
return { title: fallbackTitle, position };
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
const parsed = JSON.parse(
|
|
55
|
-
fs.readFileSync(
|
|
56
|
-
/* turbopackIgnore: true */
|
|
57
|
-
metaPath,
|
|
58
|
-
"utf8"
|
|
59
|
-
)
|
|
60
|
-
);
|
|
61
|
-
if (!isRecord(parsed)) {
|
|
62
|
-
return { title: fallbackTitle, position };
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
title: stringValue(parsed.title, fallbackTitle),
|
|
66
|
-
position: numberValue(parsed.sidebar_position, position)
|
|
67
|
-
};
|
|
68
|
-
} catch {
|
|
69
|
-
return { title: fallbackTitle, position };
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function findDocumentFiles(directory) {
|
|
73
|
-
const entries = fs.readdirSync(
|
|
74
|
-
/* turbopackIgnore: true */
|
|
75
|
-
directory,
|
|
76
|
-
{ withFileTypes: true }
|
|
77
|
-
).sort((a, b) => a.name.localeCompare(b.name));
|
|
78
|
-
return entries.flatMap((entry) => {
|
|
79
|
-
const entryPath = path.join(directory, entry.name);
|
|
80
|
-
if (entry.isDirectory()) return findDocumentFiles(entryPath);
|
|
81
|
-
if (entry.isFile() && documentExtension.test(entry.name)) return [entryPath];
|
|
82
|
-
return [];
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
function matchingEntries(directory, name, folders) {
|
|
86
|
-
if (!fs.existsSync(
|
|
87
|
-
/* turbopackIgnore: true */
|
|
88
|
-
directory
|
|
89
|
-
)) return [];
|
|
90
|
-
return fs.readdirSync(
|
|
91
|
-
/* turbopackIgnore: true */
|
|
92
|
-
directory,
|
|
93
|
-
{ withFileTypes: true }
|
|
94
|
-
).flatMap((entry) => {
|
|
95
|
-
if (folders ? !entry.isDirectory() : !entry.isFile() || !documentExtension.test(entry.name))
|
|
96
|
-
return [];
|
|
97
|
-
const candidate = folders ? entry.name : entry.name.replace(documentExtension, "");
|
|
98
|
-
return orderedName(candidate).name === name ? [path.join(directory, entry.name)] : [];
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
function isSafeSlug(slug) {
|
|
102
|
-
if (path.isAbsolute(slug) || slug.includes("\\")) return false;
|
|
103
|
-
return slug.split("/").every((segment) => segment && segment !== "." && segment !== "..");
|
|
104
|
-
}
|
|
105
|
-
function getDocsIndex({ docsDir, fallbackDocsDir, fallbackOnly } = {}, onError) {
|
|
106
|
-
if (fallbackOnly)
|
|
107
|
-
return getDocsIndex({ docsDir: fallbackDocsDir ?? docsDir }, onError);
|
|
108
|
-
if (fallbackDocsDir) {
|
|
109
|
-
const primary = getDocsIndex({ docsDir: fallbackDocsDir }, onError);
|
|
110
|
-
const translated = getDocsIndex({ docsDir }, onError);
|
|
111
|
-
const pages = new Map(
|
|
112
|
-
translated.flatMap(
|
|
113
|
-
(category) => category.pages.map((page) => [page.slug, page])
|
|
114
|
-
)
|
|
115
|
-
);
|
|
116
|
-
const translatedRoot = getDocsRoot(docsDir);
|
|
117
|
-
return primary.map((category) => ({
|
|
118
|
-
...category,
|
|
119
|
-
title: readCategoryMeta(
|
|
120
|
-
category.id === "_root" ? translatedRoot : matchingEntries(translatedRoot, category.id, true)[0] ?? path.join(translatedRoot, category.id),
|
|
121
|
-
category.title
|
|
122
|
-
).title,
|
|
123
|
-
pages: category.pages.map((page) => ({
|
|
124
|
-
...pages.get(page.slug) ?? page,
|
|
125
|
-
position: page.position
|
|
126
|
-
}))
|
|
127
|
-
}));
|
|
128
|
-
}
|
|
129
|
-
const docsRoot = getDocsRoot(docsDir);
|
|
130
|
-
if (!fs.existsSync(
|
|
131
|
-
/* turbopackIgnore: true */
|
|
132
|
-
docsRoot
|
|
133
|
-
)) return [];
|
|
134
|
-
const categories = /* @__PURE__ */ new Map();
|
|
135
|
-
const slugs = /* @__PURE__ */ new Map();
|
|
136
|
-
for (const filePath of findDocumentFiles(docsRoot)) {
|
|
137
|
-
const slug = slugFromRelativePath(path.relative(docsRoot, filePath));
|
|
138
|
-
const previous = slugs.get(slug);
|
|
139
|
-
if (previous) {
|
|
140
|
-
const error = new Error(
|
|
141
|
-
`[RDX] Duplicate documentation route "${slug}": ${previous} and ${filePath}. Keep one page per route.`
|
|
142
|
-
);
|
|
143
|
-
if (!onError) throw error;
|
|
144
|
-
onError(error, filePath);
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
slugs.set(slug, filePath);
|
|
148
|
-
const relativePath = path.relative(docsRoot, filePath);
|
|
149
|
-
const pathParts = relativePath.split(path.sep);
|
|
150
|
-
const categoryFolder = pathParts.length > 1 ? pathParts[0] ?? "_root" : "_root";
|
|
151
|
-
const { name: categoryId, position: categoryPosition } = orderedName(categoryFolder);
|
|
152
|
-
const categoryPath = categoryFolder === "_root" ? docsRoot : path.join(docsRoot, categoryFolder);
|
|
153
|
-
const fallbackCategoryTitle = categoryId === "_root" ? "Overview" : toTitle(categoryId);
|
|
154
|
-
let category = categories.get(categoryId);
|
|
155
|
-
if (!category) {
|
|
156
|
-
const meta = readCategoryMeta(
|
|
157
|
-
categoryPath,
|
|
158
|
-
fallbackCategoryTitle,
|
|
159
|
-
categoryPosition
|
|
160
|
-
);
|
|
161
|
-
const createdCategory = {
|
|
162
|
-
id: categoryId,
|
|
163
|
-
title: meta.title,
|
|
164
|
-
position: meta.position,
|
|
165
|
-
pages: [],
|
|
166
|
-
categoryPath
|
|
167
|
-
};
|
|
168
|
-
categories.set(categoryId, createdCategory);
|
|
169
|
-
category = createdCategory;
|
|
170
|
-
}
|
|
171
|
-
let frontmatter = {};
|
|
172
|
-
try {
|
|
173
|
-
const raw = fs.readFileSync(
|
|
174
|
-
/* turbopackIgnore: true */
|
|
175
|
-
filePath,
|
|
176
|
-
"utf8"
|
|
177
|
-
);
|
|
178
|
-
const parsed = onError ? parseStaticDocument(raw) : matter2(raw);
|
|
179
|
-
frontmatter = isRecord(parsed.data) ? parsed.data : {};
|
|
180
|
-
} catch (error) {
|
|
181
|
-
if (!onError) throw error;
|
|
182
|
-
onError(error, filePath);
|
|
183
|
-
}
|
|
184
|
-
const fallbackTitle = toTitle(path.basename(slug));
|
|
185
|
-
const navTitle = stringValue(frontmatter.navTitle, "");
|
|
186
|
-
const filePosition = orderedName(
|
|
187
|
-
path.basename(relativePath).replace(documentExtension, "")
|
|
188
|
-
).position;
|
|
189
|
-
category.pages.push({
|
|
190
|
-
slug,
|
|
191
|
-
title: stringValue(frontmatter.title, fallbackTitle),
|
|
192
|
-
...navTitle ? { navTitle } : {},
|
|
193
|
-
description: stringValue(frontmatter.description, ""),
|
|
194
|
-
position: numberValue(
|
|
195
|
-
frontmatter.order,
|
|
196
|
-
numberValue(frontmatter.link_position, filePosition)
|
|
197
|
-
),
|
|
198
|
-
sourcePath: filePath
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
return [...categories.values()].map(({ categoryPath: _categoryPath, ...category }) => ({
|
|
202
|
-
...category,
|
|
203
|
-
pages: category.pages.sort(
|
|
204
|
-
(first, second) => first.position - second.position || first.slug.localeCompare(second.slug)
|
|
205
|
-
)
|
|
206
|
-
})).sort(
|
|
207
|
-
(first, second) => first.position - second.position || first.title.localeCompare(second.title)
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
function getDocsPaths(options) {
|
|
211
|
-
return getDocsIndex(options).flatMap(
|
|
212
|
-
(category) => category.pages.map((page) => page.slug)
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
function getDocument(slug, { docsDir, fallbackDocsDir, fallbackOnly } = {}) {
|
|
216
|
-
if (!isSafeSlug(slug)) return null;
|
|
217
|
-
if (fallbackOnly)
|
|
218
|
-
return getDocument(slug, { docsDir: fallbackDocsDir ?? docsDir });
|
|
219
|
-
const docsRoot = getDocsRoot(docsDir);
|
|
220
|
-
const parts = slug.split("/");
|
|
221
|
-
const name = parts.pop();
|
|
222
|
-
let directories = [docsRoot];
|
|
223
|
-
for (const part of parts)
|
|
224
|
-
directories = directories.flatMap(
|
|
225
|
-
(directory) => matchingEntries(directory, part, true)
|
|
226
|
-
);
|
|
227
|
-
const candidates = directories.flatMap(
|
|
228
|
-
(directory) => matchingEntries(directory, name, false)
|
|
229
|
-
);
|
|
230
|
-
if (candidates.length > 1)
|
|
231
|
-
throw new Error(
|
|
232
|
-
`[RDX] Duplicate documentation route "${slug}": ${candidates.join(" and ")}. Keep one page per route.`
|
|
233
|
-
);
|
|
234
|
-
if (fallbackDocsDir && !getDocument(slug, { docsDir: fallbackDocsDir }))
|
|
235
|
-
return null;
|
|
236
|
-
const sourcePath = candidates[0];
|
|
237
|
-
if (!sourcePath)
|
|
238
|
-
return fallbackDocsDir ? getDocument(slug, { docsDir: fallbackDocsDir }) : null;
|
|
239
|
-
const parsed = matter2(
|
|
240
|
-
fs.readFileSync(
|
|
241
|
-
/* turbopackIgnore: true */
|
|
242
|
-
sourcePath,
|
|
243
|
-
"utf8"
|
|
244
|
-
)
|
|
245
|
-
);
|
|
246
|
-
return {
|
|
247
|
-
slug,
|
|
248
|
-
sourcePath,
|
|
249
|
-
content: parsed.content,
|
|
250
|
-
frontmatter: isRecord(parsed.data) ? parsed.data : {}
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// src/project/index.ts
|
|
255
|
-
import path2 from "path";
|
|
256
|
-
function getSourceOptions(project, source) {
|
|
257
|
-
return {
|
|
258
|
-
docsDir: path2.resolve(project.rootDir, source.docsDir),
|
|
259
|
-
...source.fallbackOnly ? { fallbackOnly: true } : {},
|
|
260
|
-
...source.fallbackDocsDir ? {
|
|
261
|
-
fallbackDocsDir: path2.resolve(
|
|
262
|
-
project.rootDir,
|
|
263
|
-
source.fallbackDocsDir
|
|
264
|
-
)
|
|
265
|
-
} : {}
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
function resolveDocsRoute(project, segments = []) {
|
|
269
|
-
const source = project.sources.find(
|
|
270
|
-
(entry) => entry.routePrefix && entry.routePrefix === segments[0]
|
|
271
|
-
) ?? project.sources[0];
|
|
272
|
-
const options = getSourceOptions(project, source);
|
|
273
|
-
const slug = (source.routePrefix ? segments.slice(1) : segments).join("/") || getDocsPaths(options)[0];
|
|
274
|
-
return {
|
|
275
|
-
source,
|
|
276
|
-
slug,
|
|
277
|
-
document: slug ? getDocument(slug, options) : null,
|
|
278
|
-
categories: getDocsIndex(options)
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
function getProjectDocsPaths(project) {
|
|
282
|
-
const paths = /* @__PURE__ */ new Set();
|
|
283
|
-
for (const source of project.sources) {
|
|
284
|
-
if (source.redirectTo !== void 0) continue;
|
|
285
|
-
for (const slug of getDocsPaths(getSourceOptions(project, source))) {
|
|
286
|
-
const route = [source.routePrefix, slug].filter(Boolean).join("/");
|
|
287
|
-
if (paths.has(route))
|
|
288
|
-
throw new Error(`Conflicting documentation route: /docs/${route}`);
|
|
289
|
-
if (!source.routePrefix && project.sources.some(
|
|
290
|
-
(other) => other.routePrefix === slug.split("/")[0]
|
|
291
|
-
)) {
|
|
292
|
-
throw new Error(
|
|
293
|
-
`Live documentation route /docs/${slug} conflicts with a plugin content source.`
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
paths.add(route);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return [...paths];
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export {
|
|
303
|
-
parseStaticDocument,
|
|
304
|
-
getDocsIndex,
|
|
305
|
-
getDocsPaths,
|
|
306
|
-
getDocument,
|
|
307
|
-
getSourceOptions,
|
|
308
|
-
resolveDocsRoute,
|
|
309
|
-
getProjectDocsPaths
|
|
310
|
-
};
|