fix page buttons on the docs page footer being broken for some links
All checks were successful
Deploy / deploy (ubuntu-latest, 2.44.0) (push) Successful in 1m9s

Took 3 minutes
This commit is contained in:
Braydon 2024-10-07 20:24:34 -04:00
parent c4f7d4bf7e
commit 71c24bd6cc
3 changed files with 24 additions and 26 deletions

View File

@ -13,7 +13,7 @@ const DocsFooter = ({
}: {
pages: DocsContentMetadata[];
}): ReactElement => {
const path: string = usePathname();
const path: string = decodeURIComponent(usePathname());
const current: number = pages.findIndex(
(page: DocsContentMetadata) =>

View File

@ -136,32 +136,26 @@ const CategoryItem = ({
const buildTree = (pages: DocsContentMetadata[]): Record<string, TreeNode> => {
const tree: Record<string, TreeNode> = {};
pages
.sort((a: DocsContentMetadata, b: DocsContentMetadata) => {
const orderA = a.order ?? Number.MAX_SAFE_INTEGER;
const orderB = b.order ?? Number.MAX_SAFE_INTEGER;
return orderA - orderB;
})
.forEach((page: DocsContentMetadata) => {
const parts: string[] | undefined = page.slug?.split("/");
let currentLevel = tree;
pages.forEach((page: DocsContentMetadata) => {
const parts: string[] | undefined = page.slug?.split("/");
let currentLevel = tree;
parts?.forEach((part: string, index: number) => {
if (!currentLevel[part]) {
currentLevel[part] = {
title: part,
slug: parts.slice(0, index + 1).join("/"),
isFolder: index < parts.length - 1,
children: {},
};
}
if (index === parts.length - 1) {
currentLevel[part].title = page.title;
currentLevel[part].isFolder = false;
}
currentLevel = currentLevel[part].children;
});
parts?.forEach((part: string, index: number) => {
if (!currentLevel[part]) {
currentLevel[part] = {
title: part,
slug: parts.slice(0, index + 1).join("/"),
isFolder: index < parts.length - 1,
children: {},
};
}
if (index === parts.length - 1) {
currentLevel[part].title = page.title;
currentLevel[part].isFolder = false;
}
currentLevel = currentLevel[part].children;
});
});
return tree;
};

View File

@ -21,7 +21,11 @@ export const getDocsContent = (): DocsContentMetadata[] => {
for (const directory of getRecursiveDirectories(DOCS_DIR)) {
content.push(...getMetadata<DocsContentMetadata>(DOCS_DIR, directory));
}
return content;
return content.sort((a: DocsContentMetadata, b: DocsContentMetadata) => {
const orderA = a.order ?? Number.MAX_SAFE_INTEGER;
const orderB = b.order ?? Number.MAX_SAFE_INTEGER;
return orderA - orderB;
});
};
/**