Skip to content

Commit

Permalink
Fix: prev/next pages (#290)
Browse files Browse the repository at this point in the history
* refactor: navigation

* feat: add cli page

* fix: minor fixes

* fix: prev/next links

* refactor: prev/next links
  • Loading branch information
esemyonov authored Dec 18, 2023
1 parent f4629bc commit aa62a2f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/PrevNextLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { navigation } from "@/build/navigation.mjs";
import { useFindNavItemByLink } from "@/lib/hooks/useFindNavItemByLink";
import { NavCategory } from "@/lib/types";
import clsx from "classnames";
import Link from "next/link";

Expand Down Expand Up @@ -48,9 +49,17 @@ function PageLink({
</div>
);
}
function collect(array: Array<NavCategory>, result: Array<NavCategory>): void {
array.forEach((value) =>
value.items ? collect(value.items, result) : result.push(value),
);
}

export function PrevNextLinks() {
let allLinks = navigation.flatMap((section) => section.items);
let navigationLinks = navigation.flatMap((section) => section.items);
let allLinks: Array<NavCategory> = [];
collect(navigationLinks, allLinks);

let linkIndex = allLinks.findIndex(useFindNavItemByLink);
let previousPage = linkIndex > -1 ? allLinks[linkIndex - 1] : null;
let nextPage = linkIndex > -1 ? allLinks[linkIndex + 1] : null;
Expand Down

0 comments on commit aa62a2f

Please sign in to comment.