@astrojs/starlight 0.41.10 → 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/{style → dist/style}/anchor-links.css +13 -1
- 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 +62 -33
- package/CHANGELOG.md +0 -3043
- 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 -566
- 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 -135
- 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}/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
package/utils/translations-fs.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import yaml from 'js-yaml';
|
|
5
|
-
import type { i18nSchemaOutput } from '../schemas/i18n';
|
|
6
|
-
import { createTranslationSystem } from './createTranslationSystem';
|
|
7
|
-
import type { StarlightConfig } from './user-config';
|
|
8
|
-
import type { AstroConfig } from 'astro';
|
|
9
|
-
|
|
10
|
-
const contentCollectionFileExtensions = ['.json', '.yaml', '.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
|
-
export async function createTranslationSystemFromFs<T extends i18nSchemaOutput>(
|
|
20
|
-
opts: Pick<StarlightConfig, 'defaultLocale' | 'locales'>,
|
|
21
|
-
{ srcDir }: Pick<AstroConfig, 'srcDir'>,
|
|
22
|
-
pluginTranslations: Record<string, T> = {}
|
|
23
|
-
) {
|
|
24
|
-
/** All translation data from the i18n collection, keyed by `id`, which matches locale. */
|
|
25
|
-
const userTranslations: Record<string, i18nSchemaOutput> = {};
|
|
26
|
-
try {
|
|
27
|
-
const i18nDir = new URL('content/i18n/', srcDir);
|
|
28
|
-
// Load the user’s i18n directory
|
|
29
|
-
const files = fs.readdirSync(i18nDir, 'utf-8');
|
|
30
|
-
// Load the user’s i18n collection and ignore the error if it doesn’t exist.
|
|
31
|
-
for (const file of files) {
|
|
32
|
-
const filePath = path.parse(file);
|
|
33
|
-
if (!contentCollectionFileExtensions.includes(filePath.ext)) continue;
|
|
34
|
-
const id = filePath.name;
|
|
35
|
-
const url = new URL(filePath.base, i18nDir);
|
|
36
|
-
const content = fs.readFileSync(new URL(file, i18nDir), 'utf-8');
|
|
37
|
-
const data = (
|
|
38
|
-
filePath.ext === '.json'
|
|
39
|
-
? JSON.parse(content)
|
|
40
|
-
: yaml.load(content, { filename: fileURLToPath(url) })
|
|
41
|
-
) as i18nSchemaOutput;
|
|
42
|
-
userTranslations[id] = data;
|
|
43
|
-
}
|
|
44
|
-
} catch (e: unknown) {
|
|
45
|
-
if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {
|
|
46
|
-
// i18nDir doesn’t exist, so we ignore the error.
|
|
47
|
-
} else {
|
|
48
|
-
// Other errors may be meaningful, e.g. JSON syntax errors, so should be thrown.
|
|
49
|
-
throw e;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return createTranslationSystem(opts, userTranslations, pluginTranslations);
|
|
54
|
-
}
|
package/utils/translations.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { getCollection, type CollectionEntry, type DataCollectionKey } from 'astro:content';
|
|
2
|
-
import config from 'virtual:starlight/user-config';
|
|
3
|
-
import project from 'virtual:starlight/project-context';
|
|
4
|
-
import pluginTranslations from 'virtual:starlight/plugin-translations';
|
|
5
|
-
import type { i18nSchemaOutput } from '../schemas/i18n';
|
|
6
|
-
import { createTranslationSystem } from './createTranslationSystem';
|
|
7
|
-
import type { RemoveIndexSignature } from './types';
|
|
8
|
-
import { getCollectionPathFromRoot } from './collection';
|
|
9
|
-
import { stripExtension, stripLeadingSlash } from './path';
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
12
|
-
// @ts-ignore - This may be a type error in projects without an i18n collection and running
|
|
13
|
-
// `tsc --noEmit` in their project. Note that it is not possible to inline this type in
|
|
14
|
-
// `UserI18nSchema` because this would break types for users having multiple data collections.
|
|
15
|
-
type i18nCollection = CollectionEntry<'i18n'>;
|
|
16
|
-
|
|
17
|
-
const i18nCollectionPathFromRoot = getCollectionPathFromRoot('i18n', project);
|
|
18
|
-
|
|
19
|
-
export type UserI18nSchema = 'i18n' extends DataCollectionKey
|
|
20
|
-
? i18nCollection extends { data: infer T }
|
|
21
|
-
? i18nSchemaOutput & T
|
|
22
|
-
: i18nSchemaOutput
|
|
23
|
-
: i18nSchemaOutput;
|
|
24
|
-
export type UserI18nKeys = keyof RemoveIndexSignature<UserI18nSchema>;
|
|
25
|
-
|
|
26
|
-
/** Get all translation data from the i18n collection, keyed by `lang`, which are BCP-47 language tags. */
|
|
27
|
-
async function loadTranslations() {
|
|
28
|
-
// Briefly override `console.warn()` to silence logging when a project has no i18n collection.
|
|
29
|
-
const warn = console.warn;
|
|
30
|
-
console.warn = () => {};
|
|
31
|
-
const userTranslations: Record<string, UserI18nSchema> = Object.fromEntries(
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
33
|
-
// @ts-ignore — may be a type error in projects without an i18n collection
|
|
34
|
-
(await getCollection('i18n')).map(({ id, data, filePath }) => {
|
|
35
|
-
const lang = !filePath
|
|
36
|
-
? id
|
|
37
|
-
: stripExtension(stripLeadingSlash(filePath.replace(i18nCollectionPathFromRoot, '')));
|
|
38
|
-
return [lang, data] as const;
|
|
39
|
-
})
|
|
40
|
-
);
|
|
41
|
-
// Restore the original warn implementation.
|
|
42
|
-
console.warn = warn;
|
|
43
|
-
return userTranslations;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Generate a utility function that returns UI strings for the given language.
|
|
48
|
-
* @param {string | undefined} [lang]
|
|
49
|
-
* @example
|
|
50
|
-
* const t = useTranslations('en');
|
|
51
|
-
* const label = t('search.label'); // => 'Search'
|
|
52
|
-
*/
|
|
53
|
-
export const useTranslations = await createTranslationSystem(
|
|
54
|
-
config,
|
|
55
|
-
await loadTranslations(),
|
|
56
|
-
pluginTranslations
|
|
57
|
-
);
|
package/utils/types.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// https://stackoverflow.com/a/66252656/1945960
|
|
2
|
-
export type RemoveIndexSignature<T> = {
|
|
3
|
-
[K in keyof T as string extends K
|
|
4
|
-
? never
|
|
5
|
-
: number extends K
|
|
6
|
-
? never
|
|
7
|
-
: symbol extends K
|
|
8
|
-
? never
|
|
9
|
-
: K]: T[K];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// https://www.totaltypescript.com/concepts/the-prettify-helper
|
|
13
|
-
export type Prettify<T> = {
|
|
14
|
-
[K in keyof T]: T[K];
|
|
15
|
-
} & {};
|
package/utils/user-config.ts
DELETED
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { z } from 'astro/zod';
|
|
2
|
-
import { parse as bcpParse, stringify as bcpStringify } from 'bcp-47';
|
|
3
|
-
import { ComponentConfigSchema } from '../schemas/components';
|
|
4
|
-
import { ExpressiveCodeSchema } from '../schemas/expressiveCode';
|
|
5
|
-
import { FaviconSchema } from '../schemas/favicon';
|
|
6
|
-
import { HeadConfigSchema } from '../schemas/head';
|
|
7
|
-
import { LogoConfigSchema } from '../schemas/logo';
|
|
8
|
-
import { PagefindConfigDefaults, PagefindConfigSchema } from '../schemas/pagefind';
|
|
9
|
-
import { SidebarItemSchema } from '../schemas/sidebar';
|
|
10
|
-
import { TitleConfigSchema, TitleTransformConfigSchema } from '../schemas/site-title';
|
|
11
|
-
import { SocialLinksSchema } from '../schemas/social';
|
|
12
|
-
import { UserConfigTableOfContentsSchema } from '../schemas/tableOfContents';
|
|
13
|
-
import { BuiltInDefaultLocale } from './i18n';
|
|
14
|
-
|
|
15
|
-
const LocaleSchema = z.object({
|
|
16
|
-
/** The label for this language to show in UI, e.g. `"English"`, `"العربية"`, or `"简体中文"`. */
|
|
17
|
-
label: z.string(),
|
|
18
|
-
/** The BCP-47 tag for this language, e.g. `"en"`, `"ar"`, or `"zh-CN"`. */
|
|
19
|
-
lang: z.string().optional(),
|
|
20
|
-
/** The writing direction of this language; `"ltr"` for left-to-right (the default) or `"rtl"` for right-to-left. */
|
|
21
|
-
dir: z.enum(['rtl', 'ltr']).optional().default('ltr'),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const UserConfigSchema = z.object({
|
|
25
|
-
/**
|
|
26
|
-
* Title for your website. Will be used in metadata and as browser tab title.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* title: 'My Docs'
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* title: { en: 'My Docs' }
|
|
33
|
-
*/
|
|
34
|
-
title: TitleConfigSchema(),
|
|
35
|
-
|
|
36
|
-
/** Description metadata for your website. Can be used in page metadata. */
|
|
37
|
-
description: z.string().optional(),
|
|
38
|
-
|
|
39
|
-
/** Set a logo image to show in the navigation bar alongside or instead of the site title. */
|
|
40
|
-
logo: LogoConfigSchema(),
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Optional details about the social media accounts for this site.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* social: [
|
|
47
|
-
* { icon: 'codeberg', label: 'Codeberg', href: 'https://codeberg.org/knut' },
|
|
48
|
-
* { icon: 'discord', label: 'Discord', href: 'https://astro.build/chat' },
|
|
49
|
-
* { icon: 'github', label: 'GitHub', href: 'https://github.com/withastro' },
|
|
50
|
-
* { icon: 'gitlab', label: 'GitLab', href: 'https://gitlab.com/delucis' },
|
|
51
|
-
* { icon: 'mastodon', label: 'Mastodon', href: 'https://m.webtoo.ls/@astro' },
|
|
52
|
-
* ]
|
|
53
|
-
*/
|
|
54
|
-
social: SocialLinksSchema(),
|
|
55
|
-
|
|
56
|
-
/** The tagline for your website. */
|
|
57
|
-
tagline: z.string().optional(),
|
|
58
|
-
|
|
59
|
-
/** Configure the defaults for the table of contents on each page. */
|
|
60
|
-
tableOfContents: UserConfigTableOfContentsSchema(),
|
|
61
|
-
|
|
62
|
-
/** Enable and configure “Edit this page” links. */
|
|
63
|
-
editLink: z
|
|
64
|
-
.object({
|
|
65
|
-
/** Set the base URL for edit links. The final link will be `baseUrl` + the current page path. */
|
|
66
|
-
baseUrl: z.url().optional(),
|
|
67
|
-
})
|
|
68
|
-
.optional()
|
|
69
|
-
.default({}),
|
|
70
|
-
|
|
71
|
-
/** Configure locales for internationalization (i18n). */
|
|
72
|
-
locales: z
|
|
73
|
-
.object({
|
|
74
|
-
/** Configure a “root” locale to serve a default language from `/`. */
|
|
75
|
-
root: LocaleSchema.required({ lang: true }).optional(),
|
|
76
|
-
})
|
|
77
|
-
.catchall(LocaleSchema)
|
|
78
|
-
.transform((locales, ctx) => {
|
|
79
|
-
for (const key in locales) {
|
|
80
|
-
const locale = locales[key]!;
|
|
81
|
-
// Fall back to the key in the locales object as the lang.
|
|
82
|
-
let lang = locale.lang || key;
|
|
83
|
-
|
|
84
|
-
// Parse the lang tag so we can check it is valid according to BCP-47.
|
|
85
|
-
const schema = bcpParse(lang, { forgiving: true });
|
|
86
|
-
schema.region = schema.region?.toUpperCase();
|
|
87
|
-
const normalizedLang = bcpStringify(schema);
|
|
88
|
-
|
|
89
|
-
// Error if parsing the language tag failed.
|
|
90
|
-
if (!normalizedLang) {
|
|
91
|
-
ctx.issues.push({
|
|
92
|
-
code: 'custom',
|
|
93
|
-
message: `Could not validate language tag "${lang}" at locales.${key}.lang.`,
|
|
94
|
-
input: lang,
|
|
95
|
-
});
|
|
96
|
-
return z.NEVER;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Let users know we’re modifying their configured `lang`.
|
|
100
|
-
if (normalizedLang !== lang) {
|
|
101
|
-
console.warn(
|
|
102
|
-
`Warning: using "${normalizedLang}" language tag for locales.${key}.lang instead of "${lang}".`
|
|
103
|
-
);
|
|
104
|
-
lang = normalizedLang;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Set the final value as the normalized lang, based on the key if needed.
|
|
108
|
-
locale.lang = lang;
|
|
109
|
-
}
|
|
110
|
-
return locales;
|
|
111
|
-
})
|
|
112
|
-
.optional(),
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Specify the default language for this site.
|
|
116
|
-
*
|
|
117
|
-
* The default locale will be used to provide fallback content where translations are missing.
|
|
118
|
-
*/
|
|
119
|
-
defaultLocale: z.string().optional(),
|
|
120
|
-
|
|
121
|
-
/** Configure your site’s sidebar navigation items. */
|
|
122
|
-
sidebar: SidebarItemSchema.array().optional(),
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Add extra tags to your site’s `<head>`.
|
|
126
|
-
*
|
|
127
|
-
* Can also be set for a single page in a page’s frontmatter.
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* // Add Fathom analytics to your site
|
|
131
|
-
* starlight({
|
|
132
|
-
* head: [
|
|
133
|
-
* {
|
|
134
|
-
* tag: 'script',
|
|
135
|
-
* attrs: {
|
|
136
|
-
* src: 'https://cdn.usefathom.com/script.js',
|
|
137
|
-
* 'data-site': 'MY-FATHOM-ID',
|
|
138
|
-
* defer: true,
|
|
139
|
-
* },
|
|
140
|
-
* },
|
|
141
|
-
* ],
|
|
142
|
-
* })
|
|
143
|
-
*/
|
|
144
|
-
head: HeadConfigSchema({ source: 'config' }),
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Provide CSS files to customize the look and feel of your Starlight site.
|
|
148
|
-
*
|
|
149
|
-
* Supports local CSS files relative to the root of your project,
|
|
150
|
-
* e.g. `'/src/custom.css'`, and CSS you installed as an npm
|
|
151
|
-
* module, e.g. `'@fontsource/roboto'`.
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* starlight({
|
|
155
|
-
* customCss: ['/src/custom-styles.css', '@fontsource/roboto'],
|
|
156
|
-
* })
|
|
157
|
-
*/
|
|
158
|
-
customCss: z
|
|
159
|
-
.string()
|
|
160
|
-
.array()
|
|
161
|
-
.optional()
|
|
162
|
-
.default([])
|
|
163
|
-
.superRefine((paths, ctx) => {
|
|
164
|
-
const invalidPathRegex = /^\.?\/public\/.+$/;
|
|
165
|
-
const invalidPaths = paths.filter((path) => invalidPathRegex.test(path));
|
|
166
|
-
if (invalidPaths.length > 0) {
|
|
167
|
-
ctx.issues.push({
|
|
168
|
-
code: 'custom',
|
|
169
|
-
message:
|
|
170
|
-
`These paths in your Starlight \`customCss\` config are invalid: ${invalidPaths.map((path) => `\`"${path}"\``).join(', ')}\n\n` +
|
|
171
|
-
`CSS files specified in \`customCss\` should be in the \`src/\` directory, not the \`public/\` directory.\n\n` +
|
|
172
|
-
`You should move these CSS files into the \`src/\` directory and update the path in \`customCss\` to match.`,
|
|
173
|
-
input: paths,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}),
|
|
177
|
-
|
|
178
|
-
/** Define if the last update date should be visible in the page footer. */
|
|
179
|
-
lastUpdated: z.boolean().default(false),
|
|
180
|
-
|
|
181
|
-
/** Define if the previous and next page links should be visible in the page footer. */
|
|
182
|
-
pagination: z.boolean().default(true),
|
|
183
|
-
|
|
184
|
-
/** The default favicon for your site which should be a path to an image in the `public/` directory. */
|
|
185
|
-
favicon: FaviconSchema(),
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Define how code blocks are rendered by passing options to Expressive Code,
|
|
189
|
-
* or disable the integration by passing `false`.
|
|
190
|
-
*/
|
|
191
|
-
expressiveCode: ExpressiveCodeSchema(),
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Configure Starlight’s default site search provider Pagefind. Set to `false` to disable indexing
|
|
195
|
-
* your site with Pagefind, which will also hide the default search UI if in use.
|
|
196
|
-
*/
|
|
197
|
-
pagefind: z
|
|
198
|
-
.boolean()
|
|
199
|
-
// Transform `true` to our default config object.
|
|
200
|
-
.transform((val) => val && PagefindConfigDefaults())
|
|
201
|
-
.or(PagefindConfigSchema())
|
|
202
|
-
.optional(),
|
|
203
|
-
|
|
204
|
-
/** Specify paths to components that should override Starlight’s default components */
|
|
205
|
-
components: ComponentConfigSchema(),
|
|
206
|
-
|
|
207
|
-
/** Will be used as title delimiter in the generated `<title>` tag. */
|
|
208
|
-
titleDelimiter: z.string().default('|'),
|
|
209
|
-
|
|
210
|
-
/** Disable Starlight's default 404 page. */
|
|
211
|
-
disable404Route: z.boolean().default(false),
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Define whether Starlight pages should be prerendered or not.
|
|
215
|
-
* Defaults to always prerender Starlight pages, even when the project is
|
|
216
|
-
* set to "server" output mode.
|
|
217
|
-
*/
|
|
218
|
-
prerender: z.boolean().default(true),
|
|
219
|
-
|
|
220
|
-
/** Enable displaying a “Built with Starlight” link in your site’s footer. */
|
|
221
|
-
credits: z.boolean().default(false),
|
|
222
|
-
|
|
223
|
-
/** Add middleware to process Starlight’s route data for each page. */
|
|
224
|
-
routeMiddleware: z
|
|
225
|
-
.string()
|
|
226
|
-
.transform((string) => [string])
|
|
227
|
-
.or(z.string().array())
|
|
228
|
-
.default([])
|
|
229
|
-
.superRefine((middlewares, ctx) => {
|
|
230
|
-
// Regex pattern to match invalid middleware paths: https://regex101.com/r/kQH7xm/2
|
|
231
|
-
const invalidPathRegex = /^\.?\/src\/middleware(?:\/index)?\.[jt]s$/;
|
|
232
|
-
const invalidPaths = middlewares.filter((middleware) => invalidPathRegex.test(middleware));
|
|
233
|
-
for (const invalidPath of invalidPaths) {
|
|
234
|
-
ctx.issues.push({
|
|
235
|
-
code: 'custom',
|
|
236
|
-
message:
|
|
237
|
-
`The \`"${invalidPath}"\` path in your Starlight \`routeMiddleware\` config conflicts with Astro’s middleware locations.\n\n` +
|
|
238
|
-
`You should rename \`${invalidPath}\` to something else like \`./src/starlightRouteData.ts\` and update the \`routeMiddleware\` file path to match.\n\n` +
|
|
239
|
-
'- More about Starlight route middleware: https://starlight.astro.build/guides/route-data/#how-to-customize-route-data\n' +
|
|
240
|
-
'- More about Astro middleware: https://docs.astro.build/en/guides/middleware/',
|
|
241
|
-
input: middlewares,
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
}),
|
|
245
|
-
|
|
246
|
-
/** Configure features that impact Starlight’s Markdown processing. */
|
|
247
|
-
markdown: z
|
|
248
|
-
.object({
|
|
249
|
-
/** Define whether headings in content should be rendered with clickable anchor links. Default: `true`. */
|
|
250
|
-
headingLinks: z.boolean().default(true),
|
|
251
|
-
/**
|
|
252
|
-
* Define additional directories where files should be processed by Starlight’s Markdown pipeline.
|
|
253
|
-
*
|
|
254
|
-
* Supports local directories relative to the root of your project, e.g. './src/data/comments/'.
|
|
255
|
-
* Content of the `docs` content collection is always processed by Starlight’s Markdown pipeline.
|
|
256
|
-
*/
|
|
257
|
-
processedDirs: z.string().array().default([]),
|
|
258
|
-
})
|
|
259
|
-
.prefault({}),
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
export const StarlightConfigSchema = z
|
|
263
|
-
.strictObject({ ...UserConfigSchema.shape })
|
|
264
|
-
.transform((config) => ({
|
|
265
|
-
...config,
|
|
266
|
-
// Pagefind only defaults to true if prerender is also true.
|
|
267
|
-
pagefind:
|
|
268
|
-
typeof config.pagefind === 'undefined'
|
|
269
|
-
? config.prerender && PagefindConfigDefaults()
|
|
270
|
-
: config.pagefind,
|
|
271
|
-
}))
|
|
272
|
-
.refine((config) => !(!config.prerender && config.pagefind), {
|
|
273
|
-
error: 'Pagefind search is not supported with prerendering disabled.',
|
|
274
|
-
})
|
|
275
|
-
.transform(({ title, locales, defaultLocale, ...config }, ctx) => {
|
|
276
|
-
const configuredLocales = Object.keys(locales ?? {});
|
|
277
|
-
|
|
278
|
-
// This is a multilingual site (more than one locale configured) or a monolingual site with
|
|
279
|
-
// only one locale configured (not a root locale).
|
|
280
|
-
// Monolingual sites with only one non-root locale needs their configuration to be defined in
|
|
281
|
-
// `config.locales` so that slugs can be correctly generated by taking into consideration the
|
|
282
|
-
// base path at which a language is served which is the key of the `config.locales` object.
|
|
283
|
-
if (
|
|
284
|
-
locales !== undefined &&
|
|
285
|
-
(configuredLocales.length > 1 ||
|
|
286
|
-
(configuredLocales.length === 1 && locales.root === undefined))
|
|
287
|
-
) {
|
|
288
|
-
// Make sure we can find the default locale and if not, help the user set it.
|
|
289
|
-
// We treat the root locale as the default if present and no explicit default is set.
|
|
290
|
-
const defaultLocaleConfig = locales[defaultLocale || 'root'];
|
|
291
|
-
|
|
292
|
-
if (!defaultLocaleConfig) {
|
|
293
|
-
const availableLocales = configuredLocales.map((l) => `"${l}"`).join(', ');
|
|
294
|
-
ctx.issues.push({
|
|
295
|
-
code: 'custom',
|
|
296
|
-
message:
|
|
297
|
-
'Could not determine the default locale. ' +
|
|
298
|
-
'Please make sure `defaultLocale` in your Starlight config is one of ' +
|
|
299
|
-
availableLocales,
|
|
300
|
-
input: locales,
|
|
301
|
-
});
|
|
302
|
-
return z.NEVER;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// Transform the title
|
|
306
|
-
const TitleSchema = TitleTransformConfigSchema(defaultLocaleConfig.lang as string);
|
|
307
|
-
const parsedTitle = TitleSchema.parse(title);
|
|
308
|
-
|
|
309
|
-
return {
|
|
310
|
-
...config,
|
|
311
|
-
title: parsedTitle,
|
|
312
|
-
/** Flag indicating if this site has multiple locales set up. */
|
|
313
|
-
isMultilingual: configuredLocales.length > 1,
|
|
314
|
-
/** Flag indicating if the Starlight built-in default locale is used. */
|
|
315
|
-
isUsingBuiltInDefaultLocale: false,
|
|
316
|
-
/** Full locale object for this site’s default language. */
|
|
317
|
-
defaultLocale: { ...defaultLocaleConfig, locale: defaultLocale },
|
|
318
|
-
locales,
|
|
319
|
-
} as const;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// This is a monolingual site with no locales configured or only a root locale, so things are
|
|
323
|
-
// pretty simple.
|
|
324
|
-
/** Full locale object for this site’s default language. */
|
|
325
|
-
const defaultLocaleConfig = {
|
|
326
|
-
label: BuiltInDefaultLocale.label,
|
|
327
|
-
lang: BuiltInDefaultLocale.lang,
|
|
328
|
-
dir: BuiltInDefaultLocale.dir,
|
|
329
|
-
locale: undefined,
|
|
330
|
-
...locales?.root,
|
|
331
|
-
};
|
|
332
|
-
/** Transform the title */
|
|
333
|
-
const TitleSchema = TitleTransformConfigSchema(defaultLocaleConfig.lang);
|
|
334
|
-
const parsedTitle = TitleSchema.parse(title);
|
|
335
|
-
return {
|
|
336
|
-
...config,
|
|
337
|
-
title: parsedTitle,
|
|
338
|
-
/** Flag indicating if this site has multiple locales set up. */
|
|
339
|
-
isMultilingual: false,
|
|
340
|
-
/** Flag indicating if the Starlight built-in default locale is used. */
|
|
341
|
-
isUsingBuiltInDefaultLocale: locales?.root === undefined,
|
|
342
|
-
defaultLocale: defaultLocaleConfig,
|
|
343
|
-
locales: undefined,
|
|
344
|
-
} as const;
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
export type StarlightConfig = z.infer<typeof StarlightConfigSchema>;
|
|
348
|
-
export type StarlightUserConfig = z.input<typeof StarlightConfigSchema>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import config from 'virtual:starlight/user-config';
|
|
2
|
-
import { logos } from 'virtual:starlight/user-images';
|
|
3
|
-
|
|
4
|
-
/** Check user-imported logo images have resolved correctly. */
|
|
5
|
-
export function validateLogoImports(): void {
|
|
6
|
-
if (config.logo) {
|
|
7
|
-
let err: string | undefined;
|
|
8
|
-
if ('src' in config.logo) {
|
|
9
|
-
if (!logos.dark || !logos.light) {
|
|
10
|
-
err = `Could not resolve logo import for "${config.logo.src}" (logo.src)`;
|
|
11
|
-
}
|
|
12
|
-
} else {
|
|
13
|
-
if (!logos.dark) {
|
|
14
|
-
err = `Could not resolve logo import for "${config.logo.dark}" (logo.dark)`;
|
|
15
|
-
} else if (!logos.light) {
|
|
16
|
-
err = `Could not resolve logo import for "${config.logo.light}" (logo.light)`;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (err) throw new Error(err);
|
|
20
|
-
}
|
|
21
|
-
}
|
package/utils/zodDeepMerge.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import type { z } from 'astro/zod';
|
|
2
|
-
|
|
3
|
-
/** Type-level equivalent of {@link mergeWithDefaultSchema}. */
|
|
4
|
-
export type DeepMergedSchema<Default extends z.core.$ZodType, User extends z.core.$ZodType> =
|
|
5
|
-
User extends z.ZodOptional<infer WrappedSchema extends z.core.$ZodType>
|
|
6
|
-
? z.ZodOptional<DeepMergedSchema<UnwrappedSchema<Default>, WrappedSchema>>
|
|
7
|
-
: User extends z.ZodNullable<infer WrappedSchema extends z.core.$ZodType>
|
|
8
|
-
? z.ZodNullable<DeepMergedSchema<UnwrappedSchema<Default>, WrappedSchema>>
|
|
9
|
-
: User extends z.ZodDefault<infer WrappedSchema extends z.core.$ZodType>
|
|
10
|
-
? z.ZodDefault<DeepMergedSchema<UnwrappedSchema<Default>, WrappedSchema>>
|
|
11
|
-
: User extends z.ZodPrefault<infer WrappedSchema extends z.core.$ZodType>
|
|
12
|
-
? z.ZodPrefault<DeepMergedSchema<UnwrappedSchema<Default>, WrappedSchema>>
|
|
13
|
-
: User extends z.ZodUnion<infer Users extends readonly z.core.$ZodType[]>
|
|
14
|
-
? z.ZodUnion<DeepMergedUnionMembers<UnwrappedSchema<Default>, Users>>
|
|
15
|
-
: UnwrappedSchema<Default> extends z.ZodObject<infer DefaultShape>
|
|
16
|
-
? User extends z.ZodObject<infer UserShape, infer UserConfig>
|
|
17
|
-
? z.ZodObject<DeepMergedShape<DefaultShape, UserShape>, UserConfig>
|
|
18
|
-
: User
|
|
19
|
-
: UnwrappedSchema<Default> extends z.ZodArray<
|
|
20
|
-
infer DefaultItemSchema extends z.core.$ZodType
|
|
21
|
-
>
|
|
22
|
-
? User extends z.ZodArray<infer UserItemSchema extends z.core.$ZodType>
|
|
23
|
-
? z.ZodArray<DeepMergedSchema<DefaultItemSchema, UserItemSchema>>
|
|
24
|
-
: User
|
|
25
|
-
: User;
|
|
26
|
-
|
|
27
|
-
/** Type-level equivalent of {@link unwrapSchema}. */
|
|
28
|
-
type UnwrappedSchema<T extends z.core.$ZodType> =
|
|
29
|
-
T extends z.ZodOptional<infer Wrapped extends z.core.$ZodType>
|
|
30
|
-
? UnwrappedSchema<Wrapped>
|
|
31
|
-
: T extends z.ZodNullable<infer Wrapped extends z.core.$ZodType>
|
|
32
|
-
? UnwrappedSchema<Wrapped>
|
|
33
|
-
: T extends z.ZodDefault<infer Wrapped extends z.core.$ZodType>
|
|
34
|
-
? UnwrappedSchema<Wrapped>
|
|
35
|
-
: T extends z.ZodPrefault<infer Wrapped extends z.core.$ZodType>
|
|
36
|
-
? UnwrappedSchema<Wrapped>
|
|
37
|
-
: T;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Merged Zod object shapes, preserving default properties, adding user-only properties, and
|
|
41
|
-
* recursively merging shared properties.
|
|
42
|
-
*/
|
|
43
|
-
type DeepMergedShape<Default extends z.ZodRawShape, User extends z.ZodRawShape> = {
|
|
44
|
-
[Key in keyof Default | keyof User]: Key extends keyof User
|
|
45
|
-
? Key extends keyof Default
|
|
46
|
-
? DeepMergedSchema<Default[Key], User[Key]>
|
|
47
|
-
: User[Key]
|
|
48
|
-
: Key extends keyof Default
|
|
49
|
-
? Default[Key]
|
|
50
|
-
: never;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/** Merged union schemas where each union member is deep-merged with the default schema. */
|
|
54
|
-
type DeepMergedUnionMembers<
|
|
55
|
-
Default extends z.core.$ZodType,
|
|
56
|
-
Users extends readonly z.core.$ZodType[],
|
|
57
|
-
> = {
|
|
58
|
-
[Key in keyof Users]: Users[Key] extends z.core.$ZodType
|
|
59
|
-
? DeepMergedSchema<Default, Users[Key]>
|
|
60
|
-
: Users[Key];
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export function deepMergeSchemas(defaultSchema: z.ZodType, userSchema: z.ZodType): z.ZodType {
|
|
64
|
-
const unwrappedDefaultSchema = unwrapSchema(defaultSchema);
|
|
65
|
-
|
|
66
|
-
if (isWrappedSchema(userSchema)) {
|
|
67
|
-
return userSchema.clone({
|
|
68
|
-
...userSchema._zod.def,
|
|
69
|
-
innerType: deepMergeSchemas(unwrappedDefaultSchema, userSchema._zod.def.innerType),
|
|
70
|
-
} as Parameters<typeof userSchema.clone>[0]);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (isZodUnion(userSchema)) {
|
|
74
|
-
return userSchema.clone({
|
|
75
|
-
...userSchema._zod.def,
|
|
76
|
-
options: userSchema.options.map((schema) => deepMergeSchemas(unwrappedDefaultSchema, schema)),
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (isZodObject(unwrappedDefaultSchema) && isZodObject(userSchema)) {
|
|
81
|
-
const shape: z.core.$ZodLooseShape = { ...unwrappedDefaultSchema.shape };
|
|
82
|
-
|
|
83
|
-
for (const key of Object.keys(userSchema.shape)) {
|
|
84
|
-
const userFieldSchema = userSchema.shape[key] as z.ZodType;
|
|
85
|
-
const defaultFieldSchema = shape[key] as z.ZodType | undefined;
|
|
86
|
-
|
|
87
|
-
shape[key] = defaultFieldSchema
|
|
88
|
-
? deepMergeSchemas(defaultFieldSchema, userFieldSchema)
|
|
89
|
-
: userFieldSchema;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return userSchema.safeExtend(shape);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (isZodArray(unwrappedDefaultSchema) && isZodArray(userSchema)) {
|
|
96
|
-
return userSchema.clone({
|
|
97
|
-
...userSchema._zod.def,
|
|
98
|
-
element: deepMergeSchemas(unwrappedDefaultSchema.element, userSchema.element),
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return userSchema;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Unwrap any Zod schema that wraps other schemas, such as `z.optional()`, `z.nullable()`,
|
|
107
|
-
* `z.default()`, etc. until we reach the innermost schema.
|
|
108
|
-
*/
|
|
109
|
-
function unwrapSchema(schema: z.ZodType): z.ZodType {
|
|
110
|
-
let current = schema;
|
|
111
|
-
|
|
112
|
-
while (isWrappedSchema(current)) {
|
|
113
|
-
current = current._zod.def.innerType;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return current;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Check if a schema wraps another schema which can happen when using modifiers like
|
|
121
|
-
* `z.optional()`, `z.nullable()`, `z.default()`, etc.
|
|
122
|
-
*/
|
|
123
|
-
function isWrappedSchema(schema: z.ZodType): schema is z.ZodType & {
|
|
124
|
-
_zod: { def: z.ZodType['_zod']['def'] & { innerType: z.ZodType } };
|
|
125
|
-
} {
|
|
126
|
-
return (
|
|
127
|
-
schema._zod.def.type === 'optional' ||
|
|
128
|
-
schema._zod.def.type === 'nullable' ||
|
|
129
|
-
schema._zod.def.type === 'default' ||
|
|
130
|
-
schema._zod.def.type === 'prefault'
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function isZodObject(schema: z.ZodType): schema is z.ZodObject<z.ZodRawShape> {
|
|
135
|
-
return schema._zod.def.type === 'object';
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function isZodArray(schema: z.ZodType): schema is z.ZodArray<z.ZodType> {
|
|
139
|
-
return schema._zod.def.type === 'array';
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function isZodUnion(schema: z.ZodType): schema is z.ZodUnion<readonly z.ZodType[]> {
|
|
143
|
-
return schema._zod.def.type === 'union';
|
|
144
|
-
}
|