Core: Upgrade to Orama v3

This commit is contained in:
Fuma Nama
2025-03-01 16:22:51 +08:00
parent 796cc5e49f
commit 2cc0be5434
5 changed files with 53 additions and 23 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-core': patch
---
Support to add custom serialization to `remarkStructure` via `data._string`
@@ -3,7 +3,7 @@ import type { Root } from 'mdast';
import { remark } from 'remark';
import remarkGfm from 'remark-gfm';
import type { PluggableList, Transformer } from 'unified';
import { visit, type Test } from 'unist-util-visit';
import { visit } from 'unist-util-visit';
import { flattenNode } from './remark-utils';
interface Heading {
@@ -26,11 +26,22 @@ export interface StructuredData {
export interface StructureOptions {
/**
* Types to be scanned.
* Types to be scanned as content.
*
* @defaultValue ['paragraph', 'blockquote', 'heading', 'tableCell']
* @defaultValue ['paragraph', 'blockquote', 'tableCell']
*/
types?: Test;
types?: string[];
}
declare module 'mdast' {
interface Data {
/**
* Get content of unserializable element
*
* Needed for `remarkStructure` to generate search index
*/
_string?: string[];
}
}
const slugger = new Slugger();
@@ -60,14 +71,14 @@ export function remarkStructure({
}
}
visit(node, types, (element) => {
visit(node, (element) => {
if (element.type === 'root') return;
const content = flattenNode(element).trim();
if (element.type === 'heading') {
element.data ||= {};
element.data.hProperties ||= {};
const properties = element.data.hProperties;
const content = flattenNode(element).trim();
const id = properties.id ?? slugger.slug(content);
data.headings.push({
@@ -79,7 +90,21 @@ export function remarkStructure({
return 'skip';
}
if (content.length > 0) {
if (element.data?._string) {
for (const content of element.data._string) {
data.contents.push({
heading: lastHeading,
content,
});
}
return 'skip';
}
if (types.includes(element.type)) {
const content = flattenNode(element).trim();
if (content.length === 0) return;
data.contents.push({
heading: lastHeading,
content,
+3 -3
View File
@@ -14,7 +14,7 @@ export interface StaticOptions {
*/
from?: string;
initOrama?: (locale?: string) => Promise<Orama<unknown, never, never, never>>;
initOrama?: (locale?: string) => AnyOrama | Promise<AnyOrama>;
}
export interface StaticClient {
@@ -52,7 +52,7 @@ export function createStaticClient({
for (const [k, v] of Object.entries(data.data)) {
const db = await initOrama(k);
await load(db, v);
load(db, v);
dbs.set(k, {
type: v.type,
db,
@@ -61,7 +61,7 @@ export function createStaticClient({
} else {
const db = await initOrama();
await load(db, data);
load(db, data);
dbs.set('', {
type: data.type,
db,
@@ -151,6 +151,17 @@ export function remarkAutoTypeTable({
properties,
}),
],
data: {
// for Fumadocs `remarkStructure`
_string: [
doc.name,
doc.description,
...doc.entries.flatMap((entry) => [
`${entry.name}: ${entry.type}`,
entry.description,
]),
],
},
children: [],
};
});
+2 -13
View File
@@ -2240,10 +2240,6 @@ packages:
'@orama/[email protected]':
resolution: {integrity: sha512-Lcak3chblMejdlSHgYU2lS2cdOhDpU6vkfIJH4m+YKvqQyLqs1bB8+w6NT1MG5bO12NUK2GFc34Mn2xshMIQ1g==}
'@orama/[email protected]':
resolution: {integrity: sha512-1dfxup89K2DB2bbfx9rXyr/IAvhCKbH79lZCXVh5HWvdJ9g0VAvPIs3+UzjiyOdycEHYTbYundCTN6+Ygj3z4w==}
engines: {node: '>= 16.0.0'}
'@orama/[email protected]':
resolution: {integrity: sha512-w60E72VyWk4QeGy5j0Nm6z4BYVu2MMgtXi8dE/kVluxvz1JVtU9fPXKUW6E0bfrpN+LQM/2w5Jq5v6stl+V0dQ==}
engines: {node: '>= 16.0.0'}
@@ -5614,9 +5610,6 @@ packages:
[email protected]:
resolution: {integrity: sha512-1wlNZK7HW+UE3eGCcMv3hDaYokhspuIeH6enXSnCL1eEZSVDsy/dYwo/4CczhUsrKLA1SSXB+qce8Glw5DEVtw==}
[email protected]:
resolution: {integrity: sha512-+vYvA/Y31l8Zk8dwxHhL3JfTuHPm6tlxM2A3GeQyl7ovYnSp1+mzAxClxaOr0qO1TtPxbQxetI7v5XqKLJZk7Q==}
[email protected]:
resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==}
engines: {node: '>=6'}
@@ -7018,7 +7011,7 @@ snapshots:
fs-extra: 7.0.1
mri: 1.2.0
p-limit: 2.3.0
package-manager-detector: 0.2.9
package-manager-detector: 0.2.10
picocolors: 1.1.1
resolve-from: 5.0.0
semver: 7.7.1
@@ -8015,8 +8008,6 @@ snapshots:
dependencies:
'@noble/hashes': 1.6.0
'@orama/[email protected]': {}
'@orama/[email protected]': {}
'@orama/[email protected]': {}
@@ -8028,7 +8019,7 @@ snapshots:
'@oramacloud/[email protected]':
dependencies:
'@orama/cuid2': 2.2.3
'@orama/orama': 3.0.2
'@orama/orama': 3.1.1
lodash: 4.17.21
'@oxc-transform/[email protected]':
@@ -12213,8 +12204,6 @@ snapshots:
dependencies:
quansync: 0.2.6
[email protected]: {}
[email protected]:
dependencies:
callsites: 3.1.0