Skip to content

Commit 3ecaede

Browse files
committed
feat: add meta description parameter
1 parent 675eb1c commit 3ecaede

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/core/constant.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { ApiDocPlatformType } from './web'
44
const DEFAULT_API_DOC_PLATFORM: ApiDocPlatformType = 'stoplight'
55
const DEFAULT_PATH = '/docs'
66
const DEFAULT_TITLE = 'API Docs'
7+
const DEFAULT_META_DESCRIPTION = 'API Documentation'
78
const DEFAULT_STOPLIGHT_LAYOUT: IStoplight['layout'] = 'sidebar'
89

910
export {
1011
DEFAULT_PATH,
1112
DEFAULT_API_DOC_PLATFORM,
1213
DEFAULT_TITLE,
1314
DEFAULT_STOPLIGHT_LAYOUT,
15+
DEFAULT_META_DESCRIPTION,
1416
}

src/framework/base.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import {
33
DEFAULT_STOPLIGHT_LAYOUT,
44
DEFAULT_TITLE,
55
DEFAULT_API_DOC_PLATFORM,
6+
DEFAULT_META_DESCRIPTION,
67
} from '@/core/constant'
78
import { NodeJSApiDocHandler } from '@/core/server'
89
import { IStoplight } from '@/core/type'
910
import { ApiDocPlatformType } from '@/core/web'
1011

1112
type Config = {
1213
title: string
14+
metaDescription: string
1315
apiDocPlatfomDefault: ApiDocPlatformType
1416
apiDocPlatfomLayout: string
1517
path: string
@@ -22,6 +24,12 @@ type BaseConfigOnConstructor = {
2224
*/
2325
title?: string
2426

27+
/**
28+
* The page meta description
29+
* @default "API Documentation"
30+
*/
31+
metaDescription?: string
32+
2533
/**
2634
* the default of doc path, the value should have / in prefix
2735
* @default "/docs"
@@ -104,7 +112,11 @@ class JSApiDocBaseFramework {
104112
*
105113
*/
106114
constructor(app: any, document: object, config: ConfigOnConstructor = {}) {
107-
const { customPath = DEFAULT_PATH, title = DEFAULT_TITLE } = config
115+
const {
116+
customPath = DEFAULT_PATH,
117+
title = DEFAULT_TITLE,
118+
metaDescription = DEFAULT_META_DESCRIPTION,
119+
} = config
108120

109121
let layout = ''
110122
let apiDocPlatformType: ApiDocPlatformType =
@@ -126,6 +138,7 @@ class JSApiDocBaseFramework {
126138
this.document = document
127139
this.config = {
128140
title,
141+
metaDescription,
129142
apiDocPlatfomDefault: apiDocPlatformType,
130143
path: customPath,
131144
apiDocPlatfomLayout: layout,

0 commit comments

Comments
 (0)