Skip to content

Commit 9707684

Browse files
committed
feat: add template example to demo
1 parent f9d6a74 commit 9707684

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

demo/customTemplateGenerators.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
export function myCustomIntroTemplateGenerator() {
2+
return `---
3+
id: {{{id}}}
4+
title: "{{{title}}}"
5+
description: "{{{frontMatter.description}}}"
6+
{{^api}}
7+
sidebar_label: Introduction (custom)
8+
{{/api}}
9+
{{#api}}
10+
sidebar_label: "{{{title}}}"
11+
{{/api}}
12+
{{^api}}
13+
sidebar_position: 0
14+
{{/api}}
15+
hide_title: true
16+
{{#api}}
17+
hide_table_of_contents: true
18+
{{/api}}
19+
{{#json}}
20+
api: {{{json}}}
21+
{{/json}}
22+
{{#api.method}}
23+
sidebar_class_name: "{{{api.method}}} api-method"
24+
{{/api.method}}
25+
{{#infoPath}}
26+
info_path: {{{infoPath}}}
27+
{{/infoPath}}
28+
custom_edit_url: null
29+
{{#frontMatter.proxy}}
30+
proxy: {{{frontMatter.proxy}}}
31+
{{/frontMatter.proxy}}
32+
{{#frontMatter.hide_send_button}}
33+
hide_send_button: true
34+
{{/frontMatter.hide_send_button}}
35+
{{#frontMatter.show_extensions}}
36+
show_extensions: true
37+
{{/frontMatter.show_extensions}}
38+
{{#frontMatter.mask_credentials_disabled}}
39+
mask_credentials: false
40+
{{/frontMatter.mask_credentials_disabled}}
41+
---
42+
43+
{{{markdown}}}
44+
`;
45+
}

demo/docusaurus.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type * as OpenApiPlugin from "docusaurus-plugin-openapi-docs";
55

66
import { DOCUSAURUS_VERSION } from "@docusaurus/utils";
77
import { myCustomApiMdGenerator } from "./customMdGenerators";
8+
import { myCustomIntroTemplateGenerator } from "./customTemplateGenerators";
89

910
const config: Config = {
1011
future: {
@@ -318,6 +319,9 @@ const config: Config = {
318319
downloadUrl: "/petstore-3.1.yaml",
319320
hideSendButton: false,
320321
showSchemas: true,
322+
templateGenerators: {
323+
createInfoTemplateMD: myCustomIntroTemplateGenerator,
324+
},
321325
markdownGenerators: { createApiPageMD: myCustomApiMdGenerator }, // customize MDX with markdown generator
322326
} satisfies OpenApiPlugin.Options,
323327
cos: {

0 commit comments

Comments
 (0)