55 * LICENSE file in the root directory of this source tree.
66 * ========================================================================== */
77
8- import path from "path" ;
8+ import { readFile } from "node:fs/promises" ;
9+ import { join , relative , resolve } from "node:path" ;
910
1011import type {
1112 LoadContext ,
@@ -23,7 +24,6 @@ import {
2324 Globby ,
2425} from "@docusaurus/utils" ;
2526import chalk from "chalk" ;
26- import fs from "fs-extra" ;
2727import { Configuration } from "webpack" ;
2828
2929import { DocEnv , processDocMetadata } from "./docs/docs" ;
@@ -37,23 +37,23 @@ export default function pluginOpenAPI(
3737 context : LoadContext ,
3838 options : PluginOptions
3939) : Plugin < LoadedContent > {
40- const { baseUrl, generatedFilesDir, siteDir } = context ;
40+ const { baseUrl, generatedFilesDir, siteDir, siteConfig } = context ;
4141
4242 const pluginId = options . id ?? DEFAULT_PLUGIN_ID ;
4343
44- const pluginDataDirRoot = path . join (
44+ const pluginDataDirRoot = join (
4545 generatedFilesDir ,
4646 "docusaurus-plugin-openapi"
4747 ) ;
4848
49- const dataDir = path . join ( pluginDataDirRoot , pluginId ) ;
49+ const dataDir = join ( pluginDataDirRoot , pluginId ) ;
5050
5151 const aliasedSource = ( source : string ) =>
52- `~api/${ posixPath ( path . relative ( pluginDataDirRoot , source ) ) } ` ;
52+ `~api/${ posixPath ( relative ( pluginDataDirRoot , source ) ) } ` ;
5353
5454 const contentPath = isURL ( options . path )
5555 ? options . path
56- : path . resolve ( context . siteDir , options . path ) ;
56+ : resolve ( context . siteDir , options . path ) ;
5757
5858 return {
5959 name : "docusaurus-plugin-openapi" ,
@@ -70,8 +70,8 @@ export default function pluginOpenAPI(
7070 /** E.g. "api/plugins/myDoc.mdx" */
7171 relativeSource : string
7272 ) : Promise < MdxPageMetadata > {
73- const source = path . join ( contentPath , relativeSource ) ;
74- const content = await fs . readFile ( source , "utf-8" ) ;
73+ const source = join ( contentPath , relativeSource ) ;
74+ const content = await readFile ( source , "utf-8" ) ;
7575
7676 return {
7777 type : "mdx" ,
@@ -200,7 +200,7 @@ export default function pluginOpenAPI(
200200 exact : true ,
201201 modules : {
202202 // TODO: "-content" should be inside hash to prevent name too long errors.
203- content : path . join ( dataDir , `${ docuHash ( pageId ) } -content.mdx` ) ,
203+ content : join ( dataDir , `${ docuHash ( pageId ) } -content.mdx` ) ,
204204 } ,
205205 sidebar : sidebarName ,
206206 } ;
@@ -237,6 +237,7 @@ export default function pluginOpenAPI(
237237 modules : {
238238 apiMetadata : aliasedSource ( apiBaseMetadataPath ) ,
239239 } ,
240+ priority : 999999 ,
240241 } ) ;
241242
242243 return ;
@@ -274,19 +275,15 @@ export default function pluginOpenAPI(
274275 rehypePlugins,
275276 beforeDefaultRehypePlugins,
276277 beforeDefaultRemarkPlugins,
277- // Docusaurus 2.2.0 has a regression that requires this option to be set.
278- markdownConfig : { } ,
278+ markdownConfig : siteConfig . markdown ?? { mdx1Compat : { } } ,
279279 metadataPath : ( mdxPath : string ) => {
280280 if ( mdxPath . startsWith ( dataDir ) ) {
281281 // The MDX file already lives in `dataDir`: this is an OpenAPI MDX
282282 return mdxPath . replace ( / ( - c o n t e n t \. m d x ? ) $ / , ".json" ) ;
283283 } else {
284284 // Standard resolution
285285 const aliasedSource = aliasedSitePath ( mdxPath , siteDir ) ;
286- return path . join (
287- dataDir ,
288- `${ docuHash ( aliasedSource ) } .json`
289- ) ;
286+ return join ( dataDir , `${ docuHash ( aliasedSource ) } .json` ) ;
290287 }
291288 } ,
292289 } ,
0 commit comments