@astrojs/starlight 0.41.11 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (402) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +13 -0
  2. package/dist/components/MobileMenuToggle.astro +65 -0
  3. package/{components → dist/components}/PageFrame.astro +32 -8
  4. package/dist/components-internals/Icons.d.ts +415 -0
  5. package/dist/components-internals/Icons.js +140 -0
  6. package/dist/components-internals/SidebarPersistState.d.ts +1 -0
  7. package/dist/components-internals/SidebarPersistState.js +53 -0
  8. package/dist/components-internals/TableOfContents/starlight-toc.d.ts +18 -0
  9. package/dist/components-internals/TableOfContents/starlight-toc.js +88 -0
  10. package/dist/constants.d.ts +4 -0
  11. package/dist/constants.js +4 -0
  12. package/{expressive-code.d.ts → dist/expressive-code.d.ts} +6 -13
  13. package/dist/expressive-code.js +31 -0
  14. package/dist/global.d.ts +62 -0
  15. package/dist/global.js +2 -0
  16. package/dist/index.d.ts +7 -0
  17. package/dist/index.js +109 -0
  18. package/dist/integrations/aside-utils.d.ts +9 -0
  19. package/dist/integrations/aside-utils.js +35 -0
  20. package/dist/integrations/expressive-code/hast.d.ts +1 -0
  21. package/dist/integrations/expressive-code/hast.js +2 -0
  22. package/dist/integrations/expressive-code/index.d.ts +60 -0
  23. package/dist/integrations/expressive-code/index.js +48 -0
  24. package/dist/integrations/expressive-code/preprocessor.d.ts +17 -0
  25. package/dist/integrations/expressive-code/preprocessor.js +76 -0
  26. package/dist/integrations/expressive-code/themes/night-owl-dark.js +4 -0
  27. package/dist/integrations/expressive-code/themes/night-owl-light.js +4 -0
  28. package/dist/integrations/expressive-code/theming.d.ts +16 -0
  29. package/dist/integrations/expressive-code/theming.js +71 -0
  30. package/dist/integrations/expressive-code/translations.d.ts +8 -0
  31. package/dist/integrations/expressive-code/translations.js +26 -0
  32. package/dist/integrations/markdown-icon.d.ts +8 -0
  33. package/dist/integrations/markdown-icon.js +14 -0
  34. package/dist/integrations/markdown-plugins.d.ts +18 -0
  35. package/dist/integrations/markdown-plugins.js +36 -0
  36. package/dist/integrations/markdown-processor.d.ts +29 -0
  37. package/dist/integrations/markdown-processor.js +44 -0
  38. package/dist/integrations/pagefind.d.ts +7 -0
  39. package/dist/integrations/pagefind.js +34 -0
  40. package/dist/integrations/rehype-code-rtl-support.d.ts +21 -0
  41. package/dist/integrations/rehype-code-rtl-support.js +36 -0
  42. package/dist/integrations/rehype-heading-links.d.ts +10 -0
  43. package/dist/integrations/rehype-heading-links.js +57 -0
  44. package/dist/integrations/remark-asides.d.ts +32 -0
  45. package/dist/integrations/remark-asides.js +166 -0
  46. package/dist/integrations/remark-rehype.d.ts +17 -0
  47. package/dist/integrations/remark-rehype.js +51 -0
  48. package/dist/integrations/satteri.d.ts +13 -0
  49. package/dist/integrations/satteri.js +209 -0
  50. package/dist/integrations/shared/absolutePathToLang.d.ts +10 -0
  51. package/dist/integrations/shared/absolutePathToLang.js +13 -0
  52. package/dist/integrations/shared/localeToLang.d.ts +10 -0
  53. package/dist/integrations/shared/localeToLang.js +13 -0
  54. package/dist/integrations/shared/slugToLocale.d.ts +12 -0
  55. package/dist/integrations/shared/slugToLocale.js +15 -0
  56. package/dist/integrations/sitemap.d.ts +12 -0
  57. package/dist/integrations/sitemap.js +19 -0
  58. package/dist/integrations/vite-layer-order.d.ts +15 -0
  59. package/dist/integrations/vite-layer-order.js +56 -0
  60. package/dist/integrations/vite-lazy-barrel-optimization.d.ts +12 -0
  61. package/dist/integrations/vite-lazy-barrel-optimization.js +33 -0
  62. package/dist/integrations/vite-virtual-modules.d.ts +14 -0
  63. package/dist/integrations/vite-virtual-modules.js +108 -0
  64. package/dist/internal.d.ts +3 -0
  65. package/dist/internal.js +3 -0
  66. package/dist/loaders.d.ts +20 -0
  67. package/dist/loaders.js +49 -0
  68. package/dist/locals.d.ts +15 -0
  69. package/dist/locals.js +33 -0
  70. package/dist/package.js +4 -0
  71. package/{props.ts → dist/props.d.ts} +6 -4
  72. package/dist/props.js +1 -0
  73. package/dist/route-data.d.ts +7 -0
  74. package/dist/route-data.js +6 -0
  75. package/dist/schema.d.ts +426 -0
  76. package/dist/schema.js +103 -0
  77. package/dist/schemas/badge.d.ts +86 -0
  78. package/dist/schemas/badge.js +39 -0
  79. package/dist/schemas/components.d.ts +236 -0
  80. package/dist/schemas/components.js +36 -0
  81. package/dist/schemas/expressiveCode.d.ts +7 -0
  82. package/dist/schemas/expressiveCode.js +5 -0
  83. package/dist/schemas/favicon.d.ts +9 -0
  84. package/dist/schemas/favicon.js +32 -0
  85. package/dist/schemas/head.d.ts +33 -0
  86. package/dist/schemas/head.js +41 -0
  87. package/dist/schemas/hero.d.ts +319 -0
  88. package/dist/schemas/hero.js +73 -0
  89. package/dist/schemas/i18n.d.ts +125 -0
  90. package/dist/schemas/i18n.js +76 -0
  91. package/dist/schemas/icon.d.ts +284 -0
  92. package/dist/schemas/icon.js +7 -0
  93. package/dist/schemas/locale.d.ts +20 -0
  94. package/dist/schemas/locale.js +11 -0
  95. package/dist/schemas/logo.d.ts +32 -0
  96. package/dist/schemas/logo.js +14 -0
  97. package/dist/schemas/pagefind.d.ts +166 -0
  98. package/dist/schemas/pagefind.js +31 -0
  99. package/dist/schemas/prevNextLink.d.ts +10 -0
  100. package/dist/schemas/prevNextLink.js +14 -0
  101. package/dist/schemas/sidebar.d.ts +205 -0
  102. package/dist/schemas/sidebar.js +71 -0
  103. package/dist/schemas/site-title.d.ts +7 -0
  104. package/dist/schemas/site-title.js +17 -0
  105. package/dist/schemas/social.d.ts +292 -0
  106. package/dist/schemas/social.js +18 -0
  107. package/dist/schemas/tableOfContents.d.ts +24 -0
  108. package/dist/schemas/tableOfContents.js +16 -0
  109. package/dist/translations/ar.js +36 -0
  110. package/dist/translations/ca.js +46 -0
  111. package/dist/translations/cs.js +46 -0
  112. package/dist/translations/da.js +33 -0
  113. package/dist/translations/de.js +33 -0
  114. package/dist/translations/el.js +33 -0
  115. package/dist/translations/en.js +33 -0
  116. package/dist/translations/es.js +46 -0
  117. package/dist/translations/fa.js +33 -0
  118. package/dist/translations/fi.js +33 -0
  119. package/dist/translations/fr.js +36 -0
  120. package/dist/translations/gl.js +46 -0
  121. package/dist/translations/he.js +33 -0
  122. package/dist/translations/hi.js +36 -0
  123. package/dist/translations/hu.js +46 -0
  124. package/dist/translations/id.js +33 -0
  125. package/dist/translations/index.d.ts +48 -0
  126. package/dist/translations/index.js +75 -0
  127. package/dist/translations/it.js +36 -0
  128. package/dist/translations/ja.js +36 -0
  129. package/dist/translations/ko.js +36 -0
  130. package/dist/translations/lv.js +33 -0
  131. package/dist/translations/nb.js +33 -0
  132. package/dist/translations/nl.js +33 -0
  133. package/dist/translations/pl.js +36 -0
  134. package/dist/translations/pt.js +36 -0
  135. package/dist/translations/ro.js +33 -0
  136. package/dist/translations/ru.js +36 -0
  137. package/dist/translations/sk.js +33 -0
  138. package/dist/translations/sv.js +33 -0
  139. package/dist/translations/th.js +33 -0
  140. package/dist/translations/tr.js +33 -0
  141. package/dist/translations/uk.js +33 -0
  142. package/dist/translations/vi.js +33 -0
  143. package/dist/translations/zh-CN.js +36 -0
  144. package/dist/translations/zh-TW.js +36 -0
  145. package/dist/types.d.ts +4 -0
  146. package/dist/types.js +1 -0
  147. package/{user-components → dist/user-components}/FileTree.astro +1 -1
  148. package/{user-components → dist/user-components}/Steps.astro +1 -1
  149. package/{user-components → dist/user-components}/TabItem.astro +1 -1
  150. package/{user-components → dist/user-components}/Tabs.astro +1 -1
  151. package/dist/user-components/file-tree-icons.d.ts +178 -0
  152. package/dist/user-components/file-tree-icons.js +632 -0
  153. package/dist/user-components/file-tree-processor.d.ts +16 -0
  154. package/dist/user-components/file-tree-processor.js +132 -0
  155. package/dist/user-components/steps-processor.d.ts +10 -0
  156. package/dist/user-components/steps-processor.js +39 -0
  157. package/dist/user-components/tabs-processor.d.ts +23 -0
  158. package/dist/user-components/tabs-processor.js +70 -0
  159. package/dist/utils/base.d.ts +7 -0
  160. package/dist/utils/base.js +15 -0
  161. package/dist/utils/canonical.d.ts +10 -0
  162. package/dist/utils/canonical.js +14 -0
  163. package/dist/utils/collection-fs.d.ts +13 -0
  164. package/dist/utils/collection-fs.js +19 -0
  165. package/{utils/collection.ts → dist/utils/collection.d.ts} +9 -20
  166. package/dist/utils/collection.js +26 -0
  167. package/dist/utils/createPathFormatter.d.ts +9 -0
  168. package/dist/utils/createPathFormatter.js +35 -0
  169. package/dist/utils/createTranslationSystem.d.ts +23 -0
  170. package/dist/utils/createTranslationSystem.js +84 -0
  171. package/dist/utils/error-map.d.ts +23 -0
  172. package/dist/utils/error-map.js +125 -0
  173. package/dist/utils/format-path.d.ts +4 -0
  174. package/dist/utils/format-path.js +9 -0
  175. package/dist/utils/generateToC.d.ts +14 -0
  176. package/dist/utils/generateToC.js +25 -0
  177. package/dist/utils/git.d.ts +12 -0
  178. package/dist/utils/git.js +71 -0
  179. package/dist/utils/gitInlined.d.ts +6 -0
  180. package/dist/utils/gitInlined.js +11 -0
  181. package/dist/utils/head.d.ts +7 -0
  182. package/dist/utils/head.js +233 -0
  183. package/dist/utils/i18n.d.ts +50 -0
  184. package/dist/utils/i18n.js +141 -0
  185. package/dist/utils/localizedUrl.d.ts +8 -0
  186. package/dist/utils/localizedUrl.js +28 -0
  187. package/dist/utils/navigation.d.ts +19 -0
  188. package/dist/utils/navigation.js +353 -0
  189. package/dist/utils/path.d.ts +21 -0
  190. package/dist/utils/path.js +51 -0
  191. package/dist/utils/plugins.d.ts +721 -0
  192. package/dist/utils/plugins.js +174 -0
  193. package/dist/utils/routing/data.d.ts +20 -0
  194. package/dist/utils/routing/data.js +127 -0
  195. package/dist/utils/routing/index.d.ts +21 -0
  196. package/dist/utils/routing/index.js +106 -0
  197. package/dist/utils/routing/middleware.d.ts +11 -0
  198. package/dist/utils/routing/middleware.js +65 -0
  199. package/dist/utils/routing/types.d.ts +93 -0
  200. package/dist/utils/routing/types.js +1 -0
  201. package/dist/utils/slugs.d.ts +45 -0
  202. package/dist/utils/slugs.js +104 -0
  203. package/dist/utils/starlight-page.d.ts +36 -0
  204. package/dist/utils/starlight-page.js +120 -0
  205. package/dist/utils/translations-fs.d.ts +15 -0
  206. package/dist/utils/translations-fs.js +39 -0
  207. package/dist/utils/translations.d.ts +20 -0
  208. package/dist/utils/translations.js +29 -0
  209. package/dist/utils/types.d.ts +5 -0
  210. package/dist/utils/types.js +1 -0
  211. package/dist/utils/url.d.ts +7 -0
  212. package/{utils/url.ts → dist/utils/url.js} +5 -4
  213. package/dist/utils/user-config.d.ts +2055 -0
  214. package/dist/utils/user-config.js +136 -0
  215. package/dist/utils/validateLogoImports.d.ts +5 -0
  216. package/dist/utils/validateLogoImports.js +16 -0
  217. package/dist/utils/zodDeepMerge.d.ts +16 -0
  218. package/dist/utils/zodDeepMerge.js +53 -0
  219. package/package.json +60 -34
  220. package/CHANGELOG.md +0 -3051
  221. package/components/MobileMenuToggle.astro +0 -114
  222. package/components-internals/Icons.ts +0 -248
  223. package/components-internals/SidebarPersistState.ts +0 -71
  224. package/components-internals/TableOfContents/starlight-toc.ts +0 -127
  225. package/constants.ts +0 -4
  226. package/expressive-code.mjs +0 -23
  227. package/global.d.ts +0 -11
  228. package/i18n.d.ts +0 -18
  229. package/index.ts +0 -200
  230. package/integrations/aside-utils.ts +0 -41
  231. package/integrations/expressive-code/hast.d.ts +0 -5
  232. package/integrations/expressive-code/hast.mjs +0 -9
  233. package/integrations/expressive-code/index.ts +0 -125
  234. package/integrations/expressive-code/preprocessor.ts +0 -126
  235. package/integrations/expressive-code/themes/night-owl-dark.jsonc +0 -1796
  236. package/integrations/expressive-code/themes/night-owl-light.jsonc +0 -1695
  237. package/integrations/expressive-code/theming.ts +0 -105
  238. package/integrations/expressive-code/translations.ts +0 -36
  239. package/integrations/markdown-icon.ts +0 -13
  240. package/integrations/markdown-plugins.ts +0 -71
  241. package/integrations/markdown-processor.ts +0 -64
  242. package/integrations/pagefind.ts +0 -60
  243. package/integrations/rehype-code-rtl-support.ts +0 -37
  244. package/integrations/rehype-heading-links.ts +0 -79
  245. package/integrations/remark-asides.ts +0 -219
  246. package/integrations/remark-rehype.ts +0 -87
  247. package/integrations/satteri.ts +0 -265
  248. package/integrations/shared/absolutePathToLang.ts +0 -26
  249. package/integrations/shared/localeToLang.ts +0 -15
  250. package/integrations/shared/slugToLocale.ts +0 -18
  251. package/integrations/sitemap.ts +0 -23
  252. package/integrations/vite-layer-order.ts +0 -69
  253. package/integrations/vite-lazy-barrel-optimization.ts +0 -40
  254. package/integrations/vite-virtual-modules.ts +0 -175
  255. package/internal.ts +0 -6
  256. package/loaders.ts +0 -63
  257. package/locals.d.ts +0 -43
  258. package/locals.ts +0 -43
  259. package/route-data.ts +0 -11
  260. package/schema.ts +0 -167
  261. package/schemas/badge.ts +0 -40
  262. package/schemas/components.ts +0 -265
  263. package/schemas/expressiveCode.ts +0 -12
  264. package/schemas/favicon.ts +0 -40
  265. package/schemas/head.ts +0 -50
  266. package/schemas/hero.ts +0 -69
  267. package/schemas/i18n.ts +0 -244
  268. package/schemas/icon.ts +0 -7
  269. package/schemas/logo.ts +0 -28
  270. package/schemas/pagefind.ts +0 -128
  271. package/schemas/prevNextLink.ts +0 -18
  272. package/schemas/sidebar.ts +0 -163
  273. package/schemas/site-title.ts +0 -20
  274. package/schemas/social.ts +0 -23
  275. package/schemas/tableOfContents.ts +0 -21
  276. package/translations/README.md +0 -14
  277. package/translations/ar.json +0 -33
  278. package/translations/ca.json +0 -43
  279. package/translations/cs.json +0 -43
  280. package/translations/da.json +0 -30
  281. package/translations/de.json +0 -30
  282. package/translations/el.json +0 -30
  283. package/translations/en.json +0 -30
  284. package/translations/es.json +0 -43
  285. package/translations/fa.json +0 -30
  286. package/translations/fi.json +0 -30
  287. package/translations/fr.json +0 -33
  288. package/translations/gl.json +0 -43
  289. package/translations/he.json +0 -30
  290. package/translations/hi.json +0 -33
  291. package/translations/hu.json +0 -43
  292. package/translations/id.json +0 -30
  293. package/translations/index.ts +0 -76
  294. package/translations/it.json +0 -33
  295. package/translations/ja.json +0 -33
  296. package/translations/ko.json +0 -33
  297. package/translations/lv.json +0 -30
  298. package/translations/nb.json +0 -30
  299. package/translations/nl.json +0 -30
  300. package/translations/pl.json +0 -33
  301. package/translations/pt.json +0 -33
  302. package/translations/ro.json +0 -30
  303. package/translations/ru.json +0 -33
  304. package/translations/sk.json +0 -30
  305. package/translations/sv.json +0 -30
  306. package/translations/th.json +0 -30
  307. package/translations/tr.json +0 -30
  308. package/translations/uk.json +0 -30
  309. package/translations/vi.json +0 -30
  310. package/translations/zh-CN.json +0 -33
  311. package/translations/zh-TW.json +0 -33
  312. package/types.ts +0 -7
  313. package/user-components/file-tree-icons.ts +0 -782
  314. package/user-components/rehype-file-tree.ts +0 -251
  315. package/user-components/rehype-steps.ts +0 -85
  316. package/user-components/rehype-tabs.ts +0 -121
  317. package/utils/base.ts +0 -15
  318. package/utils/canonical.ts +0 -19
  319. package/utils/collection-fs.ts +0 -20
  320. package/utils/createPathFormatter.ts +0 -60
  321. package/utils/createTranslationSystem.ts +0 -137
  322. package/utils/error-map.ts +0 -222
  323. package/utils/format-path.ts +0 -7
  324. package/utils/generateToC.ts +0 -33
  325. package/utils/git.ts +0 -121
  326. package/utils/gitInlined.ts +0 -20
  327. package/utils/head.ts +0 -235
  328. package/utils/i18n.ts +0 -221
  329. package/utils/localizedUrl.ts +0 -51
  330. package/utils/navigation.ts +0 -574
  331. package/utils/path.ts +0 -58
  332. package/utils/plugins.ts +0 -498
  333. package/utils/routing/data.ts +0 -154
  334. package/utils/routing/index.ts +0 -139
  335. package/utils/routing/middleware.ts +0 -81
  336. package/utils/routing/types.ts +0 -101
  337. package/utils/slugs.ts +0 -119
  338. package/utils/starlight-page.ts +0 -205
  339. package/utils/translations-fs.ts +0 -54
  340. package/utils/translations.ts +0 -57
  341. package/utils/types.ts +0 -15
  342. package/utils/user-config.ts +0 -348
  343. package/utils/validateLogoImports.ts +0 -21
  344. package/utils/zodDeepMerge.ts +0 -144
  345. package/virtual-internal.d.ts +0 -149
  346. package/virtual.d.ts +0 -27
  347. /package/{components → dist/components}/AnchorHeading.astro +0 -0
  348. /package/{components → dist/components}/Banner.astro +0 -0
  349. /package/{components → dist/components}/ContentNotice.astro +0 -0
  350. /package/{components → dist/components}/ContentPanel.astro +0 -0
  351. /package/{components → dist/components}/DraftContentNotice.astro +0 -0
  352. /package/{components → dist/components}/EditLink.astro +0 -0
  353. /package/{components → dist/components}/FallbackContentNotice.astro +0 -0
  354. /package/{components → dist/components}/Footer.astro +0 -0
  355. /package/{components → dist/components}/Head.astro +0 -0
  356. /package/{components → dist/components}/Header.astro +0 -0
  357. /package/{components → dist/components}/Hero.astro +0 -0
  358. /package/{components → dist/components}/LanguageSelect.astro +0 -0
  359. /package/{components → dist/components}/LastUpdated.astro +0 -0
  360. /package/{components → dist/components}/MarkdownContent.astro +0 -0
  361. /package/{components → dist/components}/MobileMenuFooter.astro +0 -0
  362. /package/{components → dist/components}/MobileTableOfContents.astro +0 -0
  363. /package/{components → dist/components}/Page.astro +0 -0
  364. /package/{components → dist/components}/PageSidebar.astro +0 -0
  365. /package/{components → dist/components}/PageTitle.astro +0 -0
  366. /package/{components → dist/components}/Pagination.astro +0 -0
  367. /package/{components → dist/components}/Search.astro +0 -0
  368. /package/{components → dist/components}/Select.astro +0 -0
  369. /package/{components → dist/components}/Sidebar.astro +0 -0
  370. /package/{components → dist/components}/SidebarPersister.astro +0 -0
  371. /package/{components → dist/components}/SidebarRestorePoint.astro +0 -0
  372. /package/{components → dist/components}/SidebarSublist.astro +0 -0
  373. /package/{components → dist/components}/SiteTitle.astro +0 -0
  374. /package/{components → dist/components}/SkipLink.astro +0 -0
  375. /package/{components → dist/components}/SocialIcons.astro +0 -0
  376. /package/{components → dist/components}/StarlightPage.astro +0 -0
  377. /package/{components → dist/components}/TableOfContents.astro +0 -0
  378. /package/{components → dist/components}/ThemeProvider.astro +0 -0
  379. /package/{components → dist/components}/ThemeSelect.astro +0 -0
  380. /package/{components → dist/components}/TwoColumnContent.astro +0 -0
  381. /package/{components-internals → dist/components-internals}/TableOfContents/TableOfContentsList.astro +0 -0
  382. /package/{components.ts → dist/components.ts} +0 -0
  383. /package/{routes → dist/routes}/common.astro +0 -0
  384. /package/{routes → dist/routes}/ssr/404.astro +0 -0
  385. /package/{routes → dist/routes}/ssr/index.astro +0 -0
  386. /package/{routes → dist/routes}/static/404.astro +0 -0
  387. /package/{routes → dist/routes}/static/index.astro +0 -0
  388. /package/{style → dist/style}/anchor-links.css +0 -0
  389. /package/{style → dist/style}/asides.css +0 -0
  390. /package/{style → dist/style}/layers.css +0 -0
  391. /package/{style → dist/style}/markdown.css +0 -0
  392. /package/{style → dist/style}/print.css +0 -0
  393. /package/{style → dist/style}/props.css +0 -0
  394. /package/{style → dist/style}/reset.css +0 -0
  395. /package/{style → dist/style}/util.css +0 -0
  396. /package/{user-components → dist/user-components}/Aside.astro +0 -0
  397. /package/{user-components → dist/user-components}/Badge.astro +0 -0
  398. /package/{user-components → dist/user-components}/Card.astro +0 -0
  399. /package/{user-components → dist/user-components}/CardGrid.astro +0 -0
  400. /package/{user-components → dist/user-components}/Icon.astro +0 -0
  401. /package/{user-components → dist/user-components}/LinkButton.astro +0 -0
  402. /package/{user-components → dist/user-components}/LinkCard.astro +0 -0
@@ -1,139 +0,0 @@
1
- import type { GetStaticPathsItem } from 'astro';
2
- import { getCollection } from 'astro:content';
3
- import config from 'virtual:starlight/user-config';
4
- import { localizedSlug, slugToLocaleData, slugToParam } from '../slugs';
5
- import { validateLogoImports } from '../validateLogoImports';
6
- import { BuiltInDefaultLocale } from '../i18n';
7
- import type { Route, StarlightDocsCollectionEntry, StarlightDocsEntry } from './types';
8
-
9
- // Validate any user-provided logos imported correctly.
10
- // We do this here so all pages trigger it and at the top level so it runs just once.
11
- validateLogoImports();
12
-
13
- interface Path extends GetStaticPathsItem {
14
- params: { slug: string | undefined };
15
- }
16
-
17
- /**
18
- * Astro is inconsistent in its `index.md` slug generation. In most cases,
19
- * `index` is stripped, but in the root of a collection, we get a slug of `index`.
20
- * We map that to an empty string for consistent behaviour.
21
- */
22
- const normalizeIndexSlug = (slug: string) => (slug === 'index' ? '' : slug);
23
-
24
- /** Normalize a collection entry. */
25
- export function normalizeCollectionEntry(entry: StarlightDocsCollectionEntry): StarlightDocsEntry {
26
- return {
27
- ...entry,
28
- // The `id` is a slug and should be normalized.
29
- id: normalizeIndexSlug(entry.id),
30
- // At the moment, Starlight only supports file-based loaders which always include a `filePath`.
31
- filePath: entry.filePath!,
32
- };
33
- }
34
-
35
- /** All entries in the docs content collection. */
36
- const docs: StarlightDocsEntry[] = (
37
- (await getCollection('docs', ({ data }) => {
38
- // In production, filter out drafts.
39
- return import.meta.env.MODE !== 'production' || data.draft === false;
40
- })) ?? []
41
- ).map(normalizeCollectionEntry);
42
-
43
- function getRoutes(): Route[] {
44
- const routes: Route[] = docs.map((entry) => ({
45
- entry,
46
- id: entry.id,
47
- entryMeta: slugToLocaleData(entry.id),
48
- ...slugToLocaleData(entry.id),
49
- }));
50
-
51
- // In multilingual sites, add required fallback routes.
52
- if (config.isMultilingual) {
53
- /** Entries in the docs content collection for the default locale. */
54
- const defaultLocaleDocs = getLocaleDocs(
55
- config.defaultLocale?.locale === 'root' ? undefined : config.defaultLocale?.locale
56
- );
57
- for (const key in config.locales) {
58
- if (key === config.defaultLocale.locale) continue;
59
- const localeConfig = config.locales[key];
60
- if (!localeConfig) continue;
61
- const locale = key === 'root' ? undefined : key;
62
- const localeDocs = getLocaleDocs(locale);
63
- const localeDocIds = new Set(localeDocs.map(({ id }) => id));
64
- for (const fallback of defaultLocaleDocs) {
65
- const id = localizedSlug(fallback.id, locale);
66
- if (localeDocIds.has(id)) continue;
67
- routes.push({
68
- entry: fallback,
69
- id,
70
- isFallback: true,
71
- lang: localeConfig.lang || BuiltInDefaultLocale.lang,
72
- locale,
73
- dir: localeConfig.dir,
74
- entryMeta: slugToLocaleData(fallback.id),
75
- });
76
- }
77
- }
78
- }
79
-
80
- return routes;
81
- }
82
- export const routes = getRoutes();
83
-
84
- const routesById = new Map(routes.map((route) => [route.id, route]));
85
-
86
- export function getRouteById(id: string): Route | undefined {
87
- return routesById.get(id);
88
- }
89
-
90
- function getParamRouteMapping(): ReadonlyMap<string | undefined, Route> {
91
- const map = new Map<string | undefined, Route>();
92
- for (const route of routes) {
93
- map.set(slugToParam(route.id), route);
94
- }
95
- return map;
96
- }
97
- const routesBySlugParam = getParamRouteMapping();
98
-
99
- export function getRouteBySlugParam(slugParam: string | undefined): Route | undefined {
100
- return routesBySlugParam.get(slugParam?.replace(/\/$/, '') || undefined);
101
- }
102
-
103
- function getPaths(): Path[] {
104
- return routes.map((route) => ({
105
- params: { slug: slugToParam(route.id) },
106
- }));
107
- }
108
- export const paths = getPaths();
109
-
110
- /**
111
- * Get all routes for a specific locale.
112
- * A locale of `undefined` is treated as the “root” locale, if configured.
113
- */
114
- export function getLocaleRoutes(locale: string | undefined): Route[] {
115
- return filterByLocale(routes, locale);
116
- }
117
-
118
- /**
119
- * Get all entries in the docs content collection for a specific locale.
120
- * A locale of `undefined` is treated as the “root” locale, if configured.
121
- */
122
- function getLocaleDocs(locale: string | undefined): StarlightDocsEntry[] {
123
- return filterByLocale(docs, locale);
124
- }
125
-
126
- /** Filter an array to find items whose slug matches the passed locale. */
127
- function filterByLocale<T extends { id: string }>(items: T[], locale: string | undefined): T[] {
128
- if (config.locales) {
129
- if (locale && locale in config.locales) {
130
- return items.filter((i) => i.id === locale || i.id.startsWith(locale + '/'));
131
- } else if (config.locales.root) {
132
- const langKeys = Object.keys(config.locales).filter((k) => k !== 'root');
133
- const isLangIndex = new RegExp(`^(${langKeys.join('|')})$`);
134
- const isLangDir = new RegExp(`^(${langKeys.join('|')})/`);
135
- return items.filter((i) => !isLangIndex.test(i.id) && !isLangDir.test(i.id));
136
- }
137
- }
138
- return items;
139
- }
@@ -1,81 +0,0 @@
1
- import type { APIContext } from 'astro';
2
- import { klona } from 'klona/lite';
3
- import { routeMiddleware } from 'virtual:starlight/route-middleware';
4
- import type { StarlightRouteData } from './types';
5
-
6
- /**
7
- * Adds a deep clone of the passed `routeData` object to locals and then runs middleware.
8
- * @param context Astro context object
9
- * @param routeData Initial route data object to attach.
10
- */
11
- export async function attachRouteDataAndRunMiddleware(
12
- context: APIContext,
13
- routeData: StarlightRouteData
14
- ) {
15
- context.locals.starlightRoute = klona(routeData);
16
- const runner = new MiddlewareRunner(context, routeMiddleware);
17
- await runner.run();
18
- }
19
-
20
- type MiddlewareHandler<T> = (context: T, next: () => Promise<void>) => void | Promise<void>;
21
-
22
- /**
23
- * A middleware function wrapper that only allows a single execution of the wrapped function.
24
- * Subsequent calls to `run()` are no-ops.
25
- */
26
- class MiddlewareRunnerStep<T> {
27
- #callback: MiddlewareHandler<T> | null;
28
- constructor(callback: MiddlewareHandler<T>) {
29
- this.#callback = callback;
30
- }
31
- async run(context: T, next: () => Promise<void>): Promise<void> {
32
- if (this.#callback) {
33
- await this.#callback(context, next);
34
- this.#callback = null;
35
- }
36
- }
37
- }
38
-
39
- /**
40
- * Class that runs a stack of middleware handlers with an initial context object.
41
- * Middleware functions can mutate properties of the `context` object, but cannot replace it.
42
- *
43
- * @example
44
- * const context = { value: 10 };
45
- * const timesTwo = async (ctx, next) => {
46
- * await next();
47
- * ctx.value *= 2;
48
- * };
49
- * const addFive = async (ctx) => {
50
- * ctx.value += 5;
51
- * }
52
- * const runner = new MiddlewareRunner(context, [timesTwo, addFive]);
53
- * runner.run();
54
- * console.log(context); // { value: 30 }
55
- */
56
- class MiddlewareRunner<T> {
57
- #context: T;
58
- #steps: Array<MiddlewareRunnerStep<T>>;
59
-
60
- constructor(
61
- /** Context object passed as the first argument to each middleware function. */
62
- context: T,
63
- /** Array of middleware functions to run in sequence. */
64
- stack: Array<MiddlewareHandler<T>> = []
65
- ) {
66
- this.#context = context;
67
- this.#steps = stack.map((callback) => new MiddlewareRunnerStep(callback));
68
- }
69
-
70
- async #stepThrough(steps: Array<MiddlewareRunnerStep<T>>) {
71
- let currentStep: MiddlewareRunnerStep<T>;
72
- while (steps.length > 0) {
73
- [currentStep, ...steps] = steps as [MiddlewareRunnerStep<T>, ...MiddlewareRunnerStep<T>[]];
74
- await currentStep.run(this.#context, async () => this.#stepThrough(steps));
75
- }
76
- }
77
-
78
- async run() {
79
- await this.#stepThrough(this.#steps);
80
- }
81
- }
@@ -1,101 +0,0 @@
1
- import type { MarkdownHeading } from 'astro';
2
- import type { CollectionEntry, RenderResult } from 'astro:content';
3
- import type { TocItem } from '../generateToC';
4
- import type { LinkHTMLAttributes } from '../../schemas/sidebar';
5
- import type { Badge } from '../../schemas/badge';
6
- import type { HeadConfig } from '../../schemas/head';
7
-
8
- export interface LocaleData {
9
- /** Writing direction. */
10
- dir: 'ltr' | 'rtl';
11
- /** BCP-47 language tag. */
12
- lang: string;
13
- /** The base path at which a language is served. `undefined` for root locale slugs. */
14
- locale: string | undefined;
15
- }
16
-
17
- export interface SidebarAutogenerateRouteData {
18
- directory: string;
19
- }
20
-
21
- export interface SidebarManualLink {
22
- type: 'link';
23
- label: string;
24
- href: string;
25
- isCurrent: boolean;
26
- badge: Badge | undefined;
27
- attrs: LinkHTMLAttributes;
28
- }
29
-
30
- export interface SidebarAutoLink extends SidebarManualLink {
31
- autogenerate: SidebarAutogenerateRouteData;
32
- }
33
-
34
- export interface SidebarManualGroup {
35
- type: 'group';
36
- label: string;
37
- entries: (SidebarLink | SidebarGroup)[];
38
- collapsed: boolean;
39
- badge: Badge | undefined;
40
- }
41
-
42
- export interface SidebarAutoGroup extends SidebarManualGroup {
43
- autogenerate: SidebarAutogenerateRouteData;
44
- }
45
-
46
- export type SidebarLink = SidebarManualLink | SidebarAutoLink;
47
- export type SidebarGroup = SidebarManualGroup | SidebarAutoGroup;
48
- export type SidebarEntry = SidebarLink | SidebarGroup;
49
-
50
- export interface PaginationLinks {
51
- /** Link to previous page in the sidebar. */
52
- prev: SidebarLink | undefined;
53
- /** Link to next page in the sidebar. */
54
- next: SidebarLink | undefined;
55
- }
56
-
57
- // A type representing a docs collection entry returned by the `docsLoader()`.
58
- export type StarlightDocsCollectionEntry = CollectionEntry<'docs'>;
59
-
60
- // A normalized type representing a docs collection entry used throughout Starlight.
61
- export type StarlightDocsEntry = StarlightDocsCollectionEntry & {
62
- // At the moment, Starlight only supports file-based loaders which always include a `filePath`.
63
- filePath: string;
64
- };
65
-
66
- export interface Route extends LocaleData {
67
- /** Content collection entry for the current page. Includes frontmatter at `data`. */
68
- entry: StarlightDocsEntry;
69
- /** Locale metadata for the page content. Can be different from top-level locale values when a page is using fallback content. */
70
- entryMeta: LocaleData;
71
- /** The slug. */
72
- id: string;
73
- /** Whether this page is untranslated in the current language and using fallback content from the default locale. */
74
- isFallback?: boolean;
75
- [key: string]: unknown;
76
- }
77
-
78
- export interface StarlightRouteData extends Route {
79
- /** Title of the site. */
80
- siteTitle: string;
81
- /** URL or path used as the link when clicking on the site title. */
82
- siteTitleHref: string;
83
- /** Array of Markdown headings extracted from the current page. */
84
- headings: MarkdownHeading[];
85
- /** Site navigation sidebar entries for this page. */
86
- sidebar: SidebarEntry[];
87
- /** Whether or not the sidebar should be displayed on this page. */
88
- hasSidebar: boolean;
89
- /** Links to the previous and next page in the sidebar if enabled. */
90
- pagination: PaginationLinks;
91
- /** Table of contents for this page if enabled. */
92
- toc: { minHeadingLevel: number; maxHeadingLevel: number; items: TocItem[] } | undefined;
93
- /** JS Date object representing when this page was last updated if enabled. */
94
- lastUpdated: Date | undefined;
95
- /** URL object for the address where this page can be edited if enabled. */
96
- editUrl: URL | undefined;
97
- /** An Astro component to render the current page’s content if this route is a Markdown page. */
98
- Content?: RenderResult['Content'];
99
- /** Array of tags to include in the `<head>` of the current page. */
100
- head: HeadConfig;
101
- }
package/utils/slugs.ts DELETED
@@ -1,119 +0,0 @@
1
- import config from 'virtual:starlight/user-config';
2
- import { slugToLocale as getLocaleFromSlug } from '../integrations/shared/slugToLocale';
3
- import { BuiltInDefaultLocale } from './i18n';
4
- import { stripTrailingSlash } from './path';
5
- import type { LocaleData } from './routing/types';
6
-
7
- /**
8
- * Get the “locale” of a slug. This is the base path at which a language is served.
9
- * For example, if French docs are in `src/content/docs/french/`, the locale is `french`.
10
- * Root locale slugs will return `undefined`.
11
- * @param slug A collection entry slug
12
- */
13
- function slugToLocale(slug: string): string | undefined {
14
- return getLocaleFromSlug(slug, config);
15
- }
16
-
17
- /** Get locale information for a given slug. */
18
- export function slugToLocaleData(slug: string): LocaleData {
19
- const locale = slugToLocale(slug);
20
- return { dir: localeToDir(locale), lang: localeToLang(locale), locale };
21
- }
22
-
23
- /**
24
- * Get the BCP-47 language tag for the given locale.
25
- * @param locale Locale string or `undefined` for the root locale.
26
- */
27
- export function localeToLang(locale: string | undefined): string {
28
- const lang = locale ? config.locales?.[locale]?.lang : config.locales?.root?.lang;
29
- const defaultLang = config.defaultLocale?.lang || config.defaultLocale?.locale;
30
- return lang || defaultLang || BuiltInDefaultLocale.lang;
31
- }
32
-
33
- /**
34
- * Get the configured writing direction for the given locale.
35
- * @param locale Locale string or `undefined` for the root locale.
36
- */
37
- function localeToDir(locale: string | undefined): 'ltr' | 'rtl' {
38
- const dir = locale ? config.locales?.[locale]?.dir : config.locales?.root?.dir;
39
- return dir || config.defaultLocale.dir;
40
- }
41
-
42
- /**
43
- * Convert a content collection slug to a param as expected by Astro’s router.
44
- * This utility handles stripping `index` from file names and matches
45
- * [Astro’s param sanitization logic](https://github.com/withastro/astro/blob/687d25365a41ff8a9e6da155d3527f841abb70dd/packages/astro/src/core/routing/manifest/generator.ts#L4-L18)
46
- * by normalizing strings to their canonical representations.
47
- * @param slug Content collection slug
48
- * @returns Param compatible with Astro’s router
49
- */
50
- export function slugToParam(slug: string): string | undefined {
51
- return slug === 'index' || slug === '' || slug === '/'
52
- ? undefined
53
- : (slug.endsWith('/index') ? slug.slice(0, -6) : slug).normalize();
54
- }
55
-
56
- export function slugToPathname(slug: string): string {
57
- const param = slugToParam(slug);
58
- return param ? '/' + param + '/' : '/';
59
- }
60
-
61
- /**
62
- * Convert a slug to a different locale.
63
- * For example, passing a slug of `en/home` and a locale of `fr` results in `fr/home`.
64
- * An undefined locale is treated as the root locale, resulting in `home`
65
- * @param slug A collection entry slug
66
- * @param locale The target locale
67
- * @example
68
- * localizedSlug('en/home', 'fr') // => 'fr/home'
69
- * localizedSlug('en/home', undefined) // => 'home'
70
- */
71
- export function localizedSlug(slug: string, locale: string | undefined): string {
72
- const slugLocale = slugToLocale(slug);
73
- if (slugLocale === locale) return slug;
74
- locale = locale || '';
75
- if (slugLocale === slug) return locale;
76
- if (slugLocale) {
77
- return stripTrailingSlash(slug.replace(slugLocale + '/', locale ? locale + '/' : ''));
78
- }
79
- return slug ? locale + '/' + slug : locale;
80
- }
81
-
82
- /**
83
- * Convert a file path relative to the collection root to a different locale.
84
- * For example, passing a file path of `en/home.md` and a locale of `fr` results in `fr/home.md`.
85
- * An undefined locale is treated as the root locale, resulting in `home.md`.
86
- * @param filePath A collection entry file path relative to the collection root
87
- * @param locale The target locale
88
- * @example
89
- * localizedFilePath('en/home.md', 'fr') // => 'fr/home.md'
90
- * localizedFilePath('en/home.md', undefined) // => 'home.md'
91
- */
92
- export function localizedFilePath(filePath: string, locale: string | undefined): string {
93
- const filePathLocale = slugToLocale(filePath);
94
- if (filePathLocale) {
95
- return filePath.replace(filePathLocale + '/', locale ? locale + '/' : '');
96
- } else if (locale) {
97
- return locale + '/' + filePath;
98
- } else {
99
- return filePath;
100
- }
101
- }
102
-
103
- /** Extract the slug from a URL. */
104
- export function urlToSlug(url: URL): string {
105
- let pathname = url.pathname;
106
- const base = stripTrailingSlash(import.meta.env.BASE_URL);
107
- if (pathname.startsWith(base)) pathname = pathname.replace(base, '');
108
- const segments = pathname.split('/');
109
- const htmlExt = '.html';
110
- if (segments.at(-1) === 'index.html') {
111
- // Remove trailing `index.html`.
112
- segments.pop();
113
- } else if (segments.at(-1)?.endsWith(htmlExt)) {
114
- // Remove trailing `.html`.
115
- const last = segments.pop();
116
- if (last) segments.push(last.slice(0, -1 * htmlExt.length));
117
- }
118
- return segments.filter(Boolean).join('/');
119
- }
@@ -1,205 +0,0 @@
1
- import { z } from 'astro/zod';
2
- import { type ContentConfig, type ImageFunction, type SchemaContext } from 'astro:content';
3
- import project from 'virtual:starlight/project-context';
4
- import config from 'virtual:starlight/user-config';
5
- import { getCollectionPathFromRoot } from './collection';
6
- import { parseWithFriendlyErrors, parseAsyncWithFriendlyErrors } from './error-map';
7
- import { stripLeadingAndTrailingSlashes } from './path';
8
- import {
9
- getSiteTitle,
10
- getSiteTitleHref,
11
- getToC,
12
- type PageProps,
13
- type RouteDataContext,
14
- } from './routing/data';
15
- import type { StarlightDocsEntry, StarlightRouteData } from './routing/types';
16
- import { slugToLocaleData, urlToSlug } from './slugs';
17
- import { getPrevNextLinks, getSidebar, getSidebarFromConfig } from './navigation';
18
- import { docsSchema } from '../schema';
19
- import type { Prettify, RemoveIndexSignature } from './types';
20
- import { SidebarItemSchema } from '../schemas/sidebar';
21
- import type { StarlightConfig, StarlightUserConfig } from './user-config';
22
- import { getHead } from './head';
23
-
24
- /**
25
- * The frontmatter schema for Starlight pages derived from the default schema for Starlight’s
26
- * `docs` content collection.
27
- * The frontmatter schema for Starlight pages cannot include some properties which will be omitted
28
- * and some others needs to be refined to a stricter type.
29
- */
30
- const StarlightPageFrontmatterSchema = async (context: SchemaContext) => {
31
- const userDocsSchema = await getUserDocsSchema();
32
- const schema = typeof userDocsSchema === 'function' ? userDocsSchema(context) : userDocsSchema;
33
-
34
- return schema.transform((frontmatter) => {
35
- /**
36
- * Starlight pages can only be edited if an edit URL is explicitly provided.
37
- * The `sidebar` frontmatter prop only works for pages in an autogenerated links group.
38
- * Starlight pages edit links cannot be autogenerated.
39
- *
40
- * These changes to the schema are done using a transformer and not using the usual `omit`
41
- * method because when the frontmatter schema is extended by the user, an intersection between
42
- * the default schema and the user schema is created using the `and` method. Intersections in
43
- * Zod returns a `ZodIntersection` object which does not have some methods like `omit` or
44
- * `pick`.
45
- *
46
- * This transformer only sets the `editUrl` default value and removes the `sidebar` property
47
- * from the validated output but does not apply any changes to the input schema type itself so
48
- * this needs to be done manually.
49
- *
50
- * @see StarlightPageFrontmatter
51
- * @see https://github.com/colinhacks/zod#intersections
52
- */
53
- const { editUrl, sidebar, ...others } = frontmatter;
54
- const pageEditUrl = editUrl === undefined || editUrl === true ? false : editUrl;
55
- return { ...others, editUrl: pageEditUrl };
56
- });
57
- };
58
-
59
- /**
60
- * Type of Starlight pages frontmatter schema.
61
- * We manually refines the `editUrl` type and omit the `sidebar` property as it's not possible to
62
- * do that on the schema itself using Zod but the proper validation is still using a transformer.
63
- * @see StarlightPageFrontmatterSchema
64
- */
65
- type StarlightPageFrontmatter = Omit<
66
- z.input<Awaited<ReturnType<typeof StarlightPageFrontmatterSchema>>>,
67
- 'editUrl' | 'sidebar'
68
- > & { editUrl?: string | false };
69
-
70
- /** Parse sidebar prop to ensure it's valid. */
71
- const validateSidebarProp = (
72
- sidebarProp: StarlightUserConfig['sidebar']
73
- ): StarlightConfig['sidebar'] => {
74
- return parseWithFriendlyErrors(
75
- SidebarItemSchema.array().optional(),
76
- sidebarProp,
77
- 'Invalid sidebar prop passed to the `<StarlightPage/>` component.'
78
- );
79
- };
80
-
81
- /**
82
- * The props accepted by the `<StarlightPage/>` component.
83
- */
84
- export type StarlightPageProps = Prettify<
85
- // Remove the index signature from `Route`, omit undesired properties and make the rest optional.
86
- Partial<Omit<RemoveIndexSignature<PageProps>, 'entry' | 'entryMeta' | 'id' | 'locale'>> &
87
- // Add the sidebar definitions for a Starlight page.
88
- Partial<Pick<StarlightRouteData, 'hasSidebar'>> & {
89
- sidebar?: StarlightUserConfig['sidebar'];
90
- // And finally add the Starlight page frontmatter properties in a `frontmatter` property.
91
- frontmatter: StarlightPageFrontmatter;
92
- }
93
- >;
94
-
95
- /**
96
- * A docs entry used for Starlight pages meant to be rendered by plugins and which is safe to cast
97
- * to a `StarlightDocsEntry`.
98
- * A Starlight page docs entry cannot be rendered like a content collection entry.
99
- */
100
- type StarlightPageDocsEntry = Omit<StarlightDocsEntry, 'render'>;
101
-
102
- export async function generateStarlightPageRouteData({
103
- props,
104
- context,
105
- }: {
106
- props: StarlightPageProps;
107
- context: RouteDataContext;
108
- }): Promise<StarlightRouteData> {
109
- const { frontmatter, ...routeProps } = props;
110
- const { url } = context;
111
- const id = urlToSlug(url);
112
- const pageFrontmatter = await getStarlightPageFrontmatter(frontmatter);
113
- const localeData = slugToLocaleData(id);
114
- const sidebar = props.sidebar
115
- ? getSidebarFromConfig(validateSidebarProp(props.sidebar), url.pathname, localeData.locale)
116
- : getSidebar(url.pathname, localeData.locale);
117
- const headings = props.headings ?? [];
118
- const pageDocsEntry: StarlightPageDocsEntry = {
119
- id,
120
- body: '',
121
- collection: 'docs',
122
- filePath: `${getCollectionPathFromRoot('docs', project)}/${stripLeadingAndTrailingSlashes(id)}.md`,
123
- data: {
124
- ...pageFrontmatter,
125
- sidebar: {
126
- attrs: {},
127
- hidden: false,
128
- },
129
- },
130
- };
131
- const entry = pageDocsEntry as StarlightDocsEntry;
132
- const entryMeta: StarlightRouteData['entryMeta'] = {
133
- dir: props.dir ?? localeData.dir,
134
- lang: props.lang ?? localeData.lang,
135
- locale: localeData.locale,
136
- };
137
- const editUrl = pageFrontmatter.editUrl ? new URL(pageFrontmatter.editUrl) : undefined;
138
- const lastUpdated =
139
- pageFrontmatter.lastUpdated instanceof Date ? pageFrontmatter.lastUpdated : undefined;
140
- const pageProps: PageProps = {
141
- ...routeProps,
142
- ...localeData,
143
- entry,
144
- entryMeta,
145
- headings,
146
- id,
147
- locale: localeData.locale,
148
- };
149
- const siteTitle = getSiteTitle(localeData.lang);
150
- const routeData: StarlightRouteData = {
151
- ...routeProps,
152
- ...localeData,
153
- id,
154
- editUrl,
155
- entry,
156
- entryMeta,
157
- hasSidebar: props.hasSidebar ?? entry.data.template !== 'splash',
158
- head: getHead(pageProps, context, siteTitle),
159
- headings,
160
- lastUpdated,
161
- pagination: getPrevNextLinks(sidebar, config.pagination, entry.data),
162
- sidebar,
163
- siteTitle,
164
- siteTitleHref: getSiteTitleHref(localeData.locale),
165
- toc: getToC(pageProps),
166
- };
167
- return routeData;
168
- }
169
-
170
- /** Validates the Starlight page frontmatter properties from the props received by a Starlight page. */
171
- async function getStarlightPageFrontmatter(frontmatter: StarlightPageFrontmatter) {
172
- const schema = await StarlightPageFrontmatterSchema({
173
- image: (() =>
174
- // Mock validator for ImageMetadata.
175
- // https://github.com/withastro/astro/blob/cf993bc263b58502096f00d383266cd179f331af/packages/astro/src/assets/types.ts#L32
176
- // It uses a custom validation approach because imported SVGs have a type of `function` as
177
- // well as containing the metadata properties and this ensures we handle those correctly.
178
- z.custom<ReturnType<ImageFunction>>(
179
- (value) =>
180
- value &&
181
- (typeof value === 'function' || typeof value === 'object') &&
182
- 'src' in value &&
183
- 'width' in value &&
184
- 'height' in value &&
185
- 'format' in value,
186
- 'Invalid image passed to `<StarlightPage>` component. Expected imported `ImageMetadata` object.'
187
- )) as unknown as ImageFunction,
188
- });
189
-
190
- // Starting with Astro 4.14.0, a frontmatter schema that contains collection references will
191
- // contain an async transform.
192
- return parseAsyncWithFriendlyErrors(
193
- schema,
194
- frontmatter,
195
- 'Invalid frontmatter props passed to the `<StarlightPage/>` component.'
196
- );
197
- }
198
-
199
- /** Returns the user docs schema and falls back to the default schema if needed. */
200
- async function getUserDocsSchema(): Promise<
201
- NonNullable<ContentConfig['collections']['docs']['schema']>
202
- > {
203
- const userCollections = (await import('virtual:starlight/collection-config')).collections;
204
- return userCollections?.docs?.schema ?? docsSchema();
205
- }