({
list,
route,
/** @default '' */
docsRoot = '',
/** @default DEFAULT_PAGE_THEME */
pageThemeContext = DEFAULT_PAGE_THEME
}: {
list: PageMapItem[]
route: string
docsRoot?: string
underCurrentDocsRoot?: boolean
pageThemeContext?: PageTheme
})
| 115 | } |
| 116 | |
| 117 | export function normalizePages({ |
| 118 | list, |
| 119 | route, |
| 120 | /** @default '' */ |
| 121 | docsRoot = '', |
| 122 | /** @default DEFAULT_PAGE_THEME */ |
| 123 | pageThemeContext = DEFAULT_PAGE_THEME |
| 124 | }: { |
| 125 | list: PageMapItem[] |
| 126 | route: string |
| 127 | docsRoot?: string |
| 128 | underCurrentDocsRoot?: boolean |
| 129 | pageThemeContext?: PageTheme |
| 130 | }): NormalizedResult { |
| 131 | // If the doc is under the active page root. |
| 132 | const underCurrentDocsRoot = route.startsWith(docsRoot) |
| 133 | const directories: Item[] = [] |
| 134 | const docsDirectories: DocsItem[] = [] |
| 135 | const flatDocsDirectories: DocsItem[] = [] |
| 136 | const topLevelNavbarItems: (PageItem | MenuItem)[] = [] |
| 137 | const firstItem = list[0]! // always exists |
| 138 | const meta = 'data' in firstItem ? (firstItem.data as MetaType) : {} |
| 139 | // Normalize items based on files and _meta.json. |
| 140 | const items = ('data' in firstItem ? list.slice(1) : list) as ( |
| 141 | | (Folder & { frontMatter?: FrontMatter }) |
| 142 | | MdxFile |
| 143 | )[] |
| 144 | |
| 145 | const fallbackMeta = meta['*'] || {} |
| 146 | |
| 147 | let activeType: NormalizedResult['activeType'] = fallbackMeta.type |
| 148 | let activeIndex = 0 |
| 149 | let activeThemeContext = { |
| 150 | ...pageThemeContext, |
| 151 | ...fallbackMeta.theme |
| 152 | } |
| 153 | let activePath: Item[] = [] |
| 154 | |
| 155 | for (const currentItem of items) { |
| 156 | // Get the item's meta information. |
| 157 | const extendedMeta = extendMeta( |
| 158 | meta[currentItem.name], |
| 159 | fallbackMeta, |
| 160 | currentItem.frontMatter |
| 161 | ) |
| 162 | const { display, type = 'doc' } = extendedMeta |
| 163 | const extendedPageThemeContext = { |
| 164 | ...pageThemeContext, |
| 165 | ...extendedMeta.theme |
| 166 | } |
| 167 | |
| 168 | const normalizedChildren: false | NormalizedResult = |
| 169 | 'children' in currentItem && |
| 170 | normalizePages({ |
| 171 | list: currentItem.children, |
| 172 | route, |
| 173 | docsRoot: |
| 174 | type === 'page' || type === 'menu' ? currentItem.route : docsRoot, |
no test coverage detected
searching dependent graphs…