MCPcopy
hub / github.com/shuding/nextra / normalizePages

Function normalizePages

packages/nextra/src/client/normalize-pages.ts:117–355  ·  view source on GitHub ↗
({
  list,
  route,
  /** @default '' */
  docsRoot = '',
  /** @default DEFAULT_PAGE_THEME */
  pageThemeContext = DEFAULT_PAGE_THEME
}: {
  list: PageMapItem[]
  route: string
  docsRoot?: string
  underCurrentDocsRoot?: boolean
  pageThemeContext?: PageTheme
})

Source from the content-addressed store, hash-verified

115}
116
117export 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,

Callers 6

NavbarFunction · 0.90
ConfigProviderFunction · 0.90
getPostsFunction · 0.90
NavbarFunction · 0.90
SidebarFunction · 0.90
normalize.test.tsFile · 0.85

Calls 3

extendMetaFunction · 0.85
getItemFunction · 0.85
findFirstRouteFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…