mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 23:49:51 +00:00
Core: Scan code blocks and table into search indexes by default
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-mdx': patch
|
||||
---
|
||||
|
||||
Support passing remark structure options
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-core': patch
|
||||
---
|
||||
|
||||
Scan table into search indexes by default
|
||||
@@ -3,8 +3,6 @@ title: Hello World
|
||||
description: Your first document
|
||||
---
|
||||
|
||||
import { Callout } from 'fumadocs-ui/components/callout';
|
||||
|
||||
Hey there!
|
||||
|
||||
<Callout>Hello World</Callout>
|
||||
@@ -19,3 +17,7 @@ Hey there!
|
||||
### Heading
|
||||
|
||||
#### Heading
|
||||
|
||||
| name | description |
|
||||
| ----------- | ----------- |
|
||||
| Hello World | Goodbye |
|
||||
|
||||
@@ -4,7 +4,7 @@ import { remark } from 'remark';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import remarkMdx from 'remark-mdx';
|
||||
import type { PluggableList, Transformer } from 'unified';
|
||||
import { visit } from 'unist-util-visit';
|
||||
import { visit, type Test } from 'unist-util-visit';
|
||||
import { flattenNode } from './remark-utils';
|
||||
|
||||
interface Heading {
|
||||
@@ -27,9 +27,11 @@ export interface StructuredData {
|
||||
|
||||
export interface StructureOptions {
|
||||
/**
|
||||
* Types to be scanned, default: `["heading", "blockquote", "paragraph"]`
|
||||
* Types to be scanned.
|
||||
*
|
||||
* @defaultValue ['paragraph', 'blockquote', 'heading', 'tableCell']
|
||||
*/
|
||||
types?: string[];
|
||||
types?: Test;
|
||||
}
|
||||
|
||||
const slugger = new Slugger();
|
||||
@@ -38,7 +40,7 @@ const slugger = new Slugger();
|
||||
* Attach structured data to VFile, you can access via `vfile.data.structuredData`.
|
||||
*/
|
||||
export function remarkStructure({
|
||||
types = ['paragraph', 'blockquote', 'heading'],
|
||||
types = ['paragraph', 'blockquote', 'heading', 'tableCell'],
|
||||
}: StructureOptions = {}): Transformer<Root, Root> {
|
||||
return (node, file) => {
|
||||
slugger.reset();
|
||||
|
||||
@@ -7,3 +7,11 @@ Some text here
|
||||
Some text here
|
||||
|
||||
### Heading 3
|
||||
|
||||
| Name | Description |
|
||||
| ----------- | ----------- |
|
||||
| Hello World | Goodbye |
|
||||
|
||||
```ts
|
||||
console.log('Not indexed');
|
||||
```
|
||||
|
||||
@@ -8,6 +8,22 @@
|
||||
"content": "Some text here",
|
||||
"heading": "heading-2",
|
||||
},
|
||||
{
|
||||
"content": "Name",
|
||||
"heading": "heading-3",
|
||||
},
|
||||
{
|
||||
"content": "Description",
|
||||
"heading": "heading-3",
|
||||
},
|
||||
{
|
||||
"content": "Hello World",
|
||||
"heading": "heading-3",
|
||||
},
|
||||
{
|
||||
"content": "Goodbye",
|
||||
"heading": "heading-3",
|
||||
},
|
||||
],
|
||||
"headings": [
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from '@/mdx-plugins';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import remarkMdx from 'remark-mdx';
|
||||
import { compile } from '@mdx-js/mdx';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
|
||||
const cwd = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
@@ -29,7 +29,10 @@ test('Remark Structure', async () => {
|
||||
const content = readFileSync(
|
||||
path.resolve(cwd, './fixtures/remark-structure.md'),
|
||||
);
|
||||
const result = await remark().use(remarkStructure).process(content);
|
||||
const result = await remark()
|
||||
.use(remarkGfm)
|
||||
.use(remarkStructure)
|
||||
.process(content);
|
||||
|
||||
expect(result.data.structuredData).toMatchFileSnapshot(
|
||||
path.resolve(cwd, './fixtures/remark-structure.output.json'),
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
remarkImage,
|
||||
type RemarkImageOptions,
|
||||
type RemarkHeadingOptions,
|
||||
type StructureOptions,
|
||||
} from 'fumadocs-core/mdx-plugins';
|
||||
import type { Pluggable } from 'unified';
|
||||
import type { Configuration } from 'webpack';
|
||||
@@ -33,6 +34,7 @@ type MDXOptions = Omit<
|
||||
*/
|
||||
valueToExport?: string[];
|
||||
|
||||
remarkStructureOptions?: StructureOptions | false;
|
||||
remarkHeadingOptions?: RemarkHeadingOptions;
|
||||
remarkImageOptions?: RemarkImageOptions | false;
|
||||
rehypeCodeOptions?: RehypeCodeOptions | false;
|
||||
@@ -89,6 +91,7 @@ function getMDXLoaderOptions({
|
||||
rehypeCodeOptions,
|
||||
remarkImageOptions,
|
||||
remarkHeadingOptions,
|
||||
remarkStructureOptions,
|
||||
...mdxOptions
|
||||
}: MDXOptions): MDXLoaderOptions {
|
||||
const mdxExports = [
|
||||
@@ -105,7 +108,10 @@ function getMDXLoaderOptions({
|
||||
[remarkHeading, remarkHeadingOptions],
|
||||
remarkImageOptions !== false && [remarkImage, remarkImageOptions],
|
||||
...v,
|
||||
remarkStructure,
|
||||
remarkStructureOptions !== false && [
|
||||
remarkStructure,
|
||||
remarkStructureOptions,
|
||||
],
|
||||
[remarkMdxExport, { values: mdxExports }],
|
||||
],
|
||||
mdxOptions.remarkPlugins,
|
||||
|
||||
Reference in New Issue
Block a user