<%
async function renderRootItem(slug) {
  const [link, title] = await getPageLinkAndTitle(slug);
  return `<li class="section"><a href="${link}">${title}</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="XsltSidebar">
  <ol>
    <%- await renderRootItem("/docs/Web/XSLT") %>
    <%- await template("ListSubpagesForSidebar", ['/docs/Web/XSLT/Transforming_XML_with_XSLT', 1]) %>
  </ol>
  <ol>
    <%- await renderRootItem("/docs/Web/XSLT/Element") %>
    <%- await template("ListSubpagesForSidebar", ['/docs/Web/XSLT/Element', 1]) %>
  </ol>
  <ol>
    <%- await renderRootItem("/docs/Web/EXSLT") %>
    <%- await template("ListSubpagesForSidebar", ['/docs/Web/EXSLT', 1]) %>
  </ol>
  <ol>
    <%- await renderRootItem("/docs/Web/XPath/Functions") %>
    <%- await template("ListSubpagesForSidebar", ['/docs/Web/XPath/Functions', 1]) %>
  </ol>
  <ol>
    <%- await renderRootItem("/docs/Web/XPath/Axes") %>
  </ol>
</section>
