Skip to content

Commit 4728f54

Browse files
authored
feat: condensed sidebar list (microsoft#16)
* feat: styles * feat(navigation): update sidebar
1 parent aaf3335 commit 4728f54

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/main.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ window.addEventListener('DOMContentLoaded', async() => {
210210
}
211211
documentationView.focus();
212212
await glossaryItem.highlight();
213+
214+
// const selectedNav = glossaryItem
213215
});
214216
}, false);
215217

@@ -221,10 +223,14 @@ function renderDocumentationSidebar(guidesFile) {
221223

222224
function renderGuideItems(guideItem, header) {
223225
const name = guideItem.name().split(' > ').pop();
226+
const className = header ? 'header' : '';
227+
const headerElement = guideItem.url() ?
228+
html`<a class="${className}" href="${guideItem.url()}">${name}</a>` :
229+
html`<span class="header">${name}</span>`;
224230
if (!guideItem.childItems())
225-
return html`<a class="${header ? 'header' : ''}" href="${guideItem.url()}">${name}</a>`;
231+
return headerElement;
226232
return html`
227-
<a class="${header ? 'header' : ''}" href="${guideItem.url()}">${name}</a>
233+
${headerElement}
228234
${guideItem.childItems().map(item => renderGuideItems(item, false))}
229235
`;
230236
}

src/markdownFile.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,36 @@ export class MarkdownFile {
5252
static parseDocumentationList({version, path, doc}) {
5353
const glossaryItems = [];
5454
const articleElement = html`<markdown-content>${doc}</markdown-content>`;
55-
dfs(doc, null);
55+
dfs(toc(doc), null);
5656
return new MarkdownFile(version, path, MarkdownFile.Type.DOCUMENTATION_LIST, glossaryItems);
5757

58+
function toc(element) {
59+
// Table of contents is an `ol` on the page
60+
return html`<markdown-content>${element.querySelector(':scope > ol')}</markdown-content>`;
61+
}
62+
5863
function dfs(element, parentItem) {
59-
const lists = element.querySelectorAll(':scope > ul, :scope > ol');
64+
const lists = element.querySelectorAll(':scope > ol, :scope > ul');
6065
for (const list of lists) {
6166
for (const li of list.querySelectorAll(':scope > li')) {
62-
const a = li.querySelector(':scope > a');
63-
if (!a || !a.href)
64-
continue;
67+
let el = li.querySelector(':scope > a') ? li.querySelector(':scope > a') : li;
6568
const parentText = parentItem ? parentItem.name() + ' > ' : '';
66-
const nameElement = html`${parentText}<strong>${a.textContent}</strong>`;
69+
// If el is li, title needs to exclude textContent from child links
70+
const title = el.childNodes[0].textContent.trim();
71+
const nameElement = html`${parentText}<strong>${title}</strong>`;
6772
const item = new GlossaryItem({
68-
githubLink: a.href,
73+
githubLink: el.href,
6974
parentItem,
7075
highlightable: false,
7176
articleElement,
7277
element: null,
7378
scrollAnchor: null,
74-
url: a.hash,
79+
url: el.hash,
7580
name: nameElement.textContent,
7681
needleIndexes: computeNeedleIndexes(nameElement),
7782
nameElement,
7883
description: null,
79-
title: a.textContent,
84+
title,
8085
type: GlossaryItem.Type.Other,
8186
});
8287
glossaryItems.push(item);

src/style.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ external-link-icon {
163163
color: var(--link-color);
164164
}
165165

166-
.sidebar-body > a.header {
166+
.sidebar-body > .header {
167167
color: black;
168168
font-size: 18px;
169169
margin: 15px 0 5px 0;

0 commit comments

Comments
 (0)