mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 07:01:53 +08:00
40 lines
790 B
Plaintext
40 lines
790 B
Plaintext
```js
|
|
// .storybook/main.js
|
|
|
|
import { loadCsf } from '@storybook/csf-tools';
|
|
import { compile } from '@storybook/mdx2-csf';
|
|
|
|
const indexer = async (fileName, opts) => {
|
|
const title = fileName
|
|
.split('/')
|
|
.pop()
|
|
.replace(/\.(md|html)$/, '');
|
|
|
|
// Convert Markdown into MDX
|
|
const source = `
|
|
import { Meta, Description } from '@storybook/blocks';
|
|
|
|
<Meta title='${title}' />
|
|
<Description>{require('${fileName}')}</Description>
|
|
`;
|
|
|
|
// Compile MDX into CSF
|
|
const code = await compile(source, {});
|
|
|
|
// Parse CSF component
|
|
return loadCsf(code, { ...opts, fileName }).parse();
|
|
};
|
|
|
|
export default {
|
|
storyIndexers: (indexers) => {
|
|
return [
|
|
{
|
|
test: /\.(md|html)$/,
|
|
indexer,
|
|
},
|
|
...(indexers || []),
|
|
];
|
|
},
|
|
};
|
|
```
|