Skip to content

Commit fe30047

Browse files
committed
add info description headers. fix #288
1 parent 7faa199 commit fe30047

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

src/templates/navbar-template.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ import { expandCollapseComponent } from './endpoint-template.js';
66
import { getComponentInfo } from './components-template.js';
77

88
function onExpandCollapseTag(event, tagId) {
9+
if (tagId === 'link-overview') {
10+
this.resolvedSpec.info.expanded = !this.resolvedSpec.info.expanded;
11+
this.scrollToEventTarget(event, false);
12+
return;
13+
}
14+
915
const tag = this.resolvedSpec.tags.find(t => t.elementId === tagId);
1016
if (!tag) {
1117
return;
1218
}
1319
tag.expanded = !tag.expanded;
1420
if (tag.expanded && this.operationsCollapsed) {
1521
this.resolvedSpec.tags.filter(t => t.elementId !== tagId).forEach(t => t.expanded = false);
22+
this.resolvedSpec.info.expanded = false;
1623
}
1724

1825
// Only display the dedicated tag page if the tag has a description, otherwise, it will be an ugly page with nothing on it.
@@ -62,10 +69,32 @@ export default function navbarTemplate() {
6269
${html`<nav class='nav-scroll' part="navbar-scroll">
6370
${(this.hideInfo || !this.resolvedSpec.info)
6471
? ''
65-
: html`<div class='nav-bar-info' id='link-overview' data-content-id='overview' @click = '${(e) => this.scrollToEventTarget(e, false)}' role="link" tabindex="0" @keydown = '${(e) => { if (e.key === 'Enter') { e.target.click(); }}}';
66-
}>
67-
${this.resolvedSpec.info.title || getI18nText('menu.overview')}
68-
</div>`
72+
: html`
73+
<div class='nav-bar-tag-and-paths ${this.resolvedSpec.info.expanded ? '' : 'collapsed'}'>
74+
<div class='nav-bar-info' id='link-overview' data-content-id='overview'
75+
@click = '${(e) => { onExpandCollapseTag.call(this, e, 'link-overview'); }}'
76+
role="link" tabindex="0"
77+
@keydown = '${(e) => { if (e.key === 'Enter') { e.target.click(); }}}';
78+
}>
79+
${this.resolvedSpec.info.title || getI18nText('menu.overview')}
80+
</div>
81+
82+
<div class="nav-bar-section-wrapper">
83+
<div>
84+
${this.resolvedSpec.info.headers?.map((header) => html`
85+
<div
86+
class='nav-bar-h${header.depth}'
87+
id="link-overview--${new marked.Slugger().slug(header.text)}"
88+
data-content-id='overview--${new marked.Slugger().slug(header.text)}'
89+
@click='${(e) => this.scrollToEventTarget(e, false)}'>
90+
${header.text}
91+
</div>`
92+
) || ''}
93+
</div>
94+
</div>
95+
</div>
96+
97+
`
6998
}
7099
71100
${this.hideServerSelection

src/utils/spec-parser.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ export default async function ProcessSpec(specUrlOrObject, serverUrl = '') {
9595
}
9696

9797
const parsedSpec = {
98-
info: jsonParsedSpec.info,
99-
infoDescriptionHeaders,
98+
info: {
99+
...jsonParsedSpec.info,
100+
expanded: true,
101+
headers: infoDescriptionHeaders
102+
},
100103
tags,
101104
components,
102105
// pathGroups,

0 commit comments

Comments
 (0)