@lexibase/rdx-core 1.0.0-beta.6 → 1.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/README.md CHANGED
@@ -1,3 +1,10 @@
1
- # `@rdx/rdx-core`
1
+ # `@lexibase/rdx-core`
2
2
 
3
3
  Content RDX core.
4
+
5
+ Plugin setup may return `runtimeFiles: string[]` alongside `sources`. Each entry
6
+ names a project-relative file required when serving documentation, such as a
7
+ custom version manifest. Paths cannot be absolute, escape the project or name
8
+ the project root. Entries are deduplicated in `RdxProject.runtimeFiles`.
9
+ The Next adapter validates and explicitly includes these files in production
10
+ traces; undeclared unrelated files are not automatically deployment assets.
@@ -1,12 +1,132 @@
1
1
  // src/config/index.ts
2
2
  import path from "path";
3
3
  import { existsSync } from "fs";
4
+
5
+ // src/config/error.ts
4
6
  var RdxConfigError = class extends Error {
5
7
  constructor(message) {
6
8
  super(`Invalid rdx.config.ts: ${message}`);
7
9
  this.name = "RdxConfigError";
8
10
  }
9
11
  };
12
+
13
+ // src/config/metadata.ts
14
+ function validateMetadata(input) {
15
+ function string(value, field) {
16
+ if (typeof value !== "string" || !value.trim())
17
+ throw new RdxConfigError(`${field} must be a non-empty string.`);
18
+ return value;
19
+ }
20
+ function url(value, field, relative = false) {
21
+ const source = string(value, field);
22
+ try {
23
+ if (/[\s\\]/.test(source)) throw new Error();
24
+ if (relative && /^\/(?!\/)/.test(source)) return;
25
+ const parsed = new URL(source);
26
+ if (!["http:", "https:"].includes(parsed.protocol) || parsed.username || parsed.password)
27
+ throw new Error();
28
+ } catch {
29
+ throw new RdxConfigError(
30
+ `${field} must be ${relative ? "a root-relative path or " : ""}an absolute http(s) URL.`
31
+ );
32
+ }
33
+ }
34
+ function object2(value, field, allowed) {
35
+ if (!value || typeof value !== "object" || Array.isArray(value))
36
+ throw new RdxConfigError(`${field} must be an object.`);
37
+ const result = value;
38
+ for (const key of Object.keys(result))
39
+ if (!allowed.includes(key))
40
+ throw new RdxConfigError(`unknown option ${field}.${key}.`);
41
+ return result;
42
+ }
43
+ function array(value, field, validate) {
44
+ if (!Array.isArray(value))
45
+ throw new RdxConfigError(`${field} must be an array.`);
46
+ value.forEach((item, index) => validate(item, `${field}[${index}]`));
47
+ }
48
+ const metadata = object2(input, "metadata", [
49
+ "metadataBase",
50
+ "applicationName",
51
+ "authors",
52
+ "keywords",
53
+ "icons",
54
+ "manifest",
55
+ "robots",
56
+ "openGraph",
57
+ "twitter"
58
+ ]);
59
+ if (metadata.metadataBase !== void 0)
60
+ url(metadata.metadataBase, "metadata.metadataBase");
61
+ string(metadata.applicationName, "metadata.applicationName");
62
+ if (metadata.manifest !== void 0)
63
+ url(metadata.manifest, "metadata.manifest", true);
64
+ if (metadata.keywords !== void 0)
65
+ array(metadata.keywords, "metadata.keywords", string);
66
+ if (metadata.authors !== void 0)
67
+ array(metadata.authors, "metadata.authors", (value, field) => {
68
+ const author = object2(value, field, ["name", "url"]);
69
+ string(author.name, `${field}.name`);
70
+ if (author.url !== void 0) url(author.url, `${field}.url`);
71
+ });
72
+ if (metadata.icons !== void 0) {
73
+ const icons = object2(metadata.icons, "metadata.icons", [
74
+ "icon",
75
+ "shortcut",
76
+ "apple"
77
+ ]);
78
+ for (const [key, value] of Object.entries(icons)) {
79
+ if (value === void 0) continue;
80
+ const field = `metadata.icons.${key}`;
81
+ if (key === "icon" && Array.isArray(value))
82
+ array(value, field, (item, field2) => {
83
+ const icon = object2(item, field2, ["url", "sizes", "type"]);
84
+ url(icon.url, `${field2}.url`, true);
85
+ for (const key2 of ["sizes", "type"])
86
+ if (icon[key2] !== void 0) string(icon[key2], `${field2}.${key2}`);
87
+ });
88
+ else url(value, field, true);
89
+ }
90
+ }
91
+ if (metadata.robots !== void 0) {
92
+ const robots = object2(metadata.robots, "metadata.robots", [
93
+ "index",
94
+ "follow"
95
+ ]);
96
+ for (const [key, value] of Object.entries(robots))
97
+ if (value !== void 0 && typeof value !== "boolean")
98
+ throw new RdxConfigError(`metadata.robots.${key} must be a boolean.`);
99
+ }
100
+ for (const key of ["openGraph", "twitter"]) {
101
+ if (metadata[key] === void 0) continue;
102
+ const field = `metadata.${key}`;
103
+ const social = object2(
104
+ metadata[key],
105
+ field,
106
+ key === "openGraph" ? ["title", "description", "siteName", "locale", "type", "images"] : ["title", "description", "card", "site", "creator", "images"]
107
+ );
108
+ for (const [name, value] of Object.entries(social)) {
109
+ if (name === "images" || value === void 0) continue;
110
+ string(value, `${field}.${name}`);
111
+ if (name === "type" && value !== "website" || name === "card" && !["summary", "summary_large_image"].includes(value))
112
+ throw new RdxConfigError(`${field}.${name} has an unsupported value.`);
113
+ }
114
+ if (social.images !== void 0)
115
+ array(social.images, `${field}.images`, (value, field2) => {
116
+ if (key === "twitter") return url(value, field2, true);
117
+ const image = object2(value, field2, ["url", "width", "height", "alt"]);
118
+ url(image.url, `${field2}.url`, true);
119
+ if (image.alt !== void 0) string(image.alt, `${field2}.alt`);
120
+ for (const dimension of ["width", "height"])
121
+ if (image[dimension] !== void 0 && (typeof image[dimension] !== "number" || !Number.isInteger(image[dimension]) || image[dimension] <= 0))
122
+ throw new RdxConfigError(
123
+ `${field2}.${dimension} must be a positive integer.`
124
+ );
125
+ });
126
+ }
127
+ }
128
+
129
+ // src/config/index.ts
10
130
  function record(value) {
11
131
  return typeof value === "object" && value !== null && !Array.isArray(value);
12
132
  }
@@ -40,7 +160,11 @@ function keys(value, allowed, field) {
40
160
  }
41
161
  function resolveProjectPath(rootDir, value, field) {
42
162
  text(value, field);
43
- const resolved = path.resolve(rootDir, value);
163
+ const resolved = path.resolve(
164
+ /* turbopackIgnore: true */
165
+ rootDir,
166
+ value
167
+ );
44
168
  const relative = path.relative(rootDir, resolved);
45
169
  if (path.isAbsolute(value) || !relative || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
46
170
  throw new RdxConfigError(
@@ -51,25 +175,37 @@ function resolveProjectPath(rootDir, value, field) {
51
175
  }
52
176
  function resolveConfig(input) {
53
177
  const config = object(input, "default export");
178
+ if ("title" in config)
179
+ throw new RdxConfigError(
180
+ "title has been removed. Set the site name in metadata.applicationName instead."
181
+ );
182
+ if ("docsDir" in config)
183
+ throw new RdxConfigError(
184
+ "docsDir is not configurable. Live documentation must be stored in docs/."
185
+ );
54
186
  keys(
55
187
  config,
56
188
  [
57
- "title",
58
189
  "description",
190
+ "metadata",
59
191
  "lang",
60
- "docsDir",
61
192
  "theme",
62
193
  "navbar",
63
194
  "plugins",
64
- "homepage"
195
+ "homepage",
196
+ "TOC",
197
+ "search"
65
198
  ],
66
199
  ""
67
200
  );
68
- text(config.title, "title");
201
+ if (config.search !== void 0 && typeof config.search !== "boolean")
202
+ throw new RdxConfigError("search must be a boolean.");
203
+ if (config.TOC !== void 0 && typeof config.TOC !== "boolean")
204
+ throw new RdxConfigError("TOC must be a boolean.");
69
205
  if (config.description !== void 0)
70
206
  text(config.description, "description", true);
71
207
  if (config.lang !== void 0) text(config.lang, "lang");
72
- if (config.docsDir !== void 0) text(config.docsDir, "docsDir");
208
+ validateMetadata(config.metadata);
73
209
  if (config.homepage !== void 0) {
74
210
  const homepage = object(config.homepage, "homepage");
75
211
  keys(
@@ -171,9 +307,10 @@ function resolveConfig(input) {
171
307
  const typed = config;
172
308
  return {
173
309
  ...typed,
310
+ TOC: typed.TOC ?? false,
311
+ search: typed.search ?? false,
174
312
  description: typed.description ?? "",
175
313
  lang: typed.lang ?? "en",
176
- docsDir: typed.docsDir ?? "docs",
177
314
  theme: { defaultTheme: typed.theme?.defaultTheme ?? "system" },
178
315
  plugins: typed.plugins ?? []
179
316
  };
@@ -186,18 +323,26 @@ async function createRdxProject(input, {
186
323
  rootDir = process.cwd(),
187
324
  command = "runtime"
188
325
  } = {}) {
189
- rootDir = path.resolve(rootDir);
326
+ rootDir = path.resolve(
327
+ /* turbopackIgnore: true */
328
+ rootDir
329
+ );
190
330
  const config = resolveConfig(input);
191
- const docsRoot = resolveProjectPath(rootDir, config.docsDir, "docsDir");
331
+ const docsRoot = resolveProjectPath(
332
+ rootDir,
333
+ "docs",
334
+ "documentation directory"
335
+ );
192
336
  const sources = [
193
337
  {
194
338
  id: "current",
195
339
  label: "Current",
196
- docsDir: config.docsDir,
340
+ docsDir: "docs",
197
341
  routePrefix: ""
198
342
  }
199
343
  ];
200
344
  const commands = [];
345
+ const runtimeFiles = /* @__PURE__ */ new Set();
201
346
  const commandNames = /* @__PURE__ */ new Set([
202
347
  "dev",
203
348
  "build",
@@ -233,6 +378,18 @@ async function createRdxProject(input, {
233
378
  }
234
379
  if (result === void 0) continue;
235
380
  const contribution = object(result, `plugin "${plugin.name}" setup result`);
381
+ if (contribution.runtimeFiles !== void 0) {
382
+ if (!Array.isArray(contribution.runtimeFiles))
383
+ throw new RdxConfigError(
384
+ `plugin "${plugin.name}" runtimeFiles must be an array.`
385
+ );
386
+ for (const value of contribution.runtimeFiles) {
387
+ const field = `plugin "${plugin.name}" runtimeFiles`;
388
+ const filename = text(value, field);
389
+ const resolved = resolveProjectPath(rootDir, filename, field);
390
+ runtimeFiles.add(path.relative(rootDir, resolved));
391
+ }
392
+ }
236
393
  if (contribution.sources === void 0) continue;
237
394
  if (!Array.isArray(contribution.sources))
238
395
  throw new RdxConfigError(
@@ -258,7 +415,21 @@ async function createRdxProject(input, {
258
415
  `duplicate content source id or route prefix: ${id}.`
259
416
  );
260
417
  }
261
- if (existsSync(path.join(docsRoot, prefix)) || existsSync(path.join(docsRoot, `${prefix}.mdx`))) {
418
+ if (existsSync(
419
+ /* turbopackIgnore: true */
420
+ path.join(
421
+ /* turbopackIgnore: true */
422
+ docsRoot,
423
+ prefix
424
+ )
425
+ ) || existsSync(
426
+ /* turbopackIgnore: true */
427
+ path.join(
428
+ /* turbopackIgnore: true */
429
+ docsRoot,
430
+ `${prefix}.mdx`
431
+ )
432
+ )) {
262
433
  throw new RdxConfigError(
263
434
  `content source ${id} conflicts with live documentation at /docs/${prefix}.`
264
435
  );
@@ -268,7 +439,7 @@ async function createRdxProject(input, {
268
439
  sources.push(source);
269
440
  }
270
441
  }
271
- return { rootDir, config, sources, commands };
442
+ return { rootDir, config, sources, commands, runtimeFiles: [...runtimeFiles] };
272
443
  }
273
444
 
274
445
  export {
@@ -0,0 +1,107 @@
1
+ // src/content/document-links.ts
2
+ import path from "path";
3
+ var RdxDocumentLinkError = class extends Error {
4
+ constructor(sourcePath, href, reason) {
5
+ super(`[RDX] Invalid document link "${href}" in ${sourcePath}: ${reason}`);
6
+ this.name = "RdxDocumentLinkError";
7
+ }
8
+ };
9
+ function createDocumentLinkResolver(options) {
10
+ const root = path.resolve(options.sourceRoot);
11
+ const current = path.resolve(options.sourcePath);
12
+ const documents = new Map(
13
+ options.documents.map((page) => [path.resolve(page.sourcePath), page.slug])
14
+ );
15
+ const routeCounts = /* @__PURE__ */ new Map();
16
+ for (const page of options.documents)
17
+ routeCounts.set(page.slug, (routeCounts.get(page.slug) ?? 0) + 1);
18
+ return (href) => {
19
+ if (/^(?:[a-z][a-z\d+.-]*:|\/|#|\?)/i.test(href)) return href;
20
+ const suffixAt = href.search(/[?#]/);
21
+ const pathname = suffixAt < 0 ? href : href.slice(0, suffixAt);
22
+ const suffix = suffixAt < 0 ? "" : href.slice(suffixAt);
23
+ let decoded;
24
+ try {
25
+ decoded = decodeURIComponent(pathname);
26
+ } catch {
27
+ if (/\.mdx$/i.test(pathname))
28
+ throw new RdxDocumentLinkError(
29
+ current,
30
+ href,
31
+ "the path contains invalid URL encoding."
32
+ );
33
+ return href;
34
+ }
35
+ if (!decoded.endsWith(".mdx")) return href;
36
+ const fail = (reason) => {
37
+ throw new RdxDocumentLinkError(current, href, reason);
38
+ };
39
+ if (path.isAbsolute(decoded) || decoded.includes("\\") || decoded.includes("\0"))
40
+ fail("use forward-slash relative paths without null characters.");
41
+ const target = path.resolve(path.dirname(current), decoded);
42
+ const relative = path.relative(root, target);
43
+ if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))
44
+ fail("the destination escapes this documentation source.");
45
+ const slug = documents.get(target) ?? fail(
46
+ `"${relative}" does not exist in this documentation source${options.routePrefix ? ` (${options.routePrefix})` : ""}.`
47
+ );
48
+ if ((routeCounts.get(slug) ?? 0) > 1)
49
+ fail("the destination has an ambiguous documentation route.");
50
+ const route = [
51
+ "/docs",
52
+ options.routePrefix && encodeURIComponent(options.routePrefix),
53
+ ...slug.split("/").map(encodeURIComponent)
54
+ ].filter(Boolean).join("/");
55
+ return route + suffix;
56
+ };
57
+ }
58
+ function record(value) {
59
+ return value !== null && typeof value === "object";
60
+ }
61
+ function remarkDocumentLinks(options) {
62
+ if (!options) return;
63
+ const resolve = createDocumentLinkResolver(options);
64
+ return (tree) => {
65
+ const definitions = /* @__PURE__ */ new Map();
66
+ const identifier = (value) => value.trim().replace(/\s+/g, " ").toLowerCase();
67
+ const visit = (node, action) => {
68
+ if (!record(node)) return;
69
+ action(node);
70
+ if (Array.isArray(node.children))
71
+ for (const child of node.children) visit(child, action);
72
+ };
73
+ visit(tree, (node) => {
74
+ if (node.type === "definition" && typeof node.identifier === "string") {
75
+ const key = identifier(node.identifier);
76
+ if (!definitions.has(key)) definitions.set(key, node);
77
+ }
78
+ });
79
+ visit(tree, (node) => {
80
+ if (node.type === "link" && typeof node.url === "string")
81
+ node.url = resolve(node.url);
82
+ if (node.type === "linkReference" && typeof node.identifier === "string") {
83
+ const definition = definitions.get(identifier(node.identifier));
84
+ if (typeof definition?.url === "string") {
85
+ node.type = "link";
86
+ node.url = resolve(definition.url);
87
+ node.title = definition.title ?? null;
88
+ delete node.identifier;
89
+ delete node.referenceType;
90
+ delete node.label;
91
+ }
92
+ }
93
+ if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === "a" && Array.isArray(node.attributes)) {
94
+ for (const attribute of node.attributes) {
95
+ if (record(attribute) && attribute.type === "mdxJsxAttribute" && attribute.name === "href" && typeof attribute.value === "string")
96
+ attribute.value = resolve(attribute.value);
97
+ }
98
+ }
99
+ });
100
+ };
101
+ }
102
+
103
+ export {
104
+ RdxDocumentLinkError,
105
+ createDocumentLinkResolver,
106
+ remarkDocumentLinks
107
+ };
@@ -1,12 +1,13 @@
1
- import { RdxProject, RdxConfig, ResolvedRdxConfig } from '@lexibase/rdx-types';
1
+ import { RdxProject, RDXConfig, ResolvedRdxConfig } from '@lexibase/rdx-types';
2
2
 
3
3
  declare class RdxConfigError extends Error {
4
4
  constructor(message: string);
5
5
  }
6
+
6
7
  /** Resolve project-owned paths without allowing traversal or filesystem roots. */
7
8
  declare function resolveProjectPath(rootDir: string, value: string, field: string): string;
8
9
  declare function resolveConfig(input: unknown): ResolvedRdxConfig;
9
- declare function defineConfig(config: RdxConfig): RdxConfig;
10
+ declare function defineConfig(config: RDXConfig): RDXConfig;
10
11
  declare function createRdxProject(input: unknown, { rootDir, command, }?: {
11
12
  rootDir?: string;
12
13
  command?: string;
@@ -4,7 +4,7 @@ import {
4
4
  defineConfig,
5
5
  resolveConfig,
6
6
  resolveProjectPath
7
- } from "../chunk-OXVOM2JP.js";
7
+ } from "../chunk-X6YRBB2W.js";
8
8
  export {
9
9
  RdxConfigError,
10
10
  createRdxProject,
@@ -0,0 +1,19 @@
1
+ interface DocumentLinkOptions {
2
+ sourceRoot: string;
3
+ sourcePath: string;
4
+ routePrefix?: string;
5
+ documents: readonly {
6
+ sourcePath: string;
7
+ slug: string;
8
+ }[];
9
+ }
10
+ declare class RdxDocumentLinkError extends Error {
11
+ constructor(sourcePath: string, href: string, reason: string);
12
+ }
13
+ /** Resolve only explicit relative MDX links within the current content source. */
14
+ declare function createDocumentLinkResolver(options: DocumentLinkOptions): (href: string) => string;
15
+ /** A remark adapter shared by generated sites and the development website. */
16
+ declare function remarkDocumentLinks(options?: DocumentLinkOptions): ((tree: unknown) => void) | undefined;
17
+
18
+ export { RdxDocumentLinkError as R, createDocumentLinkResolver as c, remarkDocumentLinks as r };
19
+ export type { DocumentLinkOptions as D };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as _lexibase_rdx_types from '@lexibase/rdx-types';
2
2
  import { RdxDocsOptions, RdxDocCategory, RdxDocument, RdxProject, RdxContentSource } from '@lexibase/rdx-types';
3
+ export { D as DocumentLinkOptions, R as RdxDocumentLinkError, c as createDocumentLinkResolver } from './document-links-BtWSWs2x.js';
3
4
  export { RdxConfigError, createRdxProject, defineConfig, resolveConfig, resolveProjectPath } from './config/index.js';
4
5
 
5
6
  /**
package/dist/index.js CHANGED
@@ -4,7 +4,11 @@ import {
4
4
  defineConfig,
5
5
  resolveConfig,
6
6
  resolveProjectPath
7
- } from "./chunk-OXVOM2JP.js";
7
+ } from "./chunk-X6YRBB2W.js";
8
+ import {
9
+ RdxDocumentLinkError,
10
+ createDocumentLinkResolver
11
+ } from "./chunk-Z6GCGXVC.js";
8
12
 
9
13
  // src/content/index.ts
10
14
  import fs from "fs";
@@ -13,7 +17,11 @@ import matter from "gray-matter";
13
17
  var MDX_EXTENSION = ".mdx";
14
18
  var DEFAULT_POSITION = Number.MAX_SAFE_INTEGER;
15
19
  function getDocsRoot(docsDir = "docs") {
16
- return path.resolve(process.cwd(), docsDir);
20
+ return path.resolve(
21
+ /* turbopackIgnore: true */
22
+ process.cwd(),
23
+ docsDir
24
+ );
17
25
  }
18
26
  function toTitle(value) {
19
27
  return value.replace(/[-_]/g, " ").replace(/\b\w/g, (character) => character.toUpperCase());
@@ -169,6 +177,8 @@ function getProjectDocsPaths(project) {
169
177
  }
170
178
  export {
171
179
  RdxConfigError,
180
+ RdxDocumentLinkError,
181
+ createDocumentLinkResolver,
172
182
  createRdxProject,
173
183
  defineConfig,
174
184
  getDocsIndex,
@@ -0,0 +1,8 @@
1
+ export { D as DocumentLinkOptions, r as remarkDocumentLinks } from '../document-links-BtWSWs2x.js';
2
+ export { default as rehypeDocumentationHeadings } from 'rehype-slug';
3
+ import rehypeShiki from '@shikijs/rehype';
4
+
5
+ /** shadcn's Shiki/GitHub palette, applied to MDX on the server. */
6
+ declare function rehypeDocumentationCode(this: ThisParameterType<typeof rehypeShiki>): ReturnType<typeof rehypeShiki>;
7
+
8
+ export { rehypeDocumentationCode };
@@ -0,0 +1,28 @@
1
+ import {
2
+ remarkDocumentLinks
3
+ } from "../chunk-Z6GCGXVC.js";
4
+
5
+ // src/mdx/index.ts
6
+ import { default as default2 } from "rehype-slug";
7
+
8
+ // src/mdx/code-highlighting.ts
9
+ import rehypeShiki from "@shikijs/rehype";
10
+ function rehypeDocumentationCode() {
11
+ return rehypeShiki.call(this, {
12
+ themes: { light: "github-light", dark: "github-dark" },
13
+ defaultColor: false,
14
+ addLanguageClass: true,
15
+ // Load grammars only when a document uses them, not the whole bundle.
16
+ langs: [],
17
+ lazy: true,
18
+ fallbackLanguage: "text",
19
+ // The copy button must retain MDX's original trailing newline.
20
+ stripEndNewline: false,
21
+ inline: false
22
+ });
23
+ }
24
+ export {
25
+ rehypeDocumentationCode,
26
+ default2 as rehypeDocumentationHeadings,
27
+ remarkDocumentLinks
28
+ };
@@ -0,0 +1,14 @@
1
+ import { RdxSearchIndex } from '@lexibase/rdx-types';
2
+
3
+ interface SearchDocument {
4
+ title: string;
5
+ description?: string;
6
+ category: string;
7
+ href: string;
8
+ content: string;
9
+ }
10
+ /** Parse text/sections without compiling MDX, evaluating JS, or exposing paths. */
11
+ declare function buildSearchIndex(documents: SearchDocument[]): RdxSearchIndex;
12
+
13
+ export { buildSearchIndex };
14
+ export type { SearchDocument };
@@ -0,0 +1,95 @@
1
+ // src/search/index.ts
2
+ import GithubSlugger from "github-slugger";
3
+ import remarkGfm from "remark-gfm";
4
+ import remarkMdx from "remark-mdx";
5
+ import remarkParse from "remark-parse";
6
+ import { unified } from "unified";
7
+ var parser = unified().use(remarkParse).use(remarkGfm).use(remarkMdx);
8
+ function text(node) {
9
+ if (node.type === "break") return " ";
10
+ if (["mdxjsEsm", "mdxFlowExpression", "mdxTextExpression", "html"].includes(
11
+ node.type
12
+ ))
13
+ return "";
14
+ if (node.name && ["script", "style", "svg"].includes(node.name.toLowerCase()))
15
+ return "";
16
+ if (node.type === "image") return node.alt ?? "";
17
+ if (node.children)
18
+ return node.children.map(text).join(
19
+ [
20
+ "paragraph",
21
+ "heading",
22
+ "link",
23
+ "emphasis",
24
+ "strong",
25
+ "delete",
26
+ "mdxJsxTextElement"
27
+ ].includes(node.type) ? "" : " "
28
+ );
29
+ return node.value ?? "";
30
+ }
31
+ function plain(value) {
32
+ return value.replace(/\s+/g, " ").trim();
33
+ }
34
+ function headingText(node) {
35
+ if (["image", "imageReference", "break"].includes(node.type)) return "";
36
+ if (node.children) return node.children.map(headingText).join("");
37
+ return text(node);
38
+ }
39
+ function buildSearchIndex(documents) {
40
+ const entries = [];
41
+ for (const document of documents) {
42
+ let visit2 = function(node, interactive = false) {
43
+ if (node.type === "heading") {
44
+ const title = plain(text(node));
45
+ const id = slugger.slug(headingText(node));
46
+ if (!title) return;
47
+ if (interactive) {
48
+ current.text += ` ${title}`;
49
+ return;
50
+ }
51
+ current = {
52
+ href: `${document.href}#${encodeURIComponent(id)}`,
53
+ title: document.title,
54
+ category: document.category,
55
+ section: title,
56
+ text: ""
57
+ };
58
+ entries.push(current);
59
+ } else if ([
60
+ "mdxJsxFlowElement",
61
+ "root",
62
+ "blockquote",
63
+ "list",
64
+ "listItem"
65
+ ].includes(node.type)) {
66
+ if (node.name && ["script", "style", "svg"].includes(node.name.toLowerCase()))
67
+ return;
68
+ const nestedInteractive = interactive || node.name === "TabsContent" || node.name === "AccordionContent";
69
+ node.children?.forEach((child) => visit2(child, nestedInteractive));
70
+ } else {
71
+ current.text += ` ${text(node)}`;
72
+ }
73
+ };
74
+ var visit = visit2;
75
+ const firstEntry = entries.length;
76
+ const slugger = new GithubSlugger();
77
+ const tree = parser.parse(document.content);
78
+ let current = {
79
+ href: document.href,
80
+ title: document.title,
81
+ category: document.category,
82
+ section: "",
83
+ text: document.description ?? ""
84
+ };
85
+ entries.push(current);
86
+ tree.children?.forEach((child) => visit2(child));
87
+ for (const entry of entries.slice(firstEntry)) {
88
+ entry.text = plain(entry.text);
89
+ }
90
+ }
91
+ return { schemaVersion: 1, entries };
92
+ }
93
+ export {
94
+ buildSearchIndex
95
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lexibase/rdx-core",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0",
4
4
  "description": "Content indexing and document utilities for RDX documentation projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,6 +14,14 @@
14
14
  "./config": {
15
15
  "types": "./dist/config/index.d.ts",
16
16
  "import": "./dist/config/index.js"
17
+ },
18
+ "./mdx": {
19
+ "types": "./dist/mdx/index.d.ts",
20
+ "import": "./dist/mdx/index.js"
21
+ },
22
+ "./search": {
23
+ "types": "./dist/search/index.d.ts",
24
+ "import": "./dist/search/index.js"
17
25
  }
18
26
  },
19
27
  "files": [
@@ -33,17 +41,28 @@
33
41
  },
34
42
  "homepage": "https://github.com/lexibase/rdx#readme",
35
43
  "dependencies": {
44
+ "github-slugger": "^2.0.0",
45
+ "remark-mdx": "^3.1.1",
46
+ "remark-parse": "^11.0.0",
47
+ "remark-gfm": "^4.0.1",
48
+ "unified": "^11.0.5",
49
+ "@shikijs/rehype": "^4.5.0",
36
50
  "gray-matter": "^4.0.3",
37
- "@lexibase/rdx-types": "1.0.0-beta.4"
51
+ "rehype-slug": "^6.0.0",
52
+ "@lexibase/rdx-types": "1.0.0"
38
53
  },
39
54
  "devDependencies": {
40
55
  "@types/node": "^22.15.3",
41
- "@types/react": "19.1.0",
42
- "@rdx/typescript-config": "1.0.0",
43
- "@rdx/eslint-config": "1.0.0"
56
+ "@types/react": "19.3.0",
57
+ "@rdx/eslint-config": "1.0.0",
58
+ "@rdx/typescript-config": "1.0.0"
59
+ },
60
+ "engines": {
61
+ "node": "^22.18.0 || ^24.11.0"
44
62
  },
45
63
  "scripts": {
46
- "build": "tsup src/index.ts src/config/index.ts --format esm --dts --clean --external @lexibase/rdx-types --external gray-matter",
64
+ "dev": "tsup src/index.ts src/config/index.ts src/mdx/index.ts src/search/index.ts --format esm --dts --watch --external @lexibase/rdx-types --external gray-matter",
65
+ "build": "tsup src/index.ts src/config/index.ts src/mdx/index.ts src/search/index.ts --format esm --dts --clean --external @lexibase/rdx-types --external gray-matter",
47
66
  "check-types": "tsc --noEmit",
48
67
  "test": "node --test tests/*.test.mjs"
49
68
  }