diff --git a/demo/docusaurus.config.ts b/demo/docusaurus.config.ts index bd6dbeba6..15cf61e33 100644 --- a/demo/docusaurus.config.ts +++ b/demo/docusaurus.config.ts @@ -297,7 +297,10 @@ const config: Config = { groupPathsBy: "tag", categoryLinkSource: "tag", }, - template: "api.mustache", // Customize API MDX with mustache template + template: "templates/api.mustache", // Customize API MDX with mustache template + infoTemplate: "templates/info.mustache", + tagTemplate: "templates/tag.mustache", + schemaTemplate: "templates/schema.mustache", downloadUrl: "/petstore.yaml", hideSendButton: false, showSchemas: true, diff --git a/demo/api.mustache b/demo/templates/api.mustache similarity index 74% rename from demo/api.mustache rename to demo/templates/api.mustache index 9a78cab49..aa1e66166 100644 --- a/demo/api.mustache +++ b/demo/templates/api.mustache @@ -36,4 +36,16 @@ show_extensions: true {{/frontMatter.show_extensions}} --- -{{{markdown}}} \ No newline at end of file +This is a Custom Api Page Generated by docusaurus-openapi-docs using `api.mustache` template + +
+
+
+ +{{{markdown}}} + +
+
+
+ +This is a Custom Api Page Generated by docusaurus-openapi-docs using `api.mustache` template \ No newline at end of file diff --git a/demo/templates/info.mustache b/demo/templates/info.mustache new file mode 100644 index 000000000..3db441945 --- /dev/null +++ b/demo/templates/info.mustache @@ -0,0 +1,22 @@ +--- +id: {{{id}}} +title: "{{{title}}}" +description: "{{{frontMatter.description}}}" +sidebar_label: "{{{title}}}" +hide_title: true +custom_edit_url: null +--- + +This is a Custom Info Page Generated by docusaurus-openapi-docs using `info.mustache` template + +
+
+
+ +{{{markdown}}} + +
+
+
+ +This is a Custom Info Page Generated by docusaurus-openapi-docs using `info.mustache` template \ No newline at end of file diff --git a/demo/templates/schema.mustache b/demo/templates/schema.mustache new file mode 100644 index 000000000..274323bca --- /dev/null +++ b/demo/templates/schema.mustache @@ -0,0 +1,27 @@ +--- +id: {{{id}}} +title: "{{{title}}}" +description: "{{{frontMatter.description}}}" +sidebar_label: "{{{title}}}" +hide_title: true +{{#schema}} +hide_table_of_contents: true +{{/schema}} +schema: true +sample: {{{frontMatter.sample}}} +custom_edit_url: null +--- + +This is a Custom Schema Page Generated by docusaurus-openapi-docs using `schema.mustache` template + +
+
+
+ +{{{markdown}}} + +
+
+
+ +This is a Custom Schema Page Generated by docusaurus-openapi-docs using `schema.mustache` template \ No newline at end of file diff --git a/demo/templates/tag.mustache b/demo/templates/tag.mustache new file mode 100644 index 000000000..b73b60a81 --- /dev/null +++ b/demo/templates/tag.mustache @@ -0,0 +1,20 @@ +--- +id: {{{id}}} +title: "{{{frontMatter.description}}}" +description: "{{{frontMatter.description}}}" +custom_edit_url: null +--- + +This is a Custom Tag Page Generated by docusaurus-openapi-docs using `tag.mustache` template + +
+
+
+ +{{{markdown}}} + +
+
+
+ +This is a Custom Tag Page Generated by docusaurus-openapi-docs using `tag.mustache` template \ No newline at end of file diff --git a/packages/docusaurus-plugin-openapi-docs/src/index.ts b/packages/docusaurus-plugin-openapi-docs/src/index.ts index 15d1206f1..7fd6e0f2b 100644 --- a/packages/docusaurus-plugin-openapi-docs/src/index.ts +++ b/packages/docusaurus-plugin-openapi-docs/src/index.ts @@ -117,6 +117,9 @@ export default function pluginOpenAPIDocs( specPath, outputDir, template, + infoTemplate, + tagTemplate, + schemaTemplate, markdownGenerators, downloadUrl, sidebarOptions, @@ -236,7 +239,9 @@ show_extensions: true {{{markdown}}} `; - const infoMdTemplate = `--- + const infoMdTemplate = infoTemplate + ? fs.readFileSync(infoTemplate).toString() + : `--- id: {{{id}}} title: "{{{title}}}" description: "{{{frontMatter.description}}}" @@ -255,7 +260,9 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common'; \`\`\` `; - const tagMdTemplate = `--- + const tagMdTemplate = tagTemplate + ? fs.readFileSync(tagTemplate).toString() + : `--- id: {{{id}}} title: "{{{frontMatter.description}}}" description: "{{{frontMatter.description}}}" @@ -272,7 +279,9 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common'; \`\`\` `; - const schemaMdTemplate = `--- + const schemaMdTemplate = schemaTemplate + ? fs.readFileSync(schemaTemplate).toString() + : `--- id: {{{id}}} title: "{{{title}}}" description: "{{{frontMatter.description}}}" @@ -371,21 +380,14 @@ custom_edit_url: null } } - // TODO: determine if we actually want/need this if (item.type === "info") { if (!fs.existsSync(`${outputDir}/${item.id}.info.mdx`)) { try { - sidebarOptions?.categoryLinkSource === "info" // Only use utils template if set to "info" - ? fs.writeFileSync( - `${outputDir}/${item.id}.info.mdx`, - utils, - "utf8" - ) - : fs.writeFileSync( - `${outputDir}/${item.id}.info.mdx`, - view, - "utf8" - ); + fs.writeFileSync( + `${outputDir}/${item.id}.info.mdx`, + utils, + "utf8" + ); console.log( chalk.green( `Successfully created "${outputDir}/${item.id}.info.mdx"` diff --git a/packages/docusaurus-plugin-openapi-docs/src/options.ts b/packages/docusaurus-plugin-openapi-docs/src/options.ts index ff114de7f..3c46e27f5 100644 --- a/packages/docusaurus-plugin-openapi-docs/src/options.ts +++ b/packages/docusaurus-plugin-openapi-docs/src/options.ts @@ -39,6 +39,9 @@ export const OptionsSchema = Joi.object({ proxy: Joi.string(), outputDir: Joi.string().required(), template: Joi.string(), + infoTemplate: Joi.string(), + tagTemplate: Joi.string(), + schemaTemplate: Joi.string(), downloadUrl: Joi.string(), hideSendButton: Joi.boolean(), showExtensions: Joi.boolean(), diff --git a/packages/docusaurus-plugin-openapi-docs/src/types.ts b/packages/docusaurus-plugin-openapi-docs/src/types.ts index 43367bbaa..721aea14d 100644 --- a/packages/docusaurus-plugin-openapi-docs/src/types.ts +++ b/packages/docusaurus-plugin-openapi-docs/src/types.ts @@ -35,6 +35,9 @@ export interface APIOptions { specPath: string; outputDir: string; template?: string; + infoTemplate?: string; + tagTemplate?: string; + schemaTemplate?: string; downloadUrl?: string; hideSendButton?: boolean; showExtensions?: boolean;