Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<h1 class="title">NetCord</h1>
<p class="subtitle">The modern and fully customizable C# Discord library</p>
<section class="buttons">
<a href="/guides/getting-started/installation.html" class="button primary-button">Get Started</a>
<a href="/guides/getting-started/installation.html" class="button secondary-button">Guides</a>
<a href="/docs/index.html" class="button secondary-button">Docs</a>
<a href="guides/getting-started/installation.html" class="button primary-button">Get Started</a>
<a href="guides/getting-started/installation.html" class="button secondary-button">Guides</a>
<a href="docs/index.html" class="button secondary-button">Docs</a>
</section>
</div>
34 changes: 11 additions & 23 deletions Documentation/templates-src/NetCord/src/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,19 @@ function inThisArticle(): TemplateResult {

function findActiveItem(items: (NavItem | NavItemContainer)[]): NavItem {
const url = new URL(window.location.href);
let activeItem: NavItem;
let maxPrefix = 1;
for (const item of items.map((i) => ("items" in i ? i.items : i)).flat()) {
if (isExternalHref(item.href)) {
continue;
}
const prefix = commonUrlPrefix(url, item.href);
if (prefix > maxPrefix) {
maxPrefix = prefix;
activeItem = item;
}
const href = item.href;
if (!isExternalHref(href) && commonUrl(url, href))
return item;
}
return activeItem;
}

function commonUrlPrefix(url: URL, base: URL): number {
const urlSegments = url.pathname.split("/");
const baseSegments = base.pathname.split("/");
let i = 1;
while (
i < urlSegments.length &&
i < baseSegments.length &&
urlSegments[i] === baseSegments[i]
) {
i++;
}
return i;
function commonUrl(url: URL, base: URL): boolean {
const urlPath = normalizePath(url.pathname);
const basePath = normalizePath(base.pathname);
return urlPath === basePath;
}

function normalizePath(url: string): string {
return url.replace(/\/(?:index.html)?$/, "/");
}