-
Home
- {section && (
- <>
-
-
{section.label}
- >
- )}
+
+ {breadcrumbItems.map((item, index) => (
+
+ {!!item?.href ? (
+
{item.label}
+ ) : (
+
{item.label}
+ )}
+ {index < breadcrumbItems.length - 1 &&
}
+
+ ))}
{tableOfContents && (
diff --git a/src/components/Navigation.tsx b/src/components/Navigation.tsx
index ddd7a088..9b35ac64 100644
--- a/src/components/Navigation.tsx
+++ b/src/components/Navigation.tsx
@@ -6,16 +6,17 @@ import ChevronDownIcon from "@/components/svgs/chevron-down.svg";
import ArrowIcon from "@/components/svgs/arrow.svg";
import { navigation } from "@/build/navigation.mjs";
-import { NavCategory, NavItem } from "@/lib/types";
import { useState } from "react";
+import { NavCategory } from "@/lib/types";
+import { NavigationType } from "@/lib/enums/navigation-type";
function SubNavSection({
- link,
+ navItem,
onLinkClick,
depth,
linkClassName,
}: {
- link: NavCategory;
+ navItem: NavCategory;
onLinkClick?: React.MouseEventHandler
;
depth: number;
linkClassName: string;
@@ -23,7 +24,8 @@ function SubNavSection({
const pathname = usePathname();
const chevronClassName = "absolute left-0 top-0";
const [hidden, setHidden] = useState(
- !link.items.some((l) => "href" in l && l.href === pathname),
+ !!navItem?.items &&
+ !navItem.items.some((item) => !!item?.href && item.href === pathname),
);
function onClick() {
@@ -41,12 +43,22 @@ function SubNavSection({
) : (
)}
-
- {link.label}
-
+ {!!navItem.href && hidden ? (
+
+ {navItem.label}
+
+ ) : (
+
+ {navItem.label}
+
+ )}
- {link.items.map((link, i) => (
-
- ))}
+ {!!navItem?.items &&
+ navItem.items.map((item, i) => (
+
+ ))}
);
}
function NavSection({
- link,
+ navItem,
onLinkClick,
depth,
}: {
- link: NavCategory | NavItem;
+ navItem: NavCategory;
onLinkClick?: React.MouseEventHandler;
depth: number;
}) {
const pathname = usePathname();
const linkClassName =
- "block w-full px-6 leading-6 tracking-wider transition-all hover:text-pink hover:text-shadow cursor-pointer";
+ "block w-full px-6 leading-6 tracking-wider transition-all hover:text-pink hover:text-shadow cursor-pointer relative";
- if ("href" in link) {
- return (
-
-
+ {navItem?.type === NavigationType.SUB_CATEGORY ? (
+
+ ) : (
+ <>
+ {!!navItem?.href && (
+
+
+ {navItem.label}
+ {navItem?.isExternal && (
+
+ )}
+
+
)}
- >
- {link.label}
-
-
-
- );
- } else {
- return (
-
- );
- }
+ >
+ )}
+ >
+ );
}
export function Navigation({
@@ -118,20 +140,27 @@ export function Navigation({
return (
- {navigation.map((section) => (
+ {navigation.map((section: NavCategory) => (
-
- {section.label}
-
+ {section?.type === NavigationType.CATEGORY && (
+
+ {section?.href ? (
+ {section.label}
+ ) : (
+ <>{section.label}>
+ )}
+
+ )}
- {section.items.map((link, i) => (
-
- ))}
+ {!!section?.items &&
+ section?.items.map((navItem, i) => (
+
+ ))}
))}
diff --git a/src/components/PrevNextLinks.tsx b/src/components/PrevNextLinks.tsx
index 0a971ee1..1f83cca6 100644
--- a/src/components/PrevNextLinks.tsx
+++ b/src/components/PrevNextLinks.tsx
@@ -1,10 +1,9 @@
"use client";
import { navigation } from "@/build/navigation.mjs";
-import { NavCategory, NavItem } from "@/lib/types";
+import { useFindNavItemByLink } from "@/lib/hooks/useFindNavItemByLink";
import clsx from "classnames";
import Link from "next/link";
-import { usePathname } from "next/navigation";
function ArrowIcon(props: React.ComponentPropsWithoutRef<"svg">) {
return (
@@ -51,17 +50,8 @@ function PageLink({
}
export function PrevNextLinks() {
- let pathname = usePathname();
- const findLink = (link: NavCategory | NavItem): boolean => {
- if ("href" in link) {
- return link.href === pathname.split("#")[0];
- } else {
- return link.items.some(findLink);
- }
- };
-
let allLinks = navigation.flatMap((section) => section.items);
- let linkIndex = allLinks.findIndex(findLink);
+ let linkIndex = allLinks.findIndex(useFindNavItemByLink);
let previousPage = linkIndex > -1 ? allLinks[linkIndex - 1] : null;
let nextPage = linkIndex > -1 ? allLinks[linkIndex + 1] : null;
@@ -71,11 +61,19 @@ export function PrevNextLinks() {
return (
- {previousPage && "href" in previousPage && (
-
+ {previousPage && !!previousPage?.href && (
+
)}
- {nextPage && "href" in nextPage && (
-
+ {nextPage && !!nextPage?.href && (
+
)}
);
diff --git a/src/components/Search.tsx b/src/components/Search.tsx
index 1985d2d1..8b48bf63 100644
--- a/src/components/Search.tsx
+++ b/src/components/Search.tsx
@@ -2,7 +2,7 @@
import { navigation } from "@/build/navigation.mjs";
import { type Result } from "@/build/search.mjs";
-import { NavCategory, NavItem } from "@/lib/types";
+import { useFindNavItemByLink } from "@/lib/hooks/useFindNavItemByLink";
import {
createAutocomplete,
type AutocompleteApi,
@@ -160,17 +160,9 @@ function SearchResult({
query: string;
}) {
let id = useId();
-
- const findLink = (link: NavCategory | NavItem): boolean => {
- if ("href" in link) {
- return link.href === result.url.split("#")[0];
- } else {
- return link.items.some(findLink);
- }
- };
-
- let sectionTitle = navigation.find((section) => section.items.find(findLink))
- ?.label;
+ let sectionTitle = navigation.find((section) =>
+ section.items.find(useFindNavItemByLink),
+ )?.label;
let hierarchy = [sectionTitle, result.pageTitle].filter(
(x): x is string => typeof x === "string",
);
diff --git a/src/lib/enums/navigation-type.tsx b/src/lib/enums/navigation-type.tsx
new file mode 100644
index 00000000..833ed3e9
--- /dev/null
+++ b/src/lib/enums/navigation-type.tsx
@@ -0,0 +1,4 @@
+export enum NavigationType {
+ CATEGORY = "category",
+ SUB_CATEGORY = "sub_category",
+}
diff --git a/src/lib/hooks/useFindNavItemByLink.ts b/src/lib/hooks/useFindNavItemByLink.ts
new file mode 100644
index 00000000..f33adcce
--- /dev/null
+++ b/src/lib/hooks/useFindNavItemByLink.ts
@@ -0,0 +1,11 @@
+import { NavCategory } from "@/lib/types";
+import { usePathname } from "next/navigation";
+
+export function useFindNavItemByLink(navItem: NavCategory) {
+ const pathname = usePathname();
+
+ return (
+ navItem.href === pathname.split("#")[0] ||
+ (!!navItem?.items && navItem.items.some(useFindNavItemByLink))
+ );
+}
diff --git a/src/lib/policies.ts b/src/lib/policies.ts
index f52e6dec..9425cef3 100644
--- a/src/lib/policies.ts
+++ b/src/lib/policies.ts
@@ -64,7 +64,7 @@ export async function getPolicy(policyId: string) {
isPaidAddOn: !!schema.isPaidAddOn,
isDeprecated: !!schema.isDeprecated,
fakePolicyUrl: schema.fakePolicyUrl,
- href: `/docs/policies/${policyId}/`,
+ href: `/policies/${policyId}/`,
id: policyId,
icon,
};
diff --git a/src/lib/types.ts b/src/lib/types.ts
index 22da1d86..ec470cdd 100644
--- a/src/lib/types.ts
+++ b/src/lib/types.ts
@@ -1,5 +1,6 @@
import { JSONSchema7 } from "json-schema";
import { Icon } from "@/components/Icon";
+import { NavigationType } from "@/lib/enums/navigation-type";
export type PolicyMeta = {
name: string;
@@ -39,12 +40,10 @@ export type Bundle = {
export type NavCategory = {
label: string;
- items: Array;
-};
-
-export type NavItem = {
- label: string;
- href: string;
+ href?: string;
+ type?: NavigationType;
+ isExternal?: boolean;
+ items?: Array;
};
export type QuickLinkItem = {
diff --git a/tsconfig.json b/tsconfig.json
index 52eebd56..a92c29ed 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -25,5 +25,11 @@
}
},
"exclude": ["policies/**", "node_modules"],
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"]
+ "include": [
+ "next-env.d.ts",
+ "**/*.ts",
+ "**/*.tsx",
+ ".next/types/**/*.ts",
+ "src/lib/enums/navigation-type.tsx"
+ ]
}
diff --git a/types.d.ts b/types.d.ts
index d9f0bf18..85527ce2 100644
--- a/types.d.ts
+++ b/types.d.ts
@@ -1,7 +1,6 @@
declare module "remark-admonitions";
declare module "badwords-list";
declare module "simple-functional-loader";
-import { NavCategory } from "@/lib/types";
import { type SearchOptions } from "flexsearch";
declare module "@/build/search.mjs" {
@@ -15,5 +14,5 @@ declare module "@/build/search.mjs" {
}
declare module "@/build/navigation.mjs" {
- export const navigation: NavCategory[];
+ export const navigation: Array;
}