@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.
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/components/MobileMenuToggle.astro +65 -0
- package/{components → dist/components}/PageFrame.astro +32 -8
- package/dist/components-internals/Icons.d.ts +415 -0
- package/dist/components-internals/Icons.js +140 -0
- package/dist/components-internals/SidebarPersistState.d.ts +1 -0
- package/dist/components-internals/SidebarPersistState.js +53 -0
- package/dist/components-internals/TableOfContents/starlight-toc.d.ts +18 -0
- package/dist/components-internals/TableOfContents/starlight-toc.js +88 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +4 -0
- package/{expressive-code.d.ts → dist/expressive-code.d.ts} +6 -13
- package/dist/expressive-code.js +31 -0
- package/dist/global.d.ts +62 -0
- package/dist/global.js +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +109 -0
- package/dist/integrations/aside-utils.d.ts +9 -0
- package/dist/integrations/aside-utils.js +35 -0
- package/dist/integrations/expressive-code/hast.d.ts +1 -0
- package/dist/integrations/expressive-code/hast.js +2 -0
- package/dist/integrations/expressive-code/index.d.ts +60 -0
- package/dist/integrations/expressive-code/index.js +48 -0
- package/dist/integrations/expressive-code/preprocessor.d.ts +17 -0
- package/dist/integrations/expressive-code/preprocessor.js +76 -0
- package/dist/integrations/expressive-code/themes/night-owl-dark.js +4 -0
- package/dist/integrations/expressive-code/themes/night-owl-light.js +4 -0
- package/dist/integrations/expressive-code/theming.d.ts +16 -0
- package/dist/integrations/expressive-code/theming.js +71 -0
- package/dist/integrations/expressive-code/translations.d.ts +8 -0
- package/dist/integrations/expressive-code/translations.js +26 -0
- package/dist/integrations/markdown-icon.d.ts +8 -0
- package/dist/integrations/markdown-icon.js +14 -0
- package/dist/integrations/markdown-plugins.d.ts +18 -0
- package/dist/integrations/markdown-plugins.js +36 -0
- package/dist/integrations/markdown-processor.d.ts +29 -0
- package/dist/integrations/markdown-processor.js +44 -0
- package/dist/integrations/pagefind.d.ts +7 -0
- package/dist/integrations/pagefind.js +34 -0
- package/dist/integrations/rehype-code-rtl-support.d.ts +21 -0
- package/dist/integrations/rehype-code-rtl-support.js +36 -0
- package/dist/integrations/rehype-heading-links.d.ts +10 -0
- package/dist/integrations/rehype-heading-links.js +57 -0
- package/dist/integrations/remark-asides.d.ts +32 -0
- package/dist/integrations/remark-asides.js +166 -0
- package/dist/integrations/remark-rehype.d.ts +17 -0
- package/dist/integrations/remark-rehype.js +51 -0
- package/dist/integrations/satteri.d.ts +13 -0
- package/dist/integrations/satteri.js +209 -0
- package/dist/integrations/shared/absolutePathToLang.d.ts +10 -0
- package/dist/integrations/shared/absolutePathToLang.js +13 -0
- package/dist/integrations/shared/localeToLang.d.ts +10 -0
- package/dist/integrations/shared/localeToLang.js +13 -0
- package/dist/integrations/shared/slugToLocale.d.ts +12 -0
- package/dist/integrations/shared/slugToLocale.js +15 -0
- package/dist/integrations/sitemap.d.ts +12 -0
- package/dist/integrations/sitemap.js +19 -0
- package/dist/integrations/vite-layer-order.d.ts +15 -0
- package/dist/integrations/vite-layer-order.js +56 -0
- package/dist/integrations/vite-lazy-barrel-optimization.d.ts +12 -0
- package/dist/integrations/vite-lazy-barrel-optimization.js +33 -0
- package/dist/integrations/vite-virtual-modules.d.ts +14 -0
- package/dist/integrations/vite-virtual-modules.js +108 -0
- package/dist/internal.d.ts +3 -0
- package/dist/internal.js +3 -0
- package/dist/loaders.d.ts +20 -0
- package/dist/loaders.js +49 -0
- package/dist/locals.d.ts +15 -0
- package/dist/locals.js +33 -0
- package/dist/package.js +4 -0
- package/{props.ts → dist/props.d.ts} +6 -4
- package/dist/props.js +1 -0
- package/dist/route-data.d.ts +7 -0
- package/dist/route-data.js +6 -0
- package/dist/schema.d.ts +426 -0
- package/dist/schema.js +103 -0
- package/dist/schemas/badge.d.ts +86 -0
- package/dist/schemas/badge.js +39 -0
- package/dist/schemas/components.d.ts +236 -0
- package/dist/schemas/components.js +36 -0
- package/dist/schemas/expressiveCode.d.ts +7 -0
- package/dist/schemas/expressiveCode.js +5 -0
- package/dist/schemas/favicon.d.ts +9 -0
- package/dist/schemas/favicon.js +32 -0
- package/dist/schemas/head.d.ts +33 -0
- package/dist/schemas/head.js +41 -0
- package/dist/schemas/hero.d.ts +319 -0
- package/dist/schemas/hero.js +73 -0
- package/dist/schemas/i18n.d.ts +125 -0
- package/dist/schemas/i18n.js +76 -0
- package/dist/schemas/icon.d.ts +284 -0
- package/dist/schemas/icon.js +7 -0
- package/dist/schemas/locale.d.ts +20 -0
- package/dist/schemas/locale.js +11 -0
- package/dist/schemas/logo.d.ts +32 -0
- package/dist/schemas/logo.js +14 -0
- package/dist/schemas/pagefind.d.ts +166 -0
- package/dist/schemas/pagefind.js +31 -0
- package/dist/schemas/prevNextLink.d.ts +10 -0
- package/dist/schemas/prevNextLink.js +14 -0
- package/dist/schemas/sidebar.d.ts +205 -0
- package/dist/schemas/sidebar.js +71 -0
- package/dist/schemas/site-title.d.ts +7 -0
- package/dist/schemas/site-title.js +17 -0
- package/dist/schemas/social.d.ts +292 -0
- package/dist/schemas/social.js +18 -0
- package/dist/schemas/tableOfContents.d.ts +24 -0
- package/dist/schemas/tableOfContents.js +16 -0
- package/dist/translations/ar.js +36 -0
- package/dist/translations/ca.js +46 -0
- package/dist/translations/cs.js +46 -0
- package/dist/translations/da.js +33 -0
- package/dist/translations/de.js +33 -0
- package/dist/translations/el.js +33 -0
- package/dist/translations/en.js +33 -0
- package/dist/translations/es.js +46 -0
- package/dist/translations/fa.js +33 -0
- package/dist/translations/fi.js +33 -0
- package/dist/translations/fr.js +36 -0
- package/dist/translations/gl.js +46 -0
- package/dist/translations/he.js +33 -0
- package/dist/translations/hi.js +36 -0
- package/dist/translations/hu.js +46 -0
- package/dist/translations/id.js +33 -0
- package/dist/translations/index.d.ts +48 -0
- package/dist/translations/index.js +75 -0
- package/dist/translations/it.js +36 -0
- package/dist/translations/ja.js +36 -0
- package/dist/translations/ko.js +36 -0
- package/dist/translations/lv.js +33 -0
- package/dist/translations/nb.js +33 -0
- package/dist/translations/nl.js +33 -0
- package/dist/translations/pl.js +36 -0
- package/dist/translations/pt.js +36 -0
- package/dist/translations/ro.js +33 -0
- package/dist/translations/ru.js +36 -0
- package/dist/translations/sk.js +33 -0
- package/dist/translations/sv.js +33 -0
- package/dist/translations/th.js +33 -0
- package/dist/translations/tr.js +33 -0
- package/dist/translations/uk.js +33 -0
- package/dist/translations/vi.js +33 -0
- package/dist/translations/zh-CN.js +36 -0
- package/dist/translations/zh-TW.js +36 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -0
- package/{user-components → dist/user-components}/FileTree.astro +1 -1
- package/{user-components → dist/user-components}/Steps.astro +1 -1
- package/{user-components → dist/user-components}/TabItem.astro +1 -1
- package/{user-components → dist/user-components}/Tabs.astro +1 -1
- package/dist/user-components/file-tree-icons.d.ts +178 -0
- package/dist/user-components/file-tree-icons.js +632 -0
- package/dist/user-components/file-tree-processor.d.ts +16 -0
- package/dist/user-components/file-tree-processor.js +132 -0
- package/dist/user-components/steps-processor.d.ts +10 -0
- package/dist/user-components/steps-processor.js +39 -0
- package/dist/user-components/tabs-processor.d.ts +23 -0
- package/dist/user-components/tabs-processor.js +70 -0
- package/dist/utils/base.d.ts +7 -0
- package/dist/utils/base.js +15 -0
- package/dist/utils/canonical.d.ts +10 -0
- package/dist/utils/canonical.js +14 -0
- package/dist/utils/collection-fs.d.ts +13 -0
- package/dist/utils/collection-fs.js +19 -0
- package/{utils/collection.ts → dist/utils/collection.d.ts} +9 -20
- package/dist/utils/collection.js +26 -0
- package/dist/utils/createPathFormatter.d.ts +9 -0
- package/dist/utils/createPathFormatter.js +35 -0
- package/dist/utils/createTranslationSystem.d.ts +23 -0
- package/dist/utils/createTranslationSystem.js +84 -0
- package/dist/utils/error-map.d.ts +23 -0
- package/dist/utils/error-map.js +125 -0
- package/dist/utils/format-path.d.ts +4 -0
- package/dist/utils/format-path.js +9 -0
- package/dist/utils/generateToC.d.ts +14 -0
- package/dist/utils/generateToC.js +25 -0
- package/dist/utils/git.d.ts +12 -0
- package/dist/utils/git.js +71 -0
- package/dist/utils/gitInlined.d.ts +6 -0
- package/dist/utils/gitInlined.js +11 -0
- package/dist/utils/head.d.ts +7 -0
- package/dist/utils/head.js +233 -0
- package/dist/utils/i18n.d.ts +50 -0
- package/dist/utils/i18n.js +141 -0
- package/dist/utils/localizedUrl.d.ts +8 -0
- package/dist/utils/localizedUrl.js +28 -0
- package/dist/utils/navigation.d.ts +19 -0
- package/dist/utils/navigation.js +353 -0
- package/dist/utils/path.d.ts +21 -0
- package/dist/utils/path.js +51 -0
- package/dist/utils/plugins.d.ts +721 -0
- package/dist/utils/plugins.js +174 -0
- package/dist/utils/routing/data.d.ts +20 -0
- package/dist/utils/routing/data.js +127 -0
- package/dist/utils/routing/index.d.ts +21 -0
- package/dist/utils/routing/index.js +106 -0
- package/dist/utils/routing/middleware.d.ts +11 -0
- package/dist/utils/routing/middleware.js +65 -0
- package/dist/utils/routing/types.d.ts +93 -0
- package/dist/utils/routing/types.js +1 -0
- package/dist/utils/slugs.d.ts +45 -0
- package/dist/utils/slugs.js +104 -0
- package/dist/utils/starlight-page.d.ts +36 -0
- package/dist/utils/starlight-page.js +120 -0
- package/dist/utils/translations-fs.d.ts +15 -0
- package/dist/utils/translations-fs.js +39 -0
- package/dist/utils/translations.d.ts +20 -0
- package/dist/utils/translations.js +29 -0
- package/dist/utils/types.d.ts +5 -0
- package/dist/utils/types.js +1 -0
- package/dist/utils/url.d.ts +7 -0
- package/{utils/url.ts → dist/utils/url.js} +5 -4
- package/dist/utils/user-config.d.ts +2055 -0
- package/dist/utils/user-config.js +136 -0
- package/dist/utils/validateLogoImports.d.ts +5 -0
- package/dist/utils/validateLogoImports.js +16 -0
- package/dist/utils/zodDeepMerge.d.ts +16 -0
- package/dist/utils/zodDeepMerge.js +53 -0
- package/package.json +60 -34
- package/CHANGELOG.md +0 -3051
- package/components/MobileMenuToggle.astro +0 -114
- package/components-internals/Icons.ts +0 -248
- package/components-internals/SidebarPersistState.ts +0 -71
- package/components-internals/TableOfContents/starlight-toc.ts +0 -127
- package/constants.ts +0 -4
- package/expressive-code.mjs +0 -23
- package/global.d.ts +0 -11
- package/i18n.d.ts +0 -18
- package/index.ts +0 -200
- package/integrations/aside-utils.ts +0 -41
- package/integrations/expressive-code/hast.d.ts +0 -5
- package/integrations/expressive-code/hast.mjs +0 -9
- package/integrations/expressive-code/index.ts +0 -125
- package/integrations/expressive-code/preprocessor.ts +0 -126
- package/integrations/expressive-code/themes/night-owl-dark.jsonc +0 -1796
- package/integrations/expressive-code/themes/night-owl-light.jsonc +0 -1695
- package/integrations/expressive-code/theming.ts +0 -105
- package/integrations/expressive-code/translations.ts +0 -36
- package/integrations/markdown-icon.ts +0 -13
- package/integrations/markdown-plugins.ts +0 -71
- package/integrations/markdown-processor.ts +0 -64
- package/integrations/pagefind.ts +0 -60
- package/integrations/rehype-code-rtl-support.ts +0 -37
- package/integrations/rehype-heading-links.ts +0 -79
- package/integrations/remark-asides.ts +0 -219
- package/integrations/remark-rehype.ts +0 -87
- package/integrations/satteri.ts +0 -265
- package/integrations/shared/absolutePathToLang.ts +0 -26
- package/integrations/shared/localeToLang.ts +0 -15
- package/integrations/shared/slugToLocale.ts +0 -18
- package/integrations/sitemap.ts +0 -23
- package/integrations/vite-layer-order.ts +0 -69
- package/integrations/vite-lazy-barrel-optimization.ts +0 -40
- package/integrations/vite-virtual-modules.ts +0 -175
- package/internal.ts +0 -6
- package/loaders.ts +0 -63
- package/locals.d.ts +0 -43
- package/locals.ts +0 -43
- package/route-data.ts +0 -11
- package/schema.ts +0 -167
- package/schemas/badge.ts +0 -40
- package/schemas/components.ts +0 -265
- package/schemas/expressiveCode.ts +0 -12
- package/schemas/favicon.ts +0 -40
- package/schemas/head.ts +0 -50
- package/schemas/hero.ts +0 -69
- package/schemas/i18n.ts +0 -244
- package/schemas/icon.ts +0 -7
- package/schemas/logo.ts +0 -28
- package/schemas/pagefind.ts +0 -128
- package/schemas/prevNextLink.ts +0 -18
- package/schemas/sidebar.ts +0 -163
- package/schemas/site-title.ts +0 -20
- package/schemas/social.ts +0 -23
- package/schemas/tableOfContents.ts +0 -21
- package/translations/README.md +0 -14
- package/translations/ar.json +0 -33
- package/translations/ca.json +0 -43
- package/translations/cs.json +0 -43
- package/translations/da.json +0 -30
- package/translations/de.json +0 -30
- package/translations/el.json +0 -30
- package/translations/en.json +0 -30
- package/translations/es.json +0 -43
- package/translations/fa.json +0 -30
- package/translations/fi.json +0 -30
- package/translations/fr.json +0 -33
- package/translations/gl.json +0 -43
- package/translations/he.json +0 -30
- package/translations/hi.json +0 -33
- package/translations/hu.json +0 -43
- package/translations/id.json +0 -30
- package/translations/index.ts +0 -76
- package/translations/it.json +0 -33
- package/translations/ja.json +0 -33
- package/translations/ko.json +0 -33
- package/translations/lv.json +0 -30
- package/translations/nb.json +0 -30
- package/translations/nl.json +0 -30
- package/translations/pl.json +0 -33
- package/translations/pt.json +0 -33
- package/translations/ro.json +0 -30
- package/translations/ru.json +0 -33
- package/translations/sk.json +0 -30
- package/translations/sv.json +0 -30
- package/translations/th.json +0 -30
- package/translations/tr.json +0 -30
- package/translations/uk.json +0 -30
- package/translations/vi.json +0 -30
- package/translations/zh-CN.json +0 -33
- package/translations/zh-TW.json +0 -33
- package/types.ts +0 -7
- package/user-components/file-tree-icons.ts +0 -782
- package/user-components/rehype-file-tree.ts +0 -251
- package/user-components/rehype-steps.ts +0 -85
- package/user-components/rehype-tabs.ts +0 -121
- package/utils/base.ts +0 -15
- package/utils/canonical.ts +0 -19
- package/utils/collection-fs.ts +0 -20
- package/utils/createPathFormatter.ts +0 -60
- package/utils/createTranslationSystem.ts +0 -137
- package/utils/error-map.ts +0 -222
- package/utils/format-path.ts +0 -7
- package/utils/generateToC.ts +0 -33
- package/utils/git.ts +0 -121
- package/utils/gitInlined.ts +0 -20
- package/utils/head.ts +0 -235
- package/utils/i18n.ts +0 -221
- package/utils/localizedUrl.ts +0 -51
- package/utils/navigation.ts +0 -574
- package/utils/path.ts +0 -58
- package/utils/plugins.ts +0 -498
- package/utils/routing/data.ts +0 -154
- package/utils/routing/index.ts +0 -139
- package/utils/routing/middleware.ts +0 -81
- package/utils/routing/types.ts +0 -101
- package/utils/slugs.ts +0 -119
- package/utils/starlight-page.ts +0 -205
- package/utils/translations-fs.ts +0 -54
- package/utils/translations.ts +0 -57
- package/utils/types.ts +0 -15
- package/utils/user-config.ts +0 -348
- package/utils/validateLogoImports.ts +0 -21
- package/utils/zodDeepMerge.ts +0 -144
- package/virtual-internal.d.ts +0 -149
- package/virtual.d.ts +0 -27
- /package/{components → dist/components}/AnchorHeading.astro +0 -0
- /package/{components → dist/components}/Banner.astro +0 -0
- /package/{components → dist/components}/ContentNotice.astro +0 -0
- /package/{components → dist/components}/ContentPanel.astro +0 -0
- /package/{components → dist/components}/DraftContentNotice.astro +0 -0
- /package/{components → dist/components}/EditLink.astro +0 -0
- /package/{components → dist/components}/FallbackContentNotice.astro +0 -0
- /package/{components → dist/components}/Footer.astro +0 -0
- /package/{components → dist/components}/Head.astro +0 -0
- /package/{components → dist/components}/Header.astro +0 -0
- /package/{components → dist/components}/Hero.astro +0 -0
- /package/{components → dist/components}/LanguageSelect.astro +0 -0
- /package/{components → dist/components}/LastUpdated.astro +0 -0
- /package/{components → dist/components}/MarkdownContent.astro +0 -0
- /package/{components → dist/components}/MobileMenuFooter.astro +0 -0
- /package/{components → dist/components}/MobileTableOfContents.astro +0 -0
- /package/{components → dist/components}/Page.astro +0 -0
- /package/{components → dist/components}/PageSidebar.astro +0 -0
- /package/{components → dist/components}/PageTitle.astro +0 -0
- /package/{components → dist/components}/Pagination.astro +0 -0
- /package/{components → dist/components}/Search.astro +0 -0
- /package/{components → dist/components}/Select.astro +0 -0
- /package/{components → dist/components}/Sidebar.astro +0 -0
- /package/{components → dist/components}/SidebarPersister.astro +0 -0
- /package/{components → dist/components}/SidebarRestorePoint.astro +0 -0
- /package/{components → dist/components}/SidebarSublist.astro +0 -0
- /package/{components → dist/components}/SiteTitle.astro +0 -0
- /package/{components → dist/components}/SkipLink.astro +0 -0
- /package/{components → dist/components}/SocialIcons.astro +0 -0
- /package/{components → dist/components}/StarlightPage.astro +0 -0
- /package/{components → dist/components}/TableOfContents.astro +0 -0
- /package/{components → dist/components}/ThemeProvider.astro +0 -0
- /package/{components → dist/components}/ThemeSelect.astro +0 -0
- /package/{components → dist/components}/TwoColumnContent.astro +0 -0
- /package/{components-internals → dist/components-internals}/TableOfContents/TableOfContentsList.astro +0 -0
- /package/{components.ts → dist/components.ts} +0 -0
- /package/{routes → dist/routes}/common.astro +0 -0
- /package/{routes → dist/routes}/ssr/404.astro +0 -0
- /package/{routes → dist/routes}/ssr/index.astro +0 -0
- /package/{routes → dist/routes}/static/404.astro +0 -0
- /package/{routes → dist/routes}/static/index.astro +0 -0
- /package/{style → dist/style}/anchor-links.css +0 -0
- /package/{style → dist/style}/asides.css +0 -0
- /package/{style → dist/style}/layers.css +0 -0
- /package/{style → dist/style}/markdown.css +0 -0
- /package/{style → dist/style}/print.css +0 -0
- /package/{style → dist/style}/props.css +0 -0
- /package/{style → dist/style}/reset.css +0 -0
- /package/{style → dist/style}/util.css +0 -0
- /package/{user-components → dist/user-components}/Aside.astro +0 -0
- /package/{user-components → dist/user-components}/Badge.astro +0 -0
- /package/{user-components → dist/user-components}/Card.astro +0 -0
- /package/{user-components → dist/user-components}/CardGrid.astro +0 -0
- /package/{user-components → dist/user-components}/Icon.astro +0 -0
- /package/{user-components → dist/user-components}/LinkButton.astro +0 -0
- /package/{user-components → dist/user-components}/LinkCard.astro +0 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { stripTrailingSlash } from "./path.js";
|
|
2
|
+
import { BuiltInDefaultLocale } from "./i18n.js";
|
|
3
|
+
import { slugToLocale as slugToLocale$1 } from "../integrations/shared/slugToLocale.js";
|
|
4
|
+
import config from "virtual:starlight/user-config";
|
|
5
|
+
//#region src/utils/slugs.ts
|
|
6
|
+
/**
|
|
7
|
+
* Get the “locale” of a slug. This is the base path at which a language is served.
|
|
8
|
+
* For example, if French docs are in `src/content/docs/french/`, the locale is `french`.
|
|
9
|
+
* Root locale slugs will return `undefined`.
|
|
10
|
+
* @param slug A collection entry slug
|
|
11
|
+
*/
|
|
12
|
+
function slugToLocale(slug) {
|
|
13
|
+
return slugToLocale$1(slug, config);
|
|
14
|
+
}
|
|
15
|
+
/** Get locale information for a given slug. */
|
|
16
|
+
function slugToLocaleData(slug) {
|
|
17
|
+
const locale = slugToLocale(slug);
|
|
18
|
+
return {
|
|
19
|
+
dir: localeToDir(locale),
|
|
20
|
+
lang: localeToLang(locale),
|
|
21
|
+
locale
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the BCP-47 language tag for the given locale.
|
|
26
|
+
* @param locale Locale string or `undefined` for the root locale.
|
|
27
|
+
*/
|
|
28
|
+
function localeToLang(locale) {
|
|
29
|
+
const lang = locale ? config.locales?.[locale]?.lang : config.locales?.root?.lang;
|
|
30
|
+
const defaultLang = config.defaultLocale?.lang || config.defaultLocale?.locale;
|
|
31
|
+
return lang || defaultLang || BuiltInDefaultLocale.lang;
|
|
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) {
|
|
38
|
+
return (locale ? config.locales?.[locale]?.dir : config.locales?.root?.dir) || config.defaultLocale.dir;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Convert a content collection slug to a param as expected by Astro’s router.
|
|
42
|
+
* This utility handles stripping `index` from file names and matches
|
|
43
|
+
* [Astro’s param sanitization logic](https://github.com/withastro/astro/blob/687d25365a41ff8a9e6da155d3527f841abb70dd/packages/astro/src/core/routing/manifest/generator.ts#L4-L18)
|
|
44
|
+
* by normalizing strings to their canonical representations.
|
|
45
|
+
* @param slug Content collection slug
|
|
46
|
+
* @returns Param compatible with Astro’s router
|
|
47
|
+
*/
|
|
48
|
+
function slugToParam(slug) {
|
|
49
|
+
return slug === "index" || slug === "" || slug === "/" ? void 0 : (slug.endsWith("/index") ? slug.slice(0, -6) : slug).normalize();
|
|
50
|
+
}
|
|
51
|
+
function slugToPathname(slug) {
|
|
52
|
+
const param = slugToParam(slug);
|
|
53
|
+
return param ? "/" + param + "/" : "/";
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Convert a slug to a different locale.
|
|
57
|
+
* For example, passing a slug of `en/home` and a locale of `fr` results in `fr/home`.
|
|
58
|
+
* An undefined locale is treated as the root locale, resulting in `home`
|
|
59
|
+
* @param slug A collection entry slug
|
|
60
|
+
* @param locale The target locale
|
|
61
|
+
* @example
|
|
62
|
+
* localizedSlug('en/home', 'fr') // => 'fr/home'
|
|
63
|
+
* localizedSlug('en/home', undefined) // => 'home'
|
|
64
|
+
*/
|
|
65
|
+
function localizedSlug(slug, locale) {
|
|
66
|
+
const slugLocale = slugToLocale(slug);
|
|
67
|
+
if (slugLocale === locale) return slug;
|
|
68
|
+
locale = locale || "";
|
|
69
|
+
if (slugLocale === slug) return locale;
|
|
70
|
+
if (slugLocale) return stripTrailingSlash(slug.replace(slugLocale + "/", locale ? locale + "/" : ""));
|
|
71
|
+
return slug ? locale + "/" + slug : locale;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Convert a file path relative to the collection root to a different locale.
|
|
75
|
+
* For example, passing a file path of `en/home.md` and a locale of `fr` results in `fr/home.md`.
|
|
76
|
+
* An undefined locale is treated as the root locale, resulting in `home.md`.
|
|
77
|
+
* @param filePath A collection entry file path relative to the collection root
|
|
78
|
+
* @param locale The target locale
|
|
79
|
+
* @example
|
|
80
|
+
* localizedFilePath('en/home.md', 'fr') // => 'fr/home.md'
|
|
81
|
+
* localizedFilePath('en/home.md', undefined) // => 'home.md'
|
|
82
|
+
*/
|
|
83
|
+
function localizedFilePath(filePath, locale) {
|
|
84
|
+
const filePathLocale = slugToLocale(filePath);
|
|
85
|
+
if (filePathLocale) return filePath.replace(filePathLocale + "/", locale ? locale + "/" : "");
|
|
86
|
+
else if (locale) return locale + "/" + filePath;
|
|
87
|
+
else return filePath;
|
|
88
|
+
}
|
|
89
|
+
/** Extract the slug from a URL. */
|
|
90
|
+
function urlToSlug(url) {
|
|
91
|
+
let pathname = url.pathname;
|
|
92
|
+
const base = stripTrailingSlash(import.meta.env.BASE_URL);
|
|
93
|
+
if (pathname.startsWith(base)) pathname = pathname.replace(base, "");
|
|
94
|
+
const segments = pathname.split("/");
|
|
95
|
+
const htmlExt = ".html";
|
|
96
|
+
if (segments.at(-1) === "index.html") segments.pop();
|
|
97
|
+
else if (segments.at(-1)?.endsWith(htmlExt)) {
|
|
98
|
+
const last = segments.pop();
|
|
99
|
+
if (last) segments.push(last.slice(0, -5));
|
|
100
|
+
}
|
|
101
|
+
return segments.filter(Boolean).join("/");
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { localeToLang, localizedFilePath, localizedSlug, slugToLocaleData, slugToParam, slugToPathname, urlToSlug };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Prettify, RemoveIndexSignature } from "./types.js";
|
|
2
|
+
import { StarlightUserConfig } from "./user-config.js";
|
|
3
|
+
import { StarlightRouteData } from "./routing/types.js";
|
|
4
|
+
import { PageProps, RouteDataContext } from "./routing/data.js";
|
|
5
|
+
import { z } from "astro/zod";
|
|
6
|
+
import { SchemaContext } from "astro:content";
|
|
7
|
+
//#region src/utils/starlight-page.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* The frontmatter schema for Starlight pages derived from the default schema for Starlight’s
|
|
10
|
+
* `docs` content collection.
|
|
11
|
+
* The frontmatter schema for Starlight pages cannot include some properties which will be omitted
|
|
12
|
+
* and some others needs to be refined to a stricter type.
|
|
13
|
+
*/
|
|
14
|
+
declare const StarlightPageFrontmatterSchema: (context: SchemaContext) => Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Type of Starlight pages frontmatter schema.
|
|
17
|
+
* We manually refines the `editUrl` type and omit the `sidebar` property as it's not possible to
|
|
18
|
+
* do that on the schema itself using Zod but the proper validation is still using a transformer.
|
|
19
|
+
* @see StarlightPageFrontmatterSchema
|
|
20
|
+
*/
|
|
21
|
+
type StarlightPageFrontmatter = Omit<z.input<Awaited<ReturnType<typeof StarlightPageFrontmatterSchema>>>, 'editUrl' | 'sidebar'> & {
|
|
22
|
+
editUrl?: string | false;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The props accepted by the `<StarlightPage/>` component.
|
|
26
|
+
*/
|
|
27
|
+
type StarlightPageProps = Prettify<Partial<Omit<RemoveIndexSignature<PageProps>, 'entry' | 'entryMeta' | 'id' | 'locale'>> & Partial<Pick<StarlightRouteData, 'hasSidebar'>> & {
|
|
28
|
+
sidebar?: StarlightUserConfig['sidebar'];
|
|
29
|
+
frontmatter: StarlightPageFrontmatter;
|
|
30
|
+
}>;
|
|
31
|
+
declare function generateStarlightPageRouteData({ props, context }: {
|
|
32
|
+
props: StarlightPageProps;
|
|
33
|
+
context: RouteDataContext;
|
|
34
|
+
}): Promise<StarlightRouteData>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { StarlightPageProps, generateStarlightPageRouteData };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { getCollectionPathFromRoot } from "./collection.js";
|
|
2
|
+
import { stripLeadingAndTrailingSlashes } from "./path.js";
|
|
3
|
+
import { parseAsyncWithFriendlyErrors, parseWithFriendlyErrors } from "./error-map.js";
|
|
4
|
+
import { SidebarItemSchema } from "../schemas/sidebar.js";
|
|
5
|
+
import { docsSchema } from "../schema.js";
|
|
6
|
+
import { getHead } from "./head.js";
|
|
7
|
+
import { slugToLocaleData, urlToSlug } from "./slugs.js";
|
|
8
|
+
import { getPrevNextLinks, getSidebar, getSidebarFromConfig } from "./navigation.js";
|
|
9
|
+
import { getSiteTitle, getSiteTitleHref, getToC } from "./routing/data.js";
|
|
10
|
+
import { z } from "astro/zod";
|
|
11
|
+
import "astro:content";
|
|
12
|
+
import config from "virtual:starlight/user-config";
|
|
13
|
+
import project from "virtual:starlight/project-context";
|
|
14
|
+
//#region src/utils/starlight-page.ts
|
|
15
|
+
/**
|
|
16
|
+
* The frontmatter schema for Starlight pages derived from the default schema for Starlight’s
|
|
17
|
+
* `docs` content collection.
|
|
18
|
+
* The frontmatter schema for Starlight pages cannot include some properties which will be omitted
|
|
19
|
+
* and some others needs to be refined to a stricter type.
|
|
20
|
+
*/
|
|
21
|
+
const StarlightPageFrontmatterSchema = async (context) => {
|
|
22
|
+
const userDocsSchema = await getUserDocsSchema();
|
|
23
|
+
return (typeof userDocsSchema === "function" ? userDocsSchema(context) : userDocsSchema).transform((frontmatter) => {
|
|
24
|
+
/**
|
|
25
|
+
* Starlight pages can only be edited if an edit URL is explicitly provided.
|
|
26
|
+
* The `sidebar` frontmatter prop only works for pages in an autogenerated links group.
|
|
27
|
+
* Starlight pages edit links cannot be autogenerated.
|
|
28
|
+
*
|
|
29
|
+
* These changes to the schema are done using a transformer and not using the usual `omit`
|
|
30
|
+
* method because when the frontmatter schema is extended by the user, an intersection between
|
|
31
|
+
* the default schema and the user schema is created using the `and` method. Intersections in
|
|
32
|
+
* Zod returns a `ZodIntersection` object which does not have some methods like `omit` or
|
|
33
|
+
* `pick`.
|
|
34
|
+
*
|
|
35
|
+
* This transformer only sets the `editUrl` default value and removes the `sidebar` property
|
|
36
|
+
* from the validated output but does not apply any changes to the input schema type itself so
|
|
37
|
+
* this needs to be done manually.
|
|
38
|
+
*
|
|
39
|
+
* @see StarlightPageFrontmatter
|
|
40
|
+
* @see https://github.com/colinhacks/zod#intersections
|
|
41
|
+
*/
|
|
42
|
+
const { editUrl, sidebar, ...others } = frontmatter;
|
|
43
|
+
const pageEditUrl = editUrl === void 0 || editUrl === true ? false : editUrl;
|
|
44
|
+
return {
|
|
45
|
+
...others,
|
|
46
|
+
editUrl: pageEditUrl
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
/** Parse sidebar prop to ensure it's valid. */
|
|
51
|
+
const validateSidebarProp = (sidebarProp) => {
|
|
52
|
+
return parseWithFriendlyErrors(SidebarItemSchema.array().optional(), sidebarProp, "Invalid sidebar prop passed to the `<StarlightPage/>` component.");
|
|
53
|
+
};
|
|
54
|
+
async function generateStarlightPageRouteData({ props, context }) {
|
|
55
|
+
const { frontmatter, ...routeProps } = props;
|
|
56
|
+
const { url } = context;
|
|
57
|
+
const id = urlToSlug(url);
|
|
58
|
+
const pageFrontmatter = await getStarlightPageFrontmatter(frontmatter);
|
|
59
|
+
const localeData = slugToLocaleData(id);
|
|
60
|
+
const sidebar = props.sidebar ? getSidebarFromConfig(validateSidebarProp(props.sidebar), url.pathname, localeData.locale) : getSidebar(url.pathname, localeData.locale);
|
|
61
|
+
const headings = props.headings ?? [];
|
|
62
|
+
const entry = {
|
|
63
|
+
id,
|
|
64
|
+
body: "",
|
|
65
|
+
collection: "docs",
|
|
66
|
+
filePath: `${getCollectionPathFromRoot("docs", project)}/${stripLeadingAndTrailingSlashes(id)}.md`,
|
|
67
|
+
data: {
|
|
68
|
+
...pageFrontmatter,
|
|
69
|
+
sidebar: {
|
|
70
|
+
attrs: {},
|
|
71
|
+
hidden: false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const entryMeta = {
|
|
76
|
+
dir: props.dir ?? localeData.dir,
|
|
77
|
+
lang: props.lang ?? localeData.lang,
|
|
78
|
+
locale: localeData.locale
|
|
79
|
+
};
|
|
80
|
+
const editUrl = pageFrontmatter.editUrl ? new URL(pageFrontmatter.editUrl) : void 0;
|
|
81
|
+
const lastUpdated = pageFrontmatter.lastUpdated instanceof Date ? pageFrontmatter.lastUpdated : void 0;
|
|
82
|
+
const pageProps = {
|
|
83
|
+
...routeProps,
|
|
84
|
+
...localeData,
|
|
85
|
+
entry,
|
|
86
|
+
entryMeta,
|
|
87
|
+
headings,
|
|
88
|
+
id,
|
|
89
|
+
locale: localeData.locale
|
|
90
|
+
};
|
|
91
|
+
const siteTitle = getSiteTitle(localeData.lang);
|
|
92
|
+
return {
|
|
93
|
+
...routeProps,
|
|
94
|
+
...localeData,
|
|
95
|
+
id,
|
|
96
|
+
editUrl,
|
|
97
|
+
entry,
|
|
98
|
+
entryMeta,
|
|
99
|
+
hasSidebar: props.hasSidebar ?? entry.data.template !== "splash",
|
|
100
|
+
head: getHead(pageProps, context, siteTitle),
|
|
101
|
+
headings,
|
|
102
|
+
lastUpdated,
|
|
103
|
+
pagination: getPrevNextLinks(sidebar, config.pagination, entry.data),
|
|
104
|
+
sidebar,
|
|
105
|
+
siteTitle,
|
|
106
|
+
siteTitleHref: getSiteTitleHref(localeData.locale),
|
|
107
|
+
toc: getToC(pageProps)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** Validates the Starlight page frontmatter properties from the props received by a Starlight page. */
|
|
111
|
+
async function getStarlightPageFrontmatter(frontmatter) {
|
|
112
|
+
const schema = await StarlightPageFrontmatterSchema({ image: (() => z.custom((value) => value && (typeof value === "function" || typeof value === "object") && "src" in value && "width" in value && "height" in value && "format" in value, "Invalid image passed to `<StarlightPage>` component. Expected imported `ImageMetadata` object.")) });
|
|
113
|
+
return parseAsyncWithFriendlyErrors(schema, frontmatter, "Invalid frontmatter props passed to the `<StarlightPage/>` component.");
|
|
114
|
+
}
|
|
115
|
+
/** Returns the user docs schema and falls back to the default schema if needed. */
|
|
116
|
+
async function getUserDocsSchema() {
|
|
117
|
+
return (await import("virtual:starlight/collection-config")).collections?.docs?.schema ?? docsSchema();
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
export { generateStarlightPageRouteData };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StarlightConfig } from "./user-config.js";
|
|
2
|
+
import { i18nSchemaOutput } from "../schemas/i18n.js";
|
|
3
|
+
import { I18nT } from "./createTranslationSystem.js";
|
|
4
|
+
import { AstroConfig } from "astro";
|
|
5
|
+
//#region src/utils/translations-fs.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Loads and creates a translation system from the file system.
|
|
8
|
+
* Only for use in integration code.
|
|
9
|
+
* In modules loaded by Vite/Astro, import [`useTranslations`](./translations.ts) instead.
|
|
10
|
+
*
|
|
11
|
+
* @see [`./translations.ts`](./translations.ts)
|
|
12
|
+
*/
|
|
13
|
+
declare function createTranslationSystemFromFs<T extends i18nSchemaOutput>(opts: Pick<StarlightConfig, 'defaultLocale' | 'locales'>, { srcDir }: Pick<AstroConfig, 'srcDir'>, pluginTranslations?: Record<string, T>): Promise<(lang: string | undefined) => I18nT>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { createTranslationSystemFromFs };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createTranslationSystem } from "./createTranslationSystem.js";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import yaml from "js-yaml";
|
|
6
|
+
//#region src/utils/translations-fs.ts
|
|
7
|
+
const contentCollectionFileExtensions = [
|
|
8
|
+
".json",
|
|
9
|
+
".yaml",
|
|
10
|
+
".yml"
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* Loads and creates a translation system from the file system.
|
|
14
|
+
* Only for use in integration code.
|
|
15
|
+
* In modules loaded by Vite/Astro, import [`useTranslations`](./translations.ts) instead.
|
|
16
|
+
*
|
|
17
|
+
* @see [`./translations.ts`](./translations.ts)
|
|
18
|
+
*/
|
|
19
|
+
async function createTranslationSystemFromFs(opts, { srcDir }, pluginTranslations = {}) {
|
|
20
|
+
/** All translation data from the i18n collection, keyed by `id`, which matches locale. */
|
|
21
|
+
const userTranslations = {};
|
|
22
|
+
try {
|
|
23
|
+
const i18nDir = new URL("content/i18n/", srcDir);
|
|
24
|
+
const files = fs.readdirSync(i18nDir, "utf-8");
|
|
25
|
+
for (const file of files) {
|
|
26
|
+
const filePath = path.parse(file);
|
|
27
|
+
if (!contentCollectionFileExtensions.includes(filePath.ext)) continue;
|
|
28
|
+
const id = filePath.name;
|
|
29
|
+
const url = new URL(filePath.base, i18nDir);
|
|
30
|
+
const content = fs.readFileSync(new URL(file, i18nDir), "utf-8");
|
|
31
|
+
userTranslations[id] = filePath.ext === ".json" ? JSON.parse(content) : yaml.load(content, { filename: fileURLToPath(url) });
|
|
32
|
+
}
|
|
33
|
+
} catch (e) {
|
|
34
|
+
if (e instanceof Error && "code" in e && e.code === "ENOENT") {} else throw e;
|
|
35
|
+
}
|
|
36
|
+
return createTranslationSystem(opts, userTranslations, pluginTranslations);
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { createTranslationSystemFromFs };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RemoveIndexSignature } from "./types.js";
|
|
2
|
+
import { i18nSchemaOutput } from "../schemas/i18n.js";
|
|
3
|
+
import { I18nT } from "./createTranslationSystem.js";
|
|
4
|
+
import { CollectionEntry, DataCollectionKey } from "astro:content";
|
|
5
|
+
//#region src/utils/translations.d.ts
|
|
6
|
+
type i18nCollection = CollectionEntry<'i18n'>;
|
|
7
|
+
type UserI18nSchema = 'i18n' extends DataCollectionKey ? i18nCollection extends {
|
|
8
|
+
data: infer T;
|
|
9
|
+
} ? i18nSchemaOutput & T : i18nSchemaOutput : i18nSchemaOutput;
|
|
10
|
+
type UserI18nKeys = keyof RemoveIndexSignature<UserI18nSchema>;
|
|
11
|
+
/**
|
|
12
|
+
* Generate a utility function that returns UI strings for the given language.
|
|
13
|
+
* @param {string | undefined} [lang]
|
|
14
|
+
* @example
|
|
15
|
+
* const t = useTranslations('en');
|
|
16
|
+
* const label = t('search.label'); // => 'Search'
|
|
17
|
+
*/
|
|
18
|
+
declare const useTranslations: (lang: string | undefined) => I18nT;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { UserI18nKeys, UserI18nSchema, useTranslations };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getCollectionPathFromRoot } from "./collection.js";
|
|
2
|
+
import { stripExtension, stripLeadingSlash } from "./path.js";
|
|
3
|
+
import { createTranslationSystem } from "./createTranslationSystem.js";
|
|
4
|
+
import { getCollection } from "astro:content";
|
|
5
|
+
import config from "virtual:starlight/user-config";
|
|
6
|
+
import project from "virtual:starlight/project-context";
|
|
7
|
+
import pluginTranslations from "virtual:starlight/plugin-translations";
|
|
8
|
+
//#region src/utils/translations.ts
|
|
9
|
+
const i18nCollectionPathFromRoot = getCollectionPathFromRoot("i18n", project);
|
|
10
|
+
/** Get all translation data from the i18n collection, keyed by `lang`, which are BCP-47 language tags. */
|
|
11
|
+
async function loadTranslations() {
|
|
12
|
+
const warn = console.warn;
|
|
13
|
+
console.warn = () => {};
|
|
14
|
+
const userTranslations = Object.fromEntries((await getCollection("i18n")).map(({ id, data, filePath }) => {
|
|
15
|
+
return [!filePath ? id : stripExtension(stripLeadingSlash(filePath.replace(i18nCollectionPathFromRoot, ""))), data];
|
|
16
|
+
}));
|
|
17
|
+
console.warn = warn;
|
|
18
|
+
return userTranslations;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate a utility function that returns UI strings for the given language.
|
|
22
|
+
* @param {string | undefined} [lang]
|
|
23
|
+
* @example
|
|
24
|
+
* const t = useTranslations('en');
|
|
25
|
+
* const label = t('search.label'); // => 'Search'
|
|
26
|
+
*/
|
|
27
|
+
const useTranslations = await createTranslationSystem(config, await loadTranslations(), pluginTranslations);
|
|
28
|
+
//#endregion
|
|
29
|
+
export { useTranslations };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
//#region src/utils/types.d.ts
|
|
2
|
+
type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K]; };
|
|
3
|
+
type Prettify<T> = { [K in keyof T]: T[K]; } & {};
|
|
4
|
+
//#endregion
|
|
5
|
+
export { Prettify, RemoveIndexSignature };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/utils/url.d.ts
|
|
2
|
+
/** Check if a string starts with one of `http://` or `https://`. */
|
|
3
|
+
declare const isAbsoluteUrl: (link: string) => boolean;
|
|
4
|
+
/** Check if a string contains a protocol (e.g., `http:`, `https:`, `mailto:`). */
|
|
5
|
+
declare const hasProtocol: (link: string) => boolean;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { hasProtocol, isAbsoluteUrl };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
//#region src/utils/url.ts
|
|
1
2
|
const HTTPProtocolRegEx = /^https?:\/\//;
|
|
2
3
|
const ProtocolRegEx = /^[a-z][a-z\d+.-]*:/i;
|
|
3
|
-
|
|
4
4
|
/** Check if a string starts with one of `http://` or `https://`. */
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const isAbsoluteUrl = (link) => HTTPProtocolRegEx.test(link);
|
|
7
6
|
/** Check if a string contains a protocol (e.g., `http:`, `https:`, `mailto:`). */
|
|
8
|
-
|
|
7
|
+
const hasProtocol = (link) => ProtocolRegEx.test(link);
|
|
8
|
+
//#endregion
|
|
9
|
+
export { hasProtocol, isAbsoluteUrl };
|