MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / useSiteNavigation

Function useSiteNavigation

apps/site/hooks/useSiteNavigation.ts:39–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37 );
38
39const useSiteNavigation = () => {
40 const t = useTranslations();
41
42 const mapNavigationEntries = (entries: Navigation, context: Context = {}) => {
43 const getFormattedMessage = (label: IntlMessageKeys, key: string) =>
44 t.rich(label, context[key] || {}) as FormattedMessage;
45
46 return Object.entries(entries).map(
47 ([key, { label, link, items, target }]): [
48 string,
49 MappedNavigationEntry,
50 ] => [
51 key,
52 {
53 target,
54 label: label ? getFormattedMessage(label, key) : '',
55 link: link ? replaceLinkWithContext(link, context[key]) : '',
56 items: items ? mapNavigationEntries(items, context) : [],
57 },
58 ]
59 );
60 };
61
62 const getSideNavigation = (
63 keys: Array<NavigationKeys>,
64 context: Context = {}
65 ) => {
66 const navigationEntries: Navigation = keys.reduce(
67 (acc, key) => ({ ...acc, [key]: siteNavigation.sideNavigation[key] }),
68 {}
69 );
70
71 return mapNavigationEntries(navigationEntries, context);
72 };
73
74 const navigationItems = mapNavigationEntries(siteNavigation.topNavigation);
75
76 return { getSideNavigation, navigationItems };
77};
78
79export default useSiteNavigation;

Callers 4

WithNavBarFunction · 0.85
WithBreadcrumbsFunction · 0.85
WithSidebarFunction · 0.85
WithSidebarCrossLinksFunction · 0.85

Calls 1

mapNavigationEntriesFunction · 0.85

Tested by

no test coverage detected