fumadocs-core 16.0.6 → 16.0.7
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-QMATWJ5F.js → chunk-JD3M54YF.js} +37 -1
- package/dist/content/toc.js +1 -1
- package/dist/mdx-plugins/index.d.ts +8 -2
- package/dist/mdx-plugins/index.js +26 -13
- package/dist/{remark-structure-DkCXCzpD.d.ts → remark-structure-BJxaB5zZ.d.ts} +9 -4
- package/dist/search/algolia.d.ts +1 -1
- package/dist/search/client.d.ts +1 -1
- package/dist/search/orama-cloud.d.ts +1 -1
- package/dist/search/server.d.ts +1 -1
- package/package.json +2 -1
|
@@ -2,13 +2,48 @@
|
|
|
2
2
|
import Slugger from "github-slugger";
|
|
3
3
|
import { visit } from "unist-util-visit";
|
|
4
4
|
|
|
5
|
-
// src/mdx-plugins/
|
|
5
|
+
// src/mdx-plugins/mdast-utils.ts
|
|
6
|
+
import { valueToEstree } from "estree-util-value-to-estree";
|
|
6
7
|
function flattenNode(node) {
|
|
7
8
|
if ("children" in node)
|
|
8
9
|
return node.children.map((child) => flattenNode(child)).join("");
|
|
9
10
|
if ("value" in node) return node.value;
|
|
10
11
|
return "";
|
|
11
12
|
}
|
|
13
|
+
function toMdxExport(name, value) {
|
|
14
|
+
return {
|
|
15
|
+
type: "mdxjsEsm",
|
|
16
|
+
value: "",
|
|
17
|
+
data: {
|
|
18
|
+
estree: {
|
|
19
|
+
type: "Program",
|
|
20
|
+
sourceType: "module",
|
|
21
|
+
body: [
|
|
22
|
+
{
|
|
23
|
+
type: "ExportNamedDeclaration",
|
|
24
|
+
attributes: [],
|
|
25
|
+
specifiers: [],
|
|
26
|
+
source: null,
|
|
27
|
+
declaration: {
|
|
28
|
+
type: "VariableDeclaration",
|
|
29
|
+
kind: "let",
|
|
30
|
+
declarations: [
|
|
31
|
+
{
|
|
32
|
+
type: "VariableDeclarator",
|
|
33
|
+
id: {
|
|
34
|
+
type: "Identifier",
|
|
35
|
+
name
|
|
36
|
+
},
|
|
37
|
+
init: valueToEstree(value)
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
12
47
|
|
|
13
48
|
// src/mdx-plugins/remark-heading.ts
|
|
14
49
|
var slugger = new Slugger();
|
|
@@ -53,5 +88,6 @@ function remarkHeading({
|
|
|
53
88
|
|
|
54
89
|
export {
|
|
55
90
|
flattenNode,
|
|
91
|
+
toMdxExport,
|
|
56
92
|
remarkHeading
|
|
57
93
|
};
|
package/dist/content/toc.js
CHANGED
|
@@ -4,7 +4,7 @@ import { RehypeShikiOptions } from '@shikijs/rehype';
|
|
|
4
4
|
import { Processor, Transformer } from 'unified';
|
|
5
5
|
import { ShikiTransformer } from 'shiki';
|
|
6
6
|
import { Root as Root$1, BlockContent, Text } from 'mdast';
|
|
7
|
-
export { a as StructureOptions, S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-
|
|
7
|
+
export { a as StructureOptions, S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-BJxaB5zZ.js';
|
|
8
8
|
export { a as RemarkCodeTabOptions, R as RemarkHeadingOptions, b as remarkCodeTab, r as remarkHeading } from '../remark-code-tab-DmyIyi6m.js';
|
|
9
9
|
import { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
|
|
10
10
|
|
|
@@ -51,6 +51,12 @@ type RehypeCodeOptions = RehypeShikiOptions & {
|
|
|
51
51
|
declare function rehypeCode(this: Processor, _options?: Partial<RehypeCodeOptions>): Transformer<Root, Root>;
|
|
52
52
|
declare function transformerTab(): ShikiTransformer;
|
|
53
53
|
|
|
54
|
+
type ExternalImageOptions = {
|
|
55
|
+
/**
|
|
56
|
+
* timeout for fetching remote images (in milliseconds)
|
|
57
|
+
*/
|
|
58
|
+
timeout?: number;
|
|
59
|
+
} | boolean;
|
|
54
60
|
interface RemarkImageOptions {
|
|
55
61
|
/**
|
|
56
62
|
* Directory or base URL to resolve absolute image paths
|
|
@@ -91,7 +97,7 @@ interface RemarkImageOptions {
|
|
|
91
97
|
*
|
|
92
98
|
* @defaultValue true
|
|
93
99
|
*/
|
|
94
|
-
external?:
|
|
100
|
+
external?: ExternalImageOptions;
|
|
95
101
|
}
|
|
96
102
|
/**
|
|
97
103
|
* Turn images into Next.js Image compatible usage.
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
flattenNode,
|
|
3
|
-
remarkHeading
|
|
4
|
-
} from "../chunk-QMATWJ5F.js";
|
|
5
1
|
import {
|
|
6
2
|
defaultThemes,
|
|
7
3
|
getHighlighter
|
|
8
4
|
} from "../chunk-XN2LKXFZ.js";
|
|
5
|
+
import {
|
|
6
|
+
flattenNode,
|
|
7
|
+
remarkHeading,
|
|
8
|
+
toMdxExport
|
|
9
|
+
} from "../chunk-JD3M54YF.js";
|
|
9
10
|
import "../chunk-U67V476Y.js";
|
|
10
11
|
|
|
11
12
|
// src/mdx-plugins/index.ts
|
|
@@ -426,8 +427,7 @@ function remarkImage({
|
|
|
426
427
|
}
|
|
427
428
|
return out;
|
|
428
429
|
}
|
|
429
|
-
|
|
430
|
-
const size = await getImageSize(src).catch((e) => {
|
|
430
|
+
const size = await getImageSize(src, external).catch((e) => {
|
|
431
431
|
throw new Error(
|
|
432
432
|
`[Remark Image] Failed obtain image size for ${node.url} (public directory configured as ${publicDir})`,
|
|
433
433
|
{
|
|
@@ -435,6 +435,7 @@ function remarkImage({
|
|
|
435
435
|
}
|
|
436
436
|
);
|
|
437
437
|
});
|
|
438
|
+
if (!size) return;
|
|
438
439
|
return {
|
|
439
440
|
type: "mdxJsxFlowElement",
|
|
440
441
|
name: "img",
|
|
@@ -550,9 +551,13 @@ function parseSrc(src, publicDir, dir) {
|
|
|
550
551
|
file: path.join(dir, src)
|
|
551
552
|
};
|
|
552
553
|
}
|
|
553
|
-
async function getImageSize(src) {
|
|
554
|
+
async function getImageSize(src, onExternal) {
|
|
554
555
|
if (src.type === "file") return imageSizeFromFile(src.file);
|
|
555
|
-
|
|
556
|
+
if (onExternal === false) return;
|
|
557
|
+
const { timeout } = typeof onExternal === "object" ? onExternal : {};
|
|
558
|
+
const res = await fetch(src.url, {
|
|
559
|
+
signal: typeof timeout === "number" ? AbortSignal.timeout(timeout) : void 0
|
|
560
|
+
});
|
|
556
561
|
if (!res.ok) {
|
|
557
562
|
throw new Error(
|
|
558
563
|
`[Remark Image] Failed to fetch ${src.url} (${res.status}): ${await res.text()}`
|
|
@@ -577,7 +582,8 @@ function remarkStructure({
|
|
|
577
582
|
allowedMdxAttributes = (node) => {
|
|
578
583
|
if (!node.name) return false;
|
|
579
584
|
return ["TypeTable", "Callout"].includes(node.name);
|
|
580
|
-
}
|
|
585
|
+
},
|
|
586
|
+
exportAs = false
|
|
581
587
|
} = {}) {
|
|
582
588
|
const slugger = new Slugger();
|
|
583
589
|
if (Array.isArray(allowedMdxAttributes)) {
|
|
@@ -588,7 +594,7 @@ function remarkStructure({
|
|
|
588
594
|
const arr = types;
|
|
589
595
|
types = (node) => arr.includes(node.type);
|
|
590
596
|
}
|
|
591
|
-
return (
|
|
597
|
+
return (tree, file) => {
|
|
592
598
|
slugger.reset();
|
|
593
599
|
const data = { contents: [], headings: [] };
|
|
594
600
|
let lastHeading;
|
|
@@ -599,9 +605,8 @@ function remarkStructure({
|
|
|
599
605
|
data.contents.push(...frontmatter._openapi.structuredData.contents);
|
|
600
606
|
}
|
|
601
607
|
}
|
|
602
|
-
visit2(
|
|
603
|
-
if (element.type === "root") return;
|
|
604
|
-
if (!types(element)) return;
|
|
608
|
+
visit2(tree, (element) => {
|
|
609
|
+
if (element.type === "root" || !types(element)) return;
|
|
605
610
|
if (element.type === "heading") {
|
|
606
611
|
element.data ||= {};
|
|
607
612
|
element.data.hProperties ||= {};
|
|
@@ -648,6 +653,14 @@ function remarkStructure({
|
|
|
648
653
|
return "skip";
|
|
649
654
|
});
|
|
650
655
|
file.data.structuredData = data;
|
|
656
|
+
if (exportAs) {
|
|
657
|
+
tree.children.unshift(
|
|
658
|
+
toMdxExport(
|
|
659
|
+
typeof exportAs === "string" ? exportAs : "structuredData",
|
|
660
|
+
data
|
|
661
|
+
)
|
|
662
|
+
);
|
|
663
|
+
}
|
|
651
664
|
};
|
|
652
665
|
}
|
|
653
666
|
function structure(content, remarkPlugins = [], options = {}) {
|
|
@@ -31,26 +31,31 @@ interface StructureOptions {
|
|
|
31
31
|
* - a function that determines if attribute should be indexed.
|
|
32
32
|
*/
|
|
33
33
|
allowedMdxAttributes?: string[] | ((node: MdxJsxFlowElement, attribute: MdxJsxAttribute | MdxJsxExpressionAttribute) => boolean);
|
|
34
|
+
/**
|
|
35
|
+
* export as `structuredData` or specified variable name.
|
|
36
|
+
*/
|
|
37
|
+
exportAs?: string | boolean;
|
|
34
38
|
}
|
|
35
39
|
declare module 'mdast' {
|
|
36
40
|
interface Data {
|
|
37
41
|
/**
|
|
38
|
-
* Get content of unserializable element
|
|
39
|
-
*
|
|
40
|
-
* Needed for `remarkStructure` to generate search index
|
|
42
|
+
* [Fumadocs] Get content of unserializable element, `remarkStructure` uses it to generate search index.
|
|
41
43
|
*/
|
|
42
44
|
_string?: string[];
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
declare module 'vfile' {
|
|
46
48
|
interface DataMap {
|
|
49
|
+
/**
|
|
50
|
+
* [Fumadocs] injected by `remarkStructure`
|
|
51
|
+
*/
|
|
47
52
|
structuredData: StructuredData;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
55
|
/**
|
|
51
56
|
* Attach structured data to VFile, you can access via `vfile.data.structuredData`.
|
|
52
57
|
*/
|
|
53
|
-
declare function remarkStructure({ types, allowedMdxAttributes, }?: StructureOptions): Transformer<Root, Root>;
|
|
58
|
+
declare function remarkStructure({ types, allowedMdxAttributes, exportAs, }?: StructureOptions): Transformer<Root, Root>;
|
|
54
59
|
/**
|
|
55
60
|
* Extract data from markdown/mdx content
|
|
56
61
|
*/
|
package/dist/search/algolia.d.ts
CHANGED
package/dist/search/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyOrama } from '@orama/orama';
|
|
2
|
-
import '../remark-structure-
|
|
2
|
+
import '../remark-structure-BJxaB5zZ.js';
|
|
3
3
|
import { BaseIndex } from './algolia.js';
|
|
4
4
|
import { LiteClient, SearchResponse } from 'algoliasearch/lite';
|
|
5
5
|
import { OramaCloud, OramaCloudSearchParams } from '@orama/core';
|
package/dist/search/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TypedDocument, Orama, Language, RawData, create, SearchParams } from '@orama/orama';
|
|
2
|
-
import { S as StructuredData } from '../remark-structure-
|
|
2
|
+
import { S as StructuredData } from '../remark-structure-BJxaB5zZ.js';
|
|
3
3
|
import { SortedResult } from './index.js';
|
|
4
4
|
export { HighlightedText, ReactSortedResult, createContentHighlighter } from './index.js';
|
|
5
5
|
import { I18nConfig } from '../i18n/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-core",
|
|
3
|
-
"version": "16.0.
|
|
3
|
+
"version": "16.0.7",
|
|
4
4
|
"description": "The library for building a documentation website in any React.js framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Fumadocs",
|
|
@@ -105,6 +105,7 @@
|
|
|
105
105
|
"@orama/orama": "^3.1.16",
|
|
106
106
|
"@shikijs/rehype": "^3.14.0",
|
|
107
107
|
"@shikijs/transformers": "^3.14.0",
|
|
108
|
+
"estree-util-value-to-estree": "^3.5.0",
|
|
108
109
|
"github-slugger": "^2.0.0",
|
|
109
110
|
"hast-util-to-estree": "^3.1.3",
|
|
110
111
|
"hast-util-to-jsx-runtime": "^2.3.6",
|