diff --git a/templates/modern/src/nav.ts b/templates/modern/src/nav.ts index f8ff91bd65c..52db4db0596 100644 --- a/templates/modern/src/nav.ts +++ b/templates/modern/src/nav.ts @@ -35,21 +35,20 @@ export async function renderNavbar(): Promise { } const menu = html` - ` } } @@ -131,6 +130,9 @@ function findActiveItem(items: (NavItem | NavItemContainer)[]): NavItem { let activeItem: NavItem let maxPrefix = 0 for (const item of items.map(i => 'items' in i ? i.items : i).flat()) { + if (item.href.hostname !== window.location.hostname || item.href.port !== window.location.port) { + continue + } const prefix = commonUrlPrefix(url, item.href) if (prefix > maxPrefix) { maxPrefix = prefix diff --git a/templates/modern/src/toc.ts b/templates/modern/src/toc.ts index b149a47ee42..ac33f45c2dc 100644 --- a/templates/modern/src/toc.ts +++ b/templates/modern/src/toc.ts @@ -54,7 +54,7 @@ export async function renderToc(): Promise { if (node.href) { const url = new URL(node.href, tocUrl) node.href = url.href - active = normalizeUrlPath(url) === normalizeUrlPath(window.location) + active = isExternal(url) ? false : normalizeUrlPath(url) === normalizeUrlPath(window.location) if (active) { if (node.items) { node.expanded = true @@ -79,6 +79,10 @@ export async function renderToc(): Promise { return false } + function isExternal(url: URL): boolean { + return url.hostname !== window.location.hostname || url.port !== window.location.port + } + function renderToc() { render(html`${renderTocFilter()} ${renderTocNodes(items) || renderNoFilterResult()}`, tocContainer) }