import get from 'lodash.get' import Link from 'next/link' import { useContext } from 'react' import { NavigationContext } from 'shared/context/navigation-context.mjs' import { RightIcon } from 'shared/components/icons.mjs' import { pageHasChildren } from 'shared/utils.mjs' import orderBy from 'lodash.orderby' export const getRoot = { dev: (root, nav) => { if (!root) return nav if (root.indexOf('/') === -1) return nav[root] return get(nav, root.split('/')) }, org: (root, nav) => { // Fixme: make this work for org if (!root) return nav if (root.indexOf('/') === -1) return get(nav, root) return get(nav, root.split('/')) }, } const onActivePath = (slug, active) => (active ? active.slice(0, slug.length) === slug : false) /* * This is a recursive function, so it needs to be lean */ const RenderTree = ({ tree, recurse, depth = 1, level = 0, active = false }) => { const orderedTree = orderBy(tree, ['o', 't'], ['asc', 'asc']) .filter((item) => typeof item === 'object') .filter((item) => !item.h) .filter((item) => !item._) return ( ) } export const ReadMore = ({ recurse = 0, root = false, site = 'org', asMenu = false, depth = 99, from = false, }) => { const { siteNav, slug } = useContext(NavigationContext) let active = false // Deal with recurse not being a number if (recurse && recurse !== true) { if (typeof recurse === 'number') recurse-- else recurse = 1 } // Deal with root being passed as true if (root === true) root = '' if (asMenu && slug.split('/').length > 1) { root = from ? from : slug.split('/').slice(0, -1).join('/') active = slug } const tree = root === false ? getRoot[site](from ? from : slug, siteNav) : getRoot[site](root, siteNav) if (!tree) return null return }