mirror of
https://github.com/expressjs/expressjs.com.git
synced 2026-02-21 19:41:33 +00:00
fix: active menu items
This commit is contained in:
@@ -31,6 +31,8 @@ const {
|
||||
const lang = getLangFromUrl(Astro.url);
|
||||
const currentPath = Astro.url.pathname;
|
||||
const currentVersion = detectVersionFromUrl(currentPath, versions, defaultVersion);
|
||||
|
||||
console.log('Astro pathname', currentPath);
|
||||
---
|
||||
|
||||
<div id="sidebarBackdrop" class="sidebar-backdrop" aria-hidden="true" data-sidebar-backdrop></div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
import type { MenuItem } from '@/config/types';
|
||||
import SidebarNavItem from './SidebarNavItem.astro';
|
||||
import { isLink, hasSubmenu, filterItems, getItemId, resolveHref } from './utils';
|
||||
import { isLink, hasSubmenu, filterItems, getItemId, resolveHref, normalizePath } from './utils';
|
||||
|
||||
interface Props {
|
||||
items: MenuItem[];
|
||||
@@ -38,7 +38,7 @@ const filteredItems = filterItems(items, version);
|
||||
filteredItems.map((item, itemIndex) => {
|
||||
const itemId = getItemId(parentId, sectionIndex, itemIndex);
|
||||
const href = isLink(item) ? resolveHref(item.href, lang, basePath, versioned, version) : '';
|
||||
const isActive = currentPath === href;
|
||||
const isActive = normalizePath(currentPath) === normalizePath(href);
|
||||
|
||||
return isLink(item) ? (
|
||||
<SidebarNavItem
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
import type { Menu } from '@/config/types';
|
||||
import type { VersionConfig } from '@/components/patterns/VersionSwitcher/types';
|
||||
import { Body, BodyMd } from '@/components/primitives';
|
||||
import { Body } from '@/components/primitives';
|
||||
import { Icon } from 'astro-icon/components';
|
||||
import { ThemeSwitcher, VersionSwitcher } from '@/components/patterns';
|
||||
import { VersionSwitcher } from '@/components/patterns';
|
||||
import SidebarItemsList from './SidebarItemsList.astro';
|
||||
import {
|
||||
shouldOmitSection,
|
||||
|
||||
@@ -10,6 +10,10 @@ export type SubmenuData = {
|
||||
level: number;
|
||||
};
|
||||
|
||||
export function normalizePath(path: string): string {
|
||||
return path.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
export function resolveHref(
|
||||
href: string,
|
||||
lang: string,
|
||||
@@ -123,7 +127,6 @@ function checkItemsForPath(
|
||||
for (const item of filteredItems) {
|
||||
if (isLink(item)) {
|
||||
const href = resolveHref(item.href, lang, basePath, versioned, version);
|
||||
const normalizePath = (path: string) => path.replace(/\/$/, '');
|
||||
if (normalizedCurrentPath === normalizePath(href)) {
|
||||
return true;
|
||||
}
|
||||
@@ -156,7 +159,6 @@ export function submenuContainsCurrentPath(
|
||||
lang: string,
|
||||
version: string
|
||||
): boolean {
|
||||
const normalizePath = (path: string) => path.replace(/\/$/, '');
|
||||
const normalizedCurrentPath = normalizePath(currentPath);
|
||||
|
||||
for (const section of submenuMenu.sections?.filter((s) => !shouldOmitSection(s, version)) || []) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user