Skip to content

Commit 2cc0be5

Browse files
committedMar 1, 2025·
Core: Upgrade to Orama v3
1 parent 796cc5e commit 2cc0be5

File tree

5 files changed

+53
-23
lines changed

5 files changed

+53
-23
lines changed
 

‎.changeset/quick-apes-show.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'fumadocs-core': patch
3+
---
4+
5+
Support to add custom serialization to `remarkStructure` via `data._string`

‎packages/core/src/mdx-plugins/remark-structure.ts

+32-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Root } from 'mdast';
33
import { remark } from 'remark';
44
import remarkGfm from 'remark-gfm';
55
import type { PluggableList, Transformer } from 'unified';
6-
import { visit, type Test } from 'unist-util-visit';
6+
import { visit } from 'unist-util-visit';
77
import { flattenNode } from './remark-utils';
88

99
interface Heading {
@@ -26,11 +26,22 @@ export interface StructuredData {
2626

2727
export interface StructureOptions {
2828
/**
29-
* Types to be scanned.
29+
* Types to be scanned as content.
3030
*
31-
* @defaultValue ['paragraph', 'blockquote', 'heading', 'tableCell']
31+
* @defaultValue ['paragraph', 'blockquote', 'tableCell']
3232
*/
33-
types?: Test;
33+
types?: string[];
34+
}
35+
36+
declare module 'mdast' {
37+
interface Data {
38+
/**
39+
* Get content of unserializable element
40+
*
41+
* Needed for `remarkStructure` to generate search index
42+
*/
43+
_string?: string[];
44+
}
3445
}
3546

3647
const slugger = new Slugger();
@@ -60,14 +71,14 @@ export function remarkStructure({
6071
}
6172
}
6273

63-
visit(node, types, (element) => {
74+
visit(node, (element) => {
6475
if (element.type === 'root') return;
65-
const content = flattenNode(element).trim();
6676

6777
if (element.type === 'heading') {
6878
element.data ||= {};
6979
element.data.hProperties ||= {};
7080
const properties = element.data.hProperties;
81+
const content = flattenNode(element).trim();
7182
const id = properties.id ?? slugger.slug(content);
7283

7384
data.headings.push({
@@ -79,7 +90,21 @@ export function remarkStructure({
7990
return 'skip';
8091
}
8192

82-
if (content.length > 0) {
93+
if (element.data?._string) {
94+
for (const content of element.data._string) {
95+
data.contents.push({
96+
heading: lastHeading,
97+
content,
98+
});
99+
}
100+
101+
return 'skip';
102+
}
103+
104+
if (types.includes(element.type)) {
105+
const content = flattenNode(element).trim();
106+
if (content.length === 0) return;
107+
83108
data.contents.push({
84109
heading: lastHeading,
85110
content,

‎packages/core/src/search/client/static.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface StaticOptions {
1414
*/
1515
from?: string;
1616

17-
initOrama?: (locale?: string) => Promise<Orama<unknown, never, never, never>>;
17+
initOrama?: (locale?: string) => AnyOrama | Promise<AnyOrama>;
1818
}
1919

2020
export interface StaticClient {
@@ -52,7 +52,7 @@ export function createStaticClient({
5252
for (const [k, v] of Object.entries(data.data)) {
5353
const db = await initOrama(k);
5454

55-
await load(db, v);
55+
load(db, v);
5656
dbs.set(k, {
5757
type: v.type,
5858
db,
@@ -61,7 +61,7 @@ export function createStaticClient({
6161
} else {
6262
const db = await initOrama();
6363

64-
await load(db, data);
64+
load(db, data);
6565
dbs.set('', {
6666
type: data.type,
6767
db,

‎packages/typescript/src/lib/remark-auto-type-table.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ export function remarkAutoTypeTable({
151151
properties,
152152
}),
153153
],
154+
data: {
155+
// for Fumadocs `remarkStructure`
156+
_string: [
157+
doc.name,
158+
doc.description,
159+
...doc.entries.flatMap((entry) => [
160+
`${entry.name}: ${entry.type}`,
161+
entry.description,
162+
]),
163+
],
164+
},
154165
children: [],
155166
};
156167
});

‎pnpm-lock.yaml

+2-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.