[ci] format
This commit is contained in:
parent
b2b367c969
commit
29eef85ce5
2 changed files with 20 additions and 18 deletions
|
@ -1,11 +1,11 @@
|
||||||
import mdxPlugin, { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
|
import mdxPlugin, { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
|
||||||
import type { AstroIntegration } from 'astro';
|
import type { AstroIntegration } from 'astro';
|
||||||
import type { RemarkMdxFrontmatterOptions } from 'remark-mdx-frontmatter';
|
|
||||||
import { parse as parseESM } from 'es-module-lexer';
|
import { parse as parseESM } from 'es-module-lexer';
|
||||||
import remarkGfm from 'remark-gfm';
|
|
||||||
import remarkSmartypants from 'remark-smartypants';
|
|
||||||
import remarkFrontmatter from 'remark-frontmatter';
|
import remarkFrontmatter from 'remark-frontmatter';
|
||||||
|
import remarkGfm from 'remark-gfm';
|
||||||
|
import type { RemarkMdxFrontmatterOptions } from 'remark-mdx-frontmatter';
|
||||||
import remarkMdxFrontmatter from 'remark-mdx-frontmatter';
|
import remarkMdxFrontmatter from 'remark-mdx-frontmatter';
|
||||||
|
import remarkSmartypants from 'remark-smartypants';
|
||||||
import { getFileInfo } from './utils.js';
|
import { getFileInfo } from './utils.js';
|
||||||
|
|
||||||
type WithExtends<T> = T | { extends: T };
|
type WithExtends<T> = T | { extends: T };
|
||||||
|
@ -18,15 +18,12 @@ type MdxOptions = {
|
||||||
* @see https://github.com/remcohaszing/remark-mdx-frontmatter#options for a full list of options
|
* @see https://github.com/remcohaszing/remark-mdx-frontmatter#options for a full list of options
|
||||||
* @default {{ name: 'frontmatter' }}
|
* @default {{ name: 'frontmatter' }}
|
||||||
*/
|
*/
|
||||||
frontmatterOptions?: RemarkMdxFrontmatterOptions;
|
frontmatterOptions?: RemarkMdxFrontmatterOptions;
|
||||||
}
|
};
|
||||||
|
|
||||||
const DEFAULT_REMARK_PLUGINS = [remarkGfm, remarkSmartypants];
|
const DEFAULT_REMARK_PLUGINS = [remarkGfm, remarkSmartypants];
|
||||||
|
|
||||||
function handleExtends<T>(
|
function handleExtends<T>(config: WithExtends<T[] | undefined>, defaults: T[] = []): T[] {
|
||||||
config: WithExtends<T[] | undefined>,
|
|
||||||
defaults: T[] = [],
|
|
||||||
): T[] {
|
|
||||||
if (Array.isArray(config)) return config;
|
if (Array.isArray(config)) return config;
|
||||||
|
|
||||||
return [...defaults, ...(config?.extends ?? [])];
|
return [...defaults, ...(config?.extends ?? [])];
|
||||||
|
@ -50,10 +47,13 @@ export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
|
||||||
// We can revisit this if a strong use case to *remove*
|
// We can revisit this if a strong use case to *remove*
|
||||||
// YAML frontmatter via config is reported.
|
// YAML frontmatter via config is reported.
|
||||||
remarkFrontmatter,
|
remarkFrontmatter,
|
||||||
[remarkMdxFrontmatter, {
|
[
|
||||||
name: 'frontmatter',
|
remarkMdxFrontmatter,
|
||||||
...mdxOptions.frontmatterOptions,
|
{
|
||||||
}],
|
name: 'frontmatter',
|
||||||
|
...mdxOptions.frontmatterOptions,
|
||||||
|
},
|
||||||
|
],
|
||||||
],
|
],
|
||||||
rehypePlugins: handleExtends(mdxOptions.rehypePlugins),
|
rehypePlugins: handleExtends(mdxOptions.rehypePlugins),
|
||||||
jsx: true,
|
jsx: true,
|
||||||
|
|
|
@ -29,11 +29,13 @@ describe('MDX frontmatter', () => {
|
||||||
it('extracts frontmatter to "customFrontmatter" export when configured', async () => {
|
it('extracts frontmatter to "customFrontmatter" export when configured', async () => {
|
||||||
const fixture = await loadFixture({
|
const fixture = await loadFixture({
|
||||||
root: new URL('./fixtures/mdx-custom-frontmatter-name/', import.meta.url),
|
root: new URL('./fixtures/mdx-custom-frontmatter-name/', import.meta.url),
|
||||||
integrations: [mdx({
|
integrations: [
|
||||||
frontmatterOptions: {
|
mdx({
|
||||||
name: 'customFrontmatter',
|
frontmatterOptions: {
|
||||||
},
|
name: 'customFrontmatter',
|
||||||
})],
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue