UNPKG

@mintlify/common

Version:

Commonly shared code within Mintlify

37 lines (36 loc) 1.21 kB
import { divisions, } from '@mintlify/validation'; import { isAbsoluteUrl } from '../isAbsoluteUrl.js'; import { optionallyRemoveLeadingSlash } from '../optionallyRemoveLeadingSlash.js'; import { isPage } from './isPage.js'; export function getAllPathsInDecoratedNav(nav, paths = []) { getPaths(nav, paths); return paths; } function getPaths(entry, paths) { if (isPage(entry)) { const internalPath = toInternalPath(entry.href); if (internalPath !== undefined) { paths.push(internalPath); } return; } if (entry.root != null && typeof entry.root === 'object') { getPaths(entry.root, paths); } if (Array.isArray(entry.pages)) { entry.pages.forEach((page) => getPaths(page, paths)); return; } for (const division of ['groups', ...divisions]) { const items = entry[division]; if (!Array.isArray(items)) continue; items.forEach((item) => getPaths(item, paths)); } } function toInternalPath(href) { if (!href || href.startsWith('#') || href.startsWith('//') || isAbsoluteUrl(href)) { return undefined; } return optionallyRemoveLeadingSlash(href); }