Skip to content

Commit

Permalink
fix: icons missing on empty navitems
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih committed Apr 20, 2023
1 parent 463a4ef commit 7831dfa
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions templates/modern/src/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,14 @@ export type NavItem = {
* @returns active navbar items
*/
export async function renderNavbar(): Promise<NavItem[]> {
const navrel = meta('docfx:navrel')
if (!navrel) {
return []
}

const navUrl = new URL(navrel.replace(/.html$/gi, '.json'), window.location.href)
const { items } = await fetch(navUrl).then(res => res.json())
const navItems = items.map(a => ({ name: a.name, href: new URL(a.href, navUrl) }))
if (navItems.length <= 0) {
return []
}

const activeItem = findActiveItem(navItems)
const navbar = document.getElementById('navbar')
if (!navbar) {
return
}

const navItems = await loadNavItems()
const activeItem = findActiveItem(navItems)

const menu = html`
<ul class='navbar-nav'>${
navItems.map(item => {
Expand All @@ -53,6 +43,17 @@ export async function renderNavbar(): Promise<NavItem[]> {

return activeItem ? [activeItem] : []

async function loadNavItems(): Promise<NavItem[]> {
const navrel = meta('docfx:navrel')
if (!navrel) {
return []
}

const navUrl = new URL(navrel.replace(/.html$/gi, '.json'), window.location.href)
const { items } = await fetch(navUrl).then(res => res.json())
return items.map(a => ({ name: a.name, href: new URL(a.href, navUrl) }))
}

function githubLink() {
const docurl = meta('docfx:docurl')
const github = parseGitHubRepo(docurl)
Expand Down

0 comments on commit 7831dfa

Please sign in to comment.