fix active page indicator on the sidebar being broken for some links
Took 9 minutes
This commit is contained in:
parent
54230367e1
commit
c4f7d4bf7e
@ -44,7 +44,7 @@ const CategoryItem = ({
|
|||||||
depth?: number;
|
depth?: number;
|
||||||
isLast?: boolean;
|
isLast?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const path = usePathname();
|
const path = decodeURIComponent(usePathname());
|
||||||
const active =
|
const active =
|
||||||
(path === "/" && node.slug === "intro") || path === `/${node.slug}`;
|
(path === "/" && node.slug === "intro") || path === `/${node.slug}`;
|
||||||
const [isOpen, setIsOpen] = useState(true);
|
const [isOpen, setIsOpen] = useState(true);
|
||||||
@ -136,16 +136,13 @@ const CategoryItem = ({
|
|||||||
const buildTree = (pages: DocsContentMetadata[]): Record<string, TreeNode> => {
|
const buildTree = (pages: DocsContentMetadata[]): Record<string, TreeNode> => {
|
||||||
const tree: Record<string, TreeNode> = {};
|
const tree: Record<string, TreeNode> = {};
|
||||||
|
|
||||||
// Sort pages by the order property
|
pages
|
||||||
const sortedPages = pages.sort(
|
.sort((a: DocsContentMetadata, b: DocsContentMetadata) => {
|
||||||
(a: DocsContentMetadata, b: DocsContentMetadata) => {
|
|
||||||
const orderA = a.order ?? Number.MAX_SAFE_INTEGER;
|
const orderA = a.order ?? Number.MAX_SAFE_INTEGER;
|
||||||
const orderB = b.order ?? Number.MAX_SAFE_INTEGER;
|
const orderB = b.order ?? Number.MAX_SAFE_INTEGER;
|
||||||
return orderA - orderB;
|
return orderA - orderB;
|
||||||
}
|
})
|
||||||
);
|
.forEach((page: DocsContentMetadata) => {
|
||||||
|
|
||||||
sortedPages.forEach((page: DocsContentMetadata) => {
|
|
||||||
const parts: string[] | undefined = page.slug?.split("/");
|
const parts: string[] | undefined = page.slug?.split("/");
|
||||||
let currentLevel = tree;
|
let currentLevel = tree;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user