@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,137 +0,0 @@
1
- import i18next, { type ExistsFunction, type TFunction } from 'i18next';
2
- import type { i18nSchemaOutput } from '../schemas/i18n';
3
- import builtinTranslations from '../translations/index';
4
- import { BuiltInDefaultLocale } from './i18n';
5
- import type { StarlightConfig } from './user-config';
6
- import type { UserI18nKeys, UserI18nSchema } from './translations';
7
-
8
- /**
9
- * The namespace for i18next resources used by Starlight.
10
- * All translations handled by Starlight are stored in the same namespace and Starlight always use
11
- * a new instance of i18next configured for this namespace.
12
- */
13
- export const I18nextNamespace = 'starlight' as const;
14
-
15
- export async function createTranslationSystem<T extends i18nSchemaOutput>(
16
- config: Pick<StarlightConfig, 'defaultLocale' | 'locales'>,
17
- userTranslations: Record<string, T>,
18
- pluginTranslations: Record<string, T> = {}
19
- ) {
20
- const defaultLocale =
21
- config.defaultLocale.lang || config.defaultLocale?.locale || BuiltInDefaultLocale.lang;
22
-
23
- const translations = {
24
- [defaultLocale]: buildResources(
25
- builtinTranslations[defaultLocale] || builtinTranslations[stripLangRegion(defaultLocale)],
26
- pluginTranslations[defaultLocale],
27
- userTranslations[defaultLocale]
28
- ),
29
- };
30
-
31
- if (config.locales) {
32
- for (const locale in config.locales) {
33
- const lang = localeToLang(locale, config.locales, config.defaultLocale);
34
-
35
- translations[lang] = buildResources(
36
- builtinTranslations[lang] || builtinTranslations[stripLangRegion(lang)],
37
- pluginTranslations[lang],
38
- userTranslations[lang]
39
- );
40
- }
41
- }
42
-
43
- const i18n = i18next.createInstance();
44
- await i18n.init({
45
- resources: translations,
46
- fallbackLng:
47
- config.defaultLocale.lang || config.defaultLocale?.locale || BuiltInDefaultLocale.lang,
48
- });
49
-
50
- /**
51
- * Generate a utility function that returns UI strings for the given language.
52
- *
53
- * Also includes a few utility methods:
54
- * - `all()` method for getting the entire dictionary.
55
- * - `exists()` method for checking if a key exists in the dictionary.
56
- * - `dir()` method for getting the text direction of the locale.
57
- *
58
- * @param {string | undefined} [lang]
59
- * @example
60
- * const t = useTranslations('en');
61
- * const label = t('search.label');
62
- * // => 'Search'
63
- * const dictionary = t.all();
64
- * // => { 'skipLink.label': 'Skip to content', 'search.label': 'Search', ... }
65
- * const exists = t.exists('search.label');
66
- * // => true
67
- * const dir = t.dir();
68
- * // => 'ltr'
69
- */
70
- return (lang: string | undefined) => {
71
- lang ??= config.defaultLocale?.lang || BuiltInDefaultLocale.lang;
72
-
73
- const t = i18n.getFixedT(lang, I18nextNamespace) as I18nT;
74
- t.all = () => i18n.getResourceBundle(lang, I18nextNamespace) as ReturnType<I18nT['all']>;
75
- // Since i18next 25.10.4 the `ExistsFunction` type has a signature including a predicate that
76
- // TS cannot preserve when composing a new function to add default options.
77
- // See: https://github.com/i18next/i18next/issues/2425
78
- t.exists = ((key, options) =>
79
- i18n.exists(key, { lng: lang, ns: I18nextNamespace, ...options })) as ExistsFunction;
80
- t.dir = (dirLang = lang) => i18n.dir(dirLang);
81
-
82
- return t;
83
- };
84
- }
85
-
86
- /**
87
- * Strips the region subtag from a BCP-47 lang string.
88
- * @param {string} [lang]
89
- * @example
90
- * const lang = stripLangRegion('en-GB'); // => 'en'
91
- */
92
- function stripLangRegion(lang: string) {
93
- return lang.replace(/-[a-zA-Z]{2}/, '');
94
- }
95
-
96
- /**
97
- * Get the BCP-47 language tag for the given locale.
98
- * @param locale Locale string or `undefined` for the root locale.
99
- */
100
- function localeToLang(
101
- locale: string | undefined,
102
- locales: StarlightConfig['locales'],
103
- defaultLocale: StarlightConfig['defaultLocale']
104
- ): string {
105
- const lang = locale ? locales?.[locale]?.lang : locales?.root?.lang;
106
- const defaultLang = defaultLocale?.lang || defaultLocale?.locale;
107
- return lang || defaultLang || BuiltInDefaultLocale.lang;
108
- }
109
-
110
- type BuiltInStrings = (typeof builtinTranslations)['en'];
111
-
112
- /** Build an i18next resources dictionary by layering preferred translation sources. */
113
- function buildResources<T extends i18nSchemaOutput>(
114
- ...dictionaries: (T | BuiltInStrings | undefined)[]
115
- ): { [I18nextNamespace]: BuiltInStrings & T } {
116
- const dictionary: Partial<BuiltInStrings> = {};
117
- // Iterate over alternate dictionaries to avoid overwriting preceding values with `undefined`.
118
- for (const dict of dictionaries) {
119
- for (const key in dict) {
120
- const value = dict[key as keyof typeof dict];
121
- if (value) dictionary[key as keyof typeof dictionary] = value;
122
- }
123
- }
124
- return { [I18nextNamespace]: dictionary as BuiltInStrings & T };
125
- }
126
-
127
- // `keyof BuiltInStrings` and `UserI18nKeys` may contain some identical keys, e.g. the built-in UI
128
- // strings. We let TypeScript merge them into a single union type so that plugins with a TypeScript
129
- // configuration preventing `UserI18nKeys` to be properly inferred can still get auto-completion
130
- // for built-in UI strings.
131
- export type I18nKeys = keyof BuiltInStrings | UserI18nKeys | keyof StarlightApp.I18n;
132
-
133
- export type I18nT = TFunction<'starlight', undefined> & {
134
- all: () => UserI18nSchema;
135
- exists: ExistsFunction;
136
- dir: (lang?: string) => 'ltr' | 'rtl';
137
- };
@@ -1,222 +0,0 @@
1
- /**
2
- * This is a modified version of Astro's error map.
3
- * source: https://github.com/withastro/astro/blob/main/packages/astro/src/content/error-map.ts
4
- */
5
-
6
- import { AstroError } from 'astro/errors';
7
- import { z, locales } from 'astro/zod';
8
-
9
- // The default Zod error map that we use to retrieve default error messages.
10
- const zodErrorMap = locales.en().localeError;
11
-
12
- type TypeErrByPathEntry = {
13
- code: 'invalid_type';
14
- received: unknown;
15
- expected: unknown[];
16
- message: string | undefined;
17
- };
18
-
19
- /**
20
- * Parse data with a Zod schema and throw a nicely formatted error if it is invalid.
21
- *
22
- * @param schema The Zod schema to use to parse the input.
23
- * @param input Input data that should match the schema.
24
- * @param message Error message preamble to use if the input fails to parse.
25
- * @returns Validated data parsed by Zod.
26
- */
27
- export function parseWithFriendlyErrors<T extends z.ZodType>(
28
- schema: T,
29
- input: z.input<T>,
30
- message: string
31
- ): z.output<T> {
32
- return processParsedData<T>(
33
- schema.safeParse(input, { error: errorMap, reportInput: true }),
34
- message
35
- );
36
- }
37
-
38
- /**
39
- * Asynchronously parse data with a Zod schema that contains asynchronous refinements or transforms
40
- * and throw a nicely formatted error if it is invalid.
41
- *
42
- * @param schema The Zod schema to use to parse the input.
43
- * @param input Input data that should match the schema.
44
- * @param message Error message preamble to use if the input fails to parse.
45
- * @returns Validated data parsed by Zod.
46
- */
47
- export async function parseAsyncWithFriendlyErrors<T extends z.ZodType>(
48
- schema: T,
49
- input: z.input<T>,
50
- message: string
51
- ): Promise<z.output<T>> {
52
- return processParsedData<T>(
53
- await schema.safeParseAsync(input, { error: errorMap, reportInput: true }),
54
- message
55
- );
56
- }
57
-
58
- function processParsedData<T extends z.ZodType>(
59
- parsedData: z.ZodSafeParseResult<z.output<T>>,
60
- message: string
61
- ) {
62
- if (!parsedData.success) {
63
- throw new AstroError(message, parsedData.error.issues.map((i) => i.message).join('\n'));
64
- }
65
- return parsedData.data;
66
- }
67
-
68
- const errorMap: z.core.$ZodErrorMap = (issue) => {
69
- const baseErrorPath = flattenErrorPath(issue.path ?? []);
70
- if (issue.code === 'invalid_union') {
71
- // Optimization: Combine type and literal errors for keys that are common across ALL union types
72
- // Ex. a union between `{ key: z.literal('tutorial') }` and `{ key: z.literal('blog') }` will
73
- // raise a single error when `key` does not match:
74
- // > Did not match union.
75
- // > key: Expected `'tutorial' | 'blog'`, received 'foo'
76
- const unionErrors = issue.errors.flat();
77
- const typeOrLiteralErrByPath: Map<string, TypeErrByPathEntry> = new Map();
78
- for (const unionError of unionErrors) {
79
- if (unionError.code === 'invalid_type') {
80
- const flattenedErrorPath = flattenErrorPath([baseErrorPath, ...unionError.path]);
81
- if (typeOrLiteralErrByPath.has(flattenedErrorPath)) {
82
- typeOrLiteralErrByPath.get(flattenedErrorPath)!.expected.push(unionError.expected);
83
- } else {
84
- typeOrLiteralErrByPath.set(flattenedErrorPath, {
85
- code: unionError.code,
86
- received: parsedType(issue.input),
87
- expected: [unionError.expected],
88
- message: unionError.message,
89
- });
90
- }
91
- }
92
- }
93
- const messages: string[] = [prefix(baseErrorPath, 'Did not match union.')];
94
- const details: string[] = [...typeOrLiteralErrByPath.entries()]
95
- // If type or literal error isn't common to ALL union types,
96
- // filter it out. Can lead to confusing noise.
97
- .filter(([, error]) => error.expected.length === unionErrors.length)
98
- .map(([key, error]) =>
99
- key === baseErrorPath
100
- ? // Avoid printing the key again if it's a base error
101
- `> ${getTypeErrMsg(error)}`
102
- : `> ${prefix(key, getTypeErrMsg(error))}`
103
- );
104
-
105
- if (details.length === 0) {
106
- const expectedShapes: string[] = [];
107
- for (const unionError of issue.errors) {
108
- const expectedShape: string[] = [];
109
- for (const issue of unionError) {
110
- // We sometimes use `z.NEVER` to explicitly error on certain property combinations in
111
- // non-discriminated unions to make it easier for users to identify invalid config, e.g.
112
- // autogenerated groups in the sidebar no longer being supported. Having these properties
113
- // show up in the error message with an expected type of `never` is noisy and not helpful
114
- // so we skip them here.
115
- if (issue.code === 'invalid_type' && issue.expected === 'never') continue;
116
- // If the issue is a nested union error, show the associated error message instead of the
117
- // base error message.
118
- if (issue.code === 'invalid_union') {
119
- return errorMap({ ...issue, input: issue.input, path: [baseErrorPath, ...issue.path] });
120
- }
121
- const relativePath = flattenErrorPath(issue.path)
122
- .replace(baseErrorPath, '')
123
- .replace(leadingPeriod, '');
124
- if (issue.code === 'invalid_type') {
125
- expectedShape.push(
126
- relativePath ? `${relativePath}: ${issue.expected}` : issue.expected
127
- );
128
- } else if (issue.code === 'custom') {
129
- expectedShape.push(relativePath);
130
- }
131
- }
132
- if (expectedShape.length === 1 && !expectedShape[0]?.includes(':')) {
133
- // In this case the expected shape is not an object, but probably a literal type, e.g. `['string']`.
134
- expectedShapes.push(expectedShape.join(''));
135
- } else if (expectedShape.length > 0) {
136
- expectedShapes.push(`{ ${expectedShape.join('; ')} }`);
137
- }
138
- }
139
- if (expectedShapes.length) {
140
- details.push('> Expected type `' + expectedShapes.join(' | ') + '`');
141
- details.push('> Received `' + stringify(issue.input) + '`');
142
- }
143
- }
144
-
145
- return messages.concat(details).join('\n');
146
- } else if (issue.code === 'invalid_type') {
147
- return prefix(
148
- baseErrorPath,
149
- getTypeErrMsg({
150
- code: issue.code,
151
- received: parsedType(issue.input),
152
- expected: [issue.expected],
153
- message: issue.message,
154
- })
155
- );
156
- } else if (issue.message) {
157
- return prefix(baseErrorPath, issue.message);
158
- } else {
159
- // By design, the default Zod error may not be provided in Zod 4 error maps. Instead, error
160
- // maps are supposed to return `undefined` in order to yield control to the next error map in
161
- // the precedence chain. Unfortunately, this prevents us from prefixing all errors with their
162
- // paths so we have to manually invoke the default Zod error map here.
163
- const defaultError = zodErrorMap(issue);
164
- if (!defaultError) return;
165
-
166
- return prefix(
167
- baseErrorPath,
168
- typeof defaultError === 'string' ? defaultError : defaultError.message
169
- );
170
- }
171
- };
172
-
173
- const getTypeErrMsg = (error: TypeErrByPathEntry): string => {
174
- // received could be `undefined` or the string `'undefined'`
175
- if (typeof error.received === 'undefined' || error.received === 'undefined')
176
- return error.message ?? 'Required';
177
- const expectedDeduped = new Set(error.expected);
178
- return `Expected type \`${unionExpectedVals(expectedDeduped)}\`, received \`${stringify(
179
- error.received
180
- )}\``;
181
- };
182
-
183
- const prefix = (key: string, msg: string) => (key.length ? `**${key}**: ${msg}` : msg);
184
-
185
- const unionExpectedVals = (expectedVals: Set<unknown>) =>
186
- [...expectedVals].map((expectedVal) => stringify(expectedVal)).join(' | ');
187
-
188
- const flattenErrorPath = (errorPath: PropertyKey[]) => errorPath.join('.');
189
-
190
- /** `JSON.stringify()` a value with spaces around object/array entries. */
191
- const stringify = (val: unknown) =>
192
- JSON.stringify(val, null, 1).split(newlinePlusWhitespace).join(' ');
193
- const newlinePlusWhitespace = /\n\s*/;
194
- const leadingPeriod = /^\./;
195
-
196
- /**
197
- * In Zod 4, we don't necessarily get a human-readable representation of input data types. For such
198
- * cases, we use the same logic as Zod's own `parsedType()` function.
199
- * @see https://github.com/colinhacks/zod/blob/73b071d7d08825dedb6b48b78718739118ee1308/packages/zod/src/v4/locales/en.ts#L5
200
- */
201
- const parsedType = (data: unknown): string => {
202
- const t = typeof data;
203
-
204
- switch (t) {
205
- case 'number': {
206
- return Number.isNaN(data) ? 'NaN' : 'number';
207
- }
208
- case 'object': {
209
- if (Array.isArray(data)) {
210
- return 'array';
211
- }
212
- if (data === null) {
213
- return 'null';
214
- }
215
-
216
- if (data && Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
217
- return data.constructor.name;
218
- }
219
- }
220
- }
221
- return t;
222
- };
@@ -1,7 +0,0 @@
1
- import project from 'virtual:starlight/project-context';
2
- import { createPathFormatter } from './createPathFormatter';
3
-
4
- export const formatPath = createPathFormatter({
5
- format: project.build.format,
6
- trailingSlash: project.trailingSlash,
7
- });
@@ -1,33 +0,0 @@
1
- import type { MarkdownHeading } from 'astro';
2
- import { PAGE_TITLE_ID } from '../constants';
3
-
4
- export interface TocItem extends MarkdownHeading {
5
- children: TocItem[];
6
- }
7
-
8
- interface TocOpts {
9
- minHeadingLevel: number;
10
- maxHeadingLevel: number;
11
- title: string;
12
- }
13
-
14
- /** Convert the flat headings array generated by Astro into a nested tree structure. */
15
- export function generateToC(
16
- headings: MarkdownHeading[],
17
- { minHeadingLevel, maxHeadingLevel, title }: TocOpts
18
- ) {
19
- headings = headings.filter(({ depth }) => depth >= minHeadingLevel && depth <= maxHeadingLevel);
20
- const toc: Array<TocItem> = [{ depth: 2, slug: PAGE_TITLE_ID, text: title, children: [] }];
21
- for (const heading of headings) injectChild(toc, { ...heading, children: [] });
22
- return toc;
23
- }
24
-
25
- /** Inject a ToC entry as deep in the tree as its `depth` property requires. */
26
- function injectChild(items: TocItem[], item: TocItem): void {
27
- const lastItem = items.at(-1);
28
- if (!lastItem || lastItem.depth >= item.depth) {
29
- items.push(item);
30
- } else {
31
- return injectChild(lastItem.children, item);
32
- }
33
- }
package/utils/git.ts DELETED
@@ -1,121 +0,0 @@
1
- /**
2
- * Git module to be used from the dev server and from the integration.
3
- */
4
-
5
- import { basename, dirname, relative, resolve } from 'node:path';
6
- import { realpathSync } from 'node:fs';
7
- import { spawnSync } from 'node:child_process';
8
-
9
- export type GitAPI = {
10
- getNewestCommitDate: (file: string) => Date;
11
- };
12
-
13
- export const makeAPI = (directory: string): GitAPI => {
14
- return {
15
- getNewestCommitDate: (file) => getNewestCommitDate(resolve(directory, file)),
16
- };
17
- };
18
-
19
- export function getNewestCommitDate(file: string): Date {
20
- const result = spawnSync('git', ['log', '--format=%ct', '--max-count=1', basename(file)], {
21
- cwd: dirname(file),
22
- encoding: 'utf-8',
23
- });
24
-
25
- if (result.error) {
26
- throw new Error(`Failed to retrieve the git history for file "${file}"`);
27
- }
28
- const output = result.stdout.trim();
29
- const regex = /^(?<timestamp>\d+)$/;
30
- const match = output.match(regex);
31
-
32
- if (!match?.groups?.timestamp) {
33
- throw new Error(`Failed to validate the timestamp for file "${file}"`);
34
- }
35
-
36
- const timestamp = Number(match.groups.timestamp);
37
- const date = new Date(timestamp * 1000);
38
- return date;
39
- }
40
-
41
- function getRepoRoot(directory: string): string {
42
- const result = spawnSync('git', ['rev-parse', '--show-toplevel'], {
43
- cwd: directory,
44
- encoding: 'utf-8',
45
- });
46
-
47
- if (result.error) {
48
- return directory;
49
- }
50
-
51
- try {
52
- return realpathSync(result.stdout.trim());
53
- } catch {
54
- return directory;
55
- }
56
- }
57
-
58
- export function getAllNewestCommitDate(rootPath: string, docsPath: string): [string, number][] {
59
- const repoRoot = getRepoRoot(docsPath);
60
-
61
- const gitLog = spawnSync(
62
- 'git',
63
- [
64
- 'log',
65
- // Format each history entry as t:<seconds since epoch>
66
- '--format=t:%ct',
67
- // In each entry include the name and status for each modified file
68
- '--name-status',
69
- '--',
70
- docsPath,
71
- ],
72
- {
73
- cwd: repoRoot,
74
- encoding: 'utf-8',
75
- // The default `maxBuffer` for `spawnSync` is 1024 * 1024 bytes, a.k.a 1 MB. In big projects,
76
- // the full git history can be larger than this, so we increase this to ~10 MB. For example,
77
- // Cloudflare passed 1 MB with ~4,800 pages and ~17,000 commits. If we get reports of others
78
- // hitting ENOBUFS errors here in the future, we may want to switch to streaming the git log
79
- // with `spawn` instead.
80
- // See https://github.com/withastro/starlight/issues/3154
81
- maxBuffer: 10 * 1024 * 1024,
82
- }
83
- );
84
-
85
- if (gitLog.error) {
86
- return [];
87
- }
88
-
89
- let runningDate = Date.now();
90
- const latestDates = new Map<string, number>();
91
-
92
- for (const logLine of gitLog.stdout.split('\n')) {
93
- if (logLine.startsWith('t:')) {
94
- // t:<seconds since epoch>
95
- runningDate = Number.parseInt(logLine.slice(2)) * 1000;
96
- }
97
-
98
- // - Added files take the format `A\t<file>`
99
- // - Modified files take the format `M\t<file>`
100
- // - Deleted files take the format `D\t<file>`
101
- // - Renamed files take the format `R<count>\t<old>\t<new>`
102
- // - Copied files take the format `C<count>\t<old>\t<new>`
103
- // The name of the file as of the commit being processed is always
104
- // the last part of the log line.
105
- const tabSplit = logLine.lastIndexOf('\t');
106
- if (tabSplit === -1) continue;
107
- const fileName = logLine.slice(tabSplit + 1);
108
-
109
- const currentLatest = latestDates.get(fileName) || 0;
110
- latestDates.set(fileName, Math.max(currentLatest, runningDate));
111
- }
112
-
113
- return Array.from(latestDates.entries()).map(([file, date]) => {
114
- const fileFullPath = resolve(repoRoot, file);
115
- let fileInDirectory = relative(rootPath, fileFullPath);
116
- // Format path to unix style path.
117
- fileInDirectory = fileInDirectory?.replace(/\\/g, '/');
118
-
119
- return [fileInDirectory, date];
120
- });
121
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Git module to be used on production build results.
3
- * The API is based on inlined git information.
4
- */
5
-
6
- import type { GitAPI, getAllNewestCommitDate } from './git';
7
-
8
- type InlinedData = ReturnType<typeof getAllNewestCommitDate>;
9
-
10
- export const makeAPI = (data: InlinedData): GitAPI => {
11
- const trackedDocsFiles = new Map(data);
12
-
13
- return {
14
- getNewestCommitDate: (file) => {
15
- const timestamp = trackedDocsFiles.get(file);
16
- if (!timestamp) throw new Error(`Failed to retrieve the git history for file "${file}"`);
17
- return new Date(timestamp);
18
- },
19
- };
20
- };