diff --git a/README.md b/README.md index 642fcd31a..e1c1d5f8b 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following | `outputDir` | `string` | `null` | Desired output path for generated MDX and sidebar files. | | `proxy` | `string` | `null` | _Optional:_ Proxy URL to prepend to base URL when performing API requests from browser. | | `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. | +| `templateGenerators` | `object` | `null` | _Optional:_ Customize MDX content with generator functions. See below for a list of supported options. | | `infoTemplate` | `string` | `null` | _Optional:_ Customize MDX content for **info** pages only. | | `tagTemplate` | `string` | `null` | _Optional:_ Customize MDX content for **tag** pages only. | | `schemaTemplate` | `string` | `null` | _Optional:_ Customize MDX content for **schema** pages only. | @@ -202,6 +203,17 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following > All versions will automatically inherit `sidebarOptions` from the parent/base config. +### templateGenerators + +`templateGenerators` can be configured with the following options: + +| Name | Type | Default | Description | +| ------------------------ | ---------- | ------- | ------------------------------------------------------------------------------------------------------------------ | +| `createIntroTemplateMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for API pages.

**Function type:** `() => string` | +| `createInfoTemplateMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for info pages.

**Function type:** `() => string` | +| `createTagTemplateMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for tag pages.

**Function type:** `() => string` | +| `createSchemaTemplateMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for schema pages.

**Function type:** `() => string` | + ### markdownGenerators `markdownGenerators` can be configured with the following options: diff --git a/demo/customTemplateGenerators.ts b/demo/customTemplateGenerators.ts new file mode 100644 index 000000000..fb1937b3e --- /dev/null +++ b/demo/customTemplateGenerators.ts @@ -0,0 +1,45 @@ +export function myCustomIntroTemplateGenerator() { + return `--- +id: {{{id}}} +title: "{{{title}}}" +description: "{{{frontMatter.description}}}" +{{^api}} +sidebar_label: Introduction (custom) +{{/api}} +{{#api}} +sidebar_label: "{{{title}}}" +{{/api}} +{{^api}} +sidebar_position: 0 +{{/api}} +hide_title: true +{{#api}} +hide_table_of_contents: true +{{/api}} +{{#json}} +api: {{{json}}} +{{/json}} +{{#api.method}} +sidebar_class_name: "{{{api.method}}} api-method" +{{/api.method}} +{{#infoPath}} +info_path: {{{infoPath}}} +{{/infoPath}} +custom_edit_url: null +{{#frontMatter.proxy}} +proxy: {{{frontMatter.proxy}}} +{{/frontMatter.proxy}} +{{#frontMatter.hide_send_button}} +hide_send_button: true +{{/frontMatter.hide_send_button}} +{{#frontMatter.show_extensions}} +show_extensions: true +{{/frontMatter.show_extensions}} +{{#frontMatter.mask_credentials_disabled}} +mask_credentials: false +{{/frontMatter.mask_credentials_disabled}} +--- + +{{{markdown}}} + `; +} diff --git a/demo/docs/intro.mdx b/demo/docs/intro.mdx index d4779c3f7..ab8d06a5f 100644 --- a/demo/docs/intro.mdx +++ b/demo/docs/intro.mdx @@ -29,7 +29,6 @@ OpenAPI plugin for generating API reference docs in Docusaurus v3. [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/blob/HEAD/LICENSE) [![npm latest package](https://img.shields.io/npm/v/docusaurus-plugin-openapi-docs/latest.svg)](https://www.npmjs.com/package/docusaurus-plugin-openapi-docs) [![npm downloads](https://img.shields.io/npm/dm/docusaurus-plugin-openapi-docs.svg)](https://www.npmjs.com/package/docusaurus-plugin-openapi-docs) [![npm canary package](https://img.shields.io/npm/v/docusaurus-plugin-openapi-docs/canary.svg)](https://www.npmjs.com/package/docusaurus-plugin-openapi-docs) [![npm beta package](https://img.shields.io/npm/v/docusaurus-plugin-openapi-docs/beta.svg)](https://www.npmjs.com/package/docusaurus-plugin-openapi-docs) -