@lexibase/rdx-core 2.2.0 → 3.0.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/check/index.js +3 -3
- package/dist/{chunk-J7VCQHSL.js → chunk-6WNFE2QG.js} +15 -1
- package/dist/chunk-GBW4LSBN.js +312 -0
- package/dist/{chunk-GYLAW7YX.js → chunk-GSIKV6MV.js} +29 -4
- package/dist/{chunk-M32EH5KP.js → chunk-J674JOK2.js} +57 -36
- package/dist/{chunk-36CTLWNI.js → chunk-L7FZDK6G.js} +34 -11
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +3 -1
- package/dist/{document-links-B9zsPsqx.d.ts → document-links-fo6ul9xz.d.ts} +1 -0
- package/dist/{index-DjuvW7o_.d.ts → index-2qiAhOwp.d.ts} +3 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -9
- package/dist/mdx/index.d.ts +6 -2
- package/dist/mdx/index.js +3973 -33
- package/dist/search/index.js +2 -2
- package/package.json +5 -4
package/dist/check/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
getDocsIndex,
|
|
3
3
|
getSourceOptions,
|
|
4
4
|
parseStaticDocument
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-GBW4LSBN.js";
|
|
6
6
|
import {
|
|
7
7
|
getContentSources,
|
|
8
8
|
isFallbackPage
|
|
@@ -10,13 +10,13 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
RdxDocumentLinkError,
|
|
12
12
|
createDocumentLinkResolver
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-L7FZDK6G.js";
|
|
14
14
|
import {
|
|
15
15
|
headingText
|
|
16
16
|
} from "../chunk-FPBRKD4M.js";
|
|
17
17
|
import {
|
|
18
18
|
remarkDocumentationComponents
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-6WNFE2QG.js";
|
|
20
20
|
|
|
21
21
|
// src/check/index.ts
|
|
22
22
|
import fs from "fs";
|
|
@@ -134,6 +134,18 @@ function container(node, source) {
|
|
|
134
134
|
)
|
|
135
135
|
]);
|
|
136
136
|
}
|
|
137
|
+
if (node.name === "steps") {
|
|
138
|
+
return component(
|
|
139
|
+
"Steps",
|
|
140
|
+
{},
|
|
141
|
+
groups.map(
|
|
142
|
+
(group) => component("Step", {}, [
|
|
143
|
+
component("StepTitle", {}, [{ type: "text", value: group.title }]),
|
|
144
|
+
...group.children
|
|
145
|
+
])
|
|
146
|
+
)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
137
149
|
return component(
|
|
138
150
|
"Accordion",
|
|
139
151
|
{},
|
|
@@ -157,7 +169,9 @@ function remarkDocumentationComponents() {
|
|
|
157
169
|
if (["containerDirective", "leafDirective", "textDirective"].includes(
|
|
158
170
|
node.type
|
|
159
171
|
)) {
|
|
160
|
-
const known = ["tabs", "accordion", "kbd"].includes(
|
|
172
|
+
const known = ["tabs", "accordion", "steps", "kbd"].includes(
|
|
173
|
+
node.name ?? ""
|
|
174
|
+
);
|
|
161
175
|
if (!known) {
|
|
162
176
|
const value = source.slice(
|
|
163
177
|
node.position?.start.offset,
|
|
@@ -0,0 +1,312 @@
|
|
|
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 { highlighting } = frontmatter;
|
|
187
|
+
const filePosition = orderedName(
|
|
188
|
+
path.basename(relativePath).replace(documentExtension, "")
|
|
189
|
+
).position;
|
|
190
|
+
category.pages.push({
|
|
191
|
+
slug,
|
|
192
|
+
title: stringValue(frontmatter.title, fallbackTitle),
|
|
193
|
+
...navTitle ? { navTitle } : {},
|
|
194
|
+
...highlighting === "important" || highlighting === "new" ? { highlighting } : {},
|
|
195
|
+
description: stringValue(frontmatter.description, ""),
|
|
196
|
+
position: numberValue(
|
|
197
|
+
frontmatter.order,
|
|
198
|
+
numberValue(frontmatter.link_position, filePosition)
|
|
199
|
+
),
|
|
200
|
+
sourcePath: filePath
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return [...categories.values()].map(({ categoryPath: _categoryPath, ...category }) => ({
|
|
204
|
+
...category,
|
|
205
|
+
pages: category.pages.sort(
|
|
206
|
+
(first, second) => first.position - second.position || first.slug.localeCompare(second.slug)
|
|
207
|
+
)
|
|
208
|
+
})).sort(
|
|
209
|
+
(first, second) => first.position - second.position || first.title.localeCompare(second.title)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
function getDocsPaths(options) {
|
|
213
|
+
return getDocsIndex(options).flatMap(
|
|
214
|
+
(category) => category.pages.map((page) => page.slug)
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
function getDocument(slug, { docsDir, fallbackDocsDir, fallbackOnly } = {}) {
|
|
218
|
+
if (!isSafeSlug(slug)) return null;
|
|
219
|
+
if (fallbackOnly)
|
|
220
|
+
return getDocument(slug, { docsDir: fallbackDocsDir ?? docsDir });
|
|
221
|
+
const docsRoot = getDocsRoot(docsDir);
|
|
222
|
+
const parts = slug.split("/");
|
|
223
|
+
const name = parts.pop();
|
|
224
|
+
let directories = [docsRoot];
|
|
225
|
+
for (const part of parts)
|
|
226
|
+
directories = directories.flatMap(
|
|
227
|
+
(directory) => matchingEntries(directory, part, true)
|
|
228
|
+
);
|
|
229
|
+
const candidates = directories.flatMap(
|
|
230
|
+
(directory) => matchingEntries(directory, name, false)
|
|
231
|
+
);
|
|
232
|
+
if (candidates.length > 1)
|
|
233
|
+
throw new Error(
|
|
234
|
+
`[RDX] Duplicate documentation route "${slug}": ${candidates.join(" and ")}. Keep one page per route.`
|
|
235
|
+
);
|
|
236
|
+
if (fallbackDocsDir && !getDocument(slug, { docsDir: fallbackDocsDir }))
|
|
237
|
+
return null;
|
|
238
|
+
const sourcePath = candidates[0];
|
|
239
|
+
if (!sourcePath)
|
|
240
|
+
return fallbackDocsDir ? getDocument(slug, { docsDir: fallbackDocsDir }) : null;
|
|
241
|
+
const parsed = matter2(
|
|
242
|
+
fs.readFileSync(
|
|
243
|
+
/* turbopackIgnore: true */
|
|
244
|
+
sourcePath,
|
|
245
|
+
"utf8"
|
|
246
|
+
)
|
|
247
|
+
);
|
|
248
|
+
return {
|
|
249
|
+
slug,
|
|
250
|
+
sourcePath,
|
|
251
|
+
content: parsed.content,
|
|
252
|
+
frontmatter: isRecord(parsed.data) ? parsed.data : {}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// src/project/index.ts
|
|
257
|
+
import path2 from "path";
|
|
258
|
+
function getSourceOptions(project, source) {
|
|
259
|
+
return {
|
|
260
|
+
docsDir: path2.resolve(project.rootDir, source.docsDir),
|
|
261
|
+
...source.fallbackOnly ? { fallbackOnly: true } : {},
|
|
262
|
+
...source.fallbackDocsDir ? {
|
|
263
|
+
fallbackDocsDir: path2.resolve(
|
|
264
|
+
project.rootDir,
|
|
265
|
+
source.fallbackDocsDir
|
|
266
|
+
)
|
|
267
|
+
} : {}
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
function resolveDocsRoute(project, segments = []) {
|
|
271
|
+
const source = project.sources.find(
|
|
272
|
+
(entry) => entry.routePrefix && entry.routePrefix === segments[0]
|
|
273
|
+
) ?? project.sources[0];
|
|
274
|
+
const options = getSourceOptions(project, source);
|
|
275
|
+
const slug = (source.routePrefix ? segments.slice(1) : segments).join("/") || getDocsPaths(options)[0];
|
|
276
|
+
return {
|
|
277
|
+
source,
|
|
278
|
+
slug,
|
|
279
|
+
document: slug ? getDocument(slug, options) : null,
|
|
280
|
+
categories: getDocsIndex(options)
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function getProjectDocsPaths(project) {
|
|
284
|
+
const paths = /* @__PURE__ */ new Set();
|
|
285
|
+
for (const source of project.sources) {
|
|
286
|
+
if (source.redirectTo !== void 0) continue;
|
|
287
|
+
for (const slug of getDocsPaths(getSourceOptions(project, source))) {
|
|
288
|
+
const route = [source.routePrefix, slug].filter(Boolean).join("/");
|
|
289
|
+
if (paths.has(route))
|
|
290
|
+
throw new Error(`Conflicting documentation route: /docs/${route}`);
|
|
291
|
+
if (!source.routePrefix && project.sources.some(
|
|
292
|
+
(other) => other.routePrefix === slug.split("/")[0]
|
|
293
|
+
)) {
|
|
294
|
+
throw new Error(
|
|
295
|
+
`Live documentation route /docs/${slug} conflicts with a plugin content source.`
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
paths.add(route);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return [...paths];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export {
|
|
305
|
+
parseStaticDocument,
|
|
306
|
+
getDocsIndex,
|
|
307
|
+
getDocsPaths,
|
|
308
|
+
getDocument,
|
|
309
|
+
getSourceOptions,
|
|
310
|
+
resolveDocsRoute,
|
|
311
|
+
getProjectDocsPaths
|
|
312
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/config/index.ts
|
|
2
|
-
import
|
|
2
|
+
import path6 from "path";
|
|
3
3
|
import { existsSync, readdirSync } from "fs";
|
|
4
4
|
|
|
5
5
|
// src/config/error.ts
|
|
@@ -565,6 +565,19 @@ function collectSnapshotContributions(context, options) {
|
|
|
565
565
|
};
|
|
566
566
|
}
|
|
567
567
|
|
|
568
|
+
// src/config/edit-page.ts
|
|
569
|
+
import path5 from "path";
|
|
570
|
+
function getEditPageHref(project, source, sourcePath) {
|
|
571
|
+
const editPage = project.config.editPage;
|
|
572
|
+
if (!editPage || source?.id !== "current") return;
|
|
573
|
+
const relative = path5.relative(project.rootDir, sourcePath);
|
|
574
|
+
const segments = relative.split(path5.sep);
|
|
575
|
+
if (!relative || path5.isAbsolute(relative) || segments[0] === "..") return;
|
|
576
|
+
const url = new URL(editPage.baseUrl);
|
|
577
|
+
url.pathname = `${url.pathname.replace(/\/+$/, "")}/${segments.map(encodeURIComponent).join("/")}`;
|
|
578
|
+
return url.href;
|
|
579
|
+
}
|
|
580
|
+
|
|
568
581
|
// src/config/index.ts
|
|
569
582
|
function record(value) {
|
|
570
583
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -618,7 +631,8 @@ function resolveConfig(input) {
|
|
|
618
631
|
"plugins",
|
|
619
632
|
"homepage",
|
|
620
633
|
"TOC",
|
|
621
|
-
"search"
|
|
634
|
+
"search",
|
|
635
|
+
"editPage"
|
|
622
636
|
],
|
|
623
637
|
""
|
|
624
638
|
);
|
|
@@ -630,6 +644,16 @@ function resolveConfig(input) {
|
|
|
630
644
|
text(config.description, "description", true);
|
|
631
645
|
if (config.lang !== void 0) text(config.lang, "lang");
|
|
632
646
|
validateMetadata(config.metadata);
|
|
647
|
+
if (config.editPage !== void 0 && config.editPage !== false) {
|
|
648
|
+
const editPage = object(config.editPage, "editPage");
|
|
649
|
+
keys(editPage, ["baseUrl"], "editPage.");
|
|
650
|
+
const value = text(editPage.baseUrl, "editPage.baseUrl");
|
|
651
|
+
const url = URL.parse(value);
|
|
652
|
+
if (!/^https?:\/\//i.test(value) || /[\s\\?#]/.test(value) || !url || url.username || url.password)
|
|
653
|
+
throw new RdxConfigError(
|
|
654
|
+
"editPage.baseUrl must be an absolute HTTP(S) edit URL without credentials, a query, or a fragment."
|
|
655
|
+
);
|
|
656
|
+
}
|
|
633
657
|
if (config.homepage !== void 0) {
|
|
634
658
|
const homepage = object(config.homepage, "homepage");
|
|
635
659
|
keys(
|
|
@@ -754,7 +778,7 @@ async function createRdxProject(input, {
|
|
|
754
778
|
rootDir = process.cwd(),
|
|
755
779
|
command = "runtime"
|
|
756
780
|
} = {}) {
|
|
757
|
-
rootDir =
|
|
781
|
+
rootDir = path6.resolve(
|
|
758
782
|
/* turbopackIgnore: true */
|
|
759
783
|
rootDir
|
|
760
784
|
);
|
|
@@ -830,7 +854,7 @@ async function createRdxProject(input, {
|
|
|
830
854
|
const field = `plugin "${plugin.name}" runtimeFiles`;
|
|
831
855
|
const filename = text(value, field);
|
|
832
856
|
const resolved = resolveProjectPath(rootDir, filename, field);
|
|
833
|
-
runtimeFiles.add(
|
|
857
|
+
runtimeFiles.add(path6.relative(rootDir, resolved));
|
|
834
858
|
}
|
|
835
859
|
}
|
|
836
860
|
if (contribution.sources === void 0) continue;
|
|
@@ -941,6 +965,7 @@ export {
|
|
|
941
965
|
normalizeLocalization,
|
|
942
966
|
resolveProjectPath,
|
|
943
967
|
collectSnapshotContributions,
|
|
968
|
+
getEditPageHref,
|
|
944
969
|
resolveConfig,
|
|
945
970
|
defineConfig,
|
|
946
971
|
createRdxProject
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_POSITION,
|
|
3
|
+
documentExtension,
|
|
4
|
+
orderedName,
|
|
5
|
+
slugFromRelativePath
|
|
6
|
+
} from "./chunk-L7FZDK6G.js";
|
|
7
|
+
|
|
1
8
|
// src/content/static-source.ts
|
|
2
9
|
import matter from "gray-matter";
|
|
3
10
|
function parseStaticDocument(source) {
|
|
@@ -16,9 +23,6 @@ function parseStaticDocument(source) {
|
|
|
16
23
|
import fs from "fs";
|
|
17
24
|
import path from "path";
|
|
18
25
|
import matter2 from "gray-matter";
|
|
19
|
-
var DOCUMENT_EXTENSIONS = [".md", ".mdx"];
|
|
20
|
-
var documentExtension = /\.mdx?$/;
|
|
21
|
-
var DEFAULT_POSITION = Number.MAX_SAFE_INTEGER;
|
|
22
26
|
function getDocsRoot(docsDir = "docs") {
|
|
23
27
|
return path.resolve(
|
|
24
28
|
/* turbopackIgnore: true */
|
|
@@ -38,13 +42,13 @@ function stringValue(value, fallback) {
|
|
|
38
42
|
function numberValue(value, fallback = DEFAULT_POSITION) {
|
|
39
43
|
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
40
44
|
}
|
|
41
|
-
function readCategoryMeta(categoryPath, fallbackTitle) {
|
|
45
|
+
function readCategoryMeta(categoryPath, fallbackTitle, position = DEFAULT_POSITION) {
|
|
42
46
|
const metaPath = path.join(categoryPath, "_category.json");
|
|
43
47
|
if (!fs.existsSync(
|
|
44
48
|
/* turbopackIgnore: true */
|
|
45
49
|
metaPath
|
|
46
50
|
)) {
|
|
47
|
-
return { title: fallbackTitle, position
|
|
51
|
+
return { title: fallbackTitle, position };
|
|
48
52
|
}
|
|
49
53
|
try {
|
|
50
54
|
const parsed = JSON.parse(
|
|
@@ -55,14 +59,14 @@ function readCategoryMeta(categoryPath, fallbackTitle) {
|
|
|
55
59
|
)
|
|
56
60
|
);
|
|
57
61
|
if (!isRecord(parsed)) {
|
|
58
|
-
return { title: fallbackTitle, position
|
|
62
|
+
return { title: fallbackTitle, position };
|
|
59
63
|
}
|
|
60
64
|
return {
|
|
61
65
|
title: stringValue(parsed.title, fallbackTitle),
|
|
62
|
-
position: numberValue(parsed.sidebar_position)
|
|
66
|
+
position: numberValue(parsed.sidebar_position, position)
|
|
63
67
|
};
|
|
64
68
|
} catch {
|
|
65
|
-
return { title: fallbackTitle, position
|
|
69
|
+
return { title: fallbackTitle, position };
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
function findDocumentFiles(directory) {
|
|
@@ -78,8 +82,21 @@ function findDocumentFiles(directory) {
|
|
|
78
82
|
return [];
|
|
79
83
|
});
|
|
80
84
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
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
|
+
});
|
|
83
100
|
}
|
|
84
101
|
function isSafeSlug(slug) {
|
|
85
102
|
if (path.isAbsolute(slug) || slug.includes("\\")) return false;
|
|
@@ -96,13 +113,11 @@ function getDocsIndex({ docsDir, fallbackDocsDir, fallbackOnly } = {}, onError)
|
|
|
96
113
|
(category) => category.pages.map((page) => [page.slug, page])
|
|
97
114
|
)
|
|
98
115
|
);
|
|
116
|
+
const translatedRoot = getDocsRoot(docsDir);
|
|
99
117
|
return primary.map((category) => ({
|
|
100
118
|
...category,
|
|
101
119
|
title: readCategoryMeta(
|
|
102
|
-
path.join(
|
|
103
|
-
getDocsRoot(docsDir),
|
|
104
|
-
category.id === "_root" ? "" : category.id
|
|
105
|
-
),
|
|
120
|
+
category.id === "_root" ? translatedRoot : matchingEntries(translatedRoot, category.id, true)[0] ?? path.join(translatedRoot, category.id),
|
|
106
121
|
category.title
|
|
107
122
|
).title,
|
|
108
123
|
pages: category.pages.map((page) => ({
|
|
@@ -132,12 +147,17 @@ function getDocsIndex({ docsDir, fallbackDocsDir, fallbackOnly } = {}, onError)
|
|
|
132
147
|
slugs.set(slug, filePath);
|
|
133
148
|
const relativePath = path.relative(docsRoot, filePath);
|
|
134
149
|
const pathParts = relativePath.split(path.sep);
|
|
135
|
-
const
|
|
136
|
-
const
|
|
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);
|
|
137
153
|
const fallbackCategoryTitle = categoryId === "_root" ? "Overview" : toTitle(categoryId);
|
|
138
154
|
let category = categories.get(categoryId);
|
|
139
155
|
if (!category) {
|
|
140
|
-
const meta = readCategoryMeta(
|
|
156
|
+
const meta = readCategoryMeta(
|
|
157
|
+
categoryPath,
|
|
158
|
+
fallbackCategoryTitle,
|
|
159
|
+
categoryPosition
|
|
160
|
+
);
|
|
141
161
|
const createdCategory = {
|
|
142
162
|
id: categoryId,
|
|
143
163
|
title: meta.title,
|
|
@@ -162,11 +182,19 @@ function getDocsIndex({ docsDir, fallbackDocsDir, fallbackOnly } = {}, onError)
|
|
|
162
182
|
onError(error, filePath);
|
|
163
183
|
}
|
|
164
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;
|
|
165
189
|
category.pages.push({
|
|
166
190
|
slug,
|
|
167
191
|
title: stringValue(frontmatter.title, fallbackTitle),
|
|
192
|
+
...navTitle ? { navTitle } : {},
|
|
168
193
|
description: stringValue(frontmatter.description, ""),
|
|
169
|
-
position: numberValue(
|
|
194
|
+
position: numberValue(
|
|
195
|
+
frontmatter.order,
|
|
196
|
+
numberValue(frontmatter.link_position, filePosition)
|
|
197
|
+
),
|
|
170
198
|
sourcePath: filePath
|
|
171
199
|
});
|
|
172
200
|
}
|
|
@@ -189,31 +217,24 @@ function getDocument(slug, { docsDir, fallbackDocsDir, fallbackOnly } = {}) {
|
|
|
189
217
|
if (fallbackOnly)
|
|
190
218
|
return getDocument(slug, { docsDir: fallbackDocsDir ?? docsDir });
|
|
191
219
|
const docsRoot = getDocsRoot(docsDir);
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
).isFile()
|
|
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)
|
|
202
229
|
);
|
|
203
230
|
if (candidates.length > 1)
|
|
204
231
|
throw new Error(
|
|
205
232
|
`[RDX] Duplicate documentation route "${slug}": ${candidates.join(" and ")}. Keep one page per route.`
|
|
206
233
|
);
|
|
207
|
-
const sourcePath = candidates[0] ?? path.resolve(docsRoot, `${slug}.mdx`);
|
|
208
|
-
const relativePath = path.relative(docsRoot, sourcePath);
|
|
209
|
-
if (relativePath.startsWith("..") || path.isAbsolute(relativePath))
|
|
210
|
-
return null;
|
|
211
234
|
if (fallbackDocsDir && !getDocument(slug, { docsDir: fallbackDocsDir }))
|
|
212
235
|
return null;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
sourcePath
|
|
216
|
-
))
|
|
236
|
+
const sourcePath = candidates[0];
|
|
237
|
+
if (!sourcePath)
|
|
217
238
|
return fallbackDocsDir ? getDocument(slug, { docsDir: fallbackDocsDir }) : null;
|
|
218
239
|
const parsed = matter2(
|
|
219
240
|
fs.readFileSync(
|