Skip to content

Commit

Permalink
feat(macros): add GlossarySidebar macro (#8997)
Browse files Browse the repository at this point in the history
Co-authored-by: Claas Augner <[email protected]>
  • Loading branch information
bsmth and caugner authored Jun 5, 2023
1 parent 2ff4a7b commit e704315
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions kumascript/macros/GlossarySidebar.ejs
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>
2 changes: 1 addition & 1 deletion kumascript/macros/ListSubpagesForSidebar.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function createLink(aPage) {
if (wrapInCode) {
linkContent = `<code>${linkContent}</code>`;
}
const pageBadges = (await page.badges(aPage)).join("");
const result = `<li><a href="${url}">${linkContent}</a>${pageBadges}</li>`;
Expand Down

0 comments on commit e704315

Please sign in to comment.