-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(macros): add GlossarySidebar macro (#8997)
Co-authored-by: Claas Augner <[email protected]>
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<% | ||
async function renderRootItem(slug) { | ||
const [link, title] = await getPageLinkAndTitle(slug); | ||
return `<li><a href="${link}"><strong>${title}</strong></a></li>` | ||
} | ||
async function getPageLinkAndTitle(slug) { | ||
let link = `/${env.locale}${slug}`; | ||
let page = await wiki.getPage(link); | ||
if (!page.title && env.locale !== 'en-US') { | ||
link = `/en-US${slug}`; | ||
page = await wiki.getPage(link); | ||
} | ||
let title = page.short_title || page.title; | ||
title = mdn.htmlEscape(title); | ||
return [link, title]; | ||
} | ||
%> | ||
|
||
<section id="Quick_links" data-macro="GlossarySidebar"> | ||
<ol> | ||
<%- await renderRootItem("/docs/Glossary") %> | ||
<%- await template("ListSubpagesForSidebar", ['/docs/Glossary', 1]) %> | ||
</ol> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters