@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
package/utils/plugins.ts
DELETED
|
@@ -1,498 +0,0 @@
|
|
|
1
|
-
import type { AstroIntegration, HookParameters as AstroHookParameters } from 'astro';
|
|
2
|
-
import { AstroError } from 'astro/errors';
|
|
3
|
-
import { z } from 'astro/zod';
|
|
4
|
-
import { parseWithFriendlyErrors } from '../utils/error-map';
|
|
5
|
-
import {
|
|
6
|
-
StarlightConfigSchema,
|
|
7
|
-
type StarlightConfig,
|
|
8
|
-
type StarlightUserConfig,
|
|
9
|
-
} from '../utils/user-config';
|
|
10
|
-
import type { UserI18nSchema } from './translations';
|
|
11
|
-
import { createTranslationSystemFromFs } from './translations-fs';
|
|
12
|
-
import { absolutePathToLang as getAbsolutePathFromLang } from '../integrations/shared/absolutePathToLang';
|
|
13
|
-
import { getCollectionPosixPath } from './collection-fs';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Runs Starlight plugins in the order that they are configured after validating the user-provided
|
|
17
|
-
* configuration and returns the final validated user config that may have been updated by the
|
|
18
|
-
* plugins and a list of any integrations added by the plugins.
|
|
19
|
-
*/
|
|
20
|
-
export async function runPlugins(
|
|
21
|
-
starlightUserConfig: StarlightUserConfig,
|
|
22
|
-
pluginsUserConfig: StarlightPluginsUserConfig,
|
|
23
|
-
context: StarlightPluginContext
|
|
24
|
-
) {
|
|
25
|
-
// Validate the user-provided configuration.
|
|
26
|
-
let userConfig = starlightUserConfig;
|
|
27
|
-
|
|
28
|
-
let starlightConfig = parseWithFriendlyErrors(
|
|
29
|
-
StarlightConfigSchema,
|
|
30
|
-
userConfig,
|
|
31
|
-
'Invalid config passed to starlight integration'
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
// Validate the user-provided plugins configuration.
|
|
35
|
-
const pluginsConfig = parseWithFriendlyErrors(
|
|
36
|
-
starlightPluginsConfigSchema,
|
|
37
|
-
pluginsUserConfig,
|
|
38
|
-
'Invalid plugins config passed to starlight integration'
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
// A list of translations injected by the various plugins keyed by locale.
|
|
42
|
-
const pluginTranslations: PluginTranslations = {};
|
|
43
|
-
// A list of route middleware added by the various plugins.
|
|
44
|
-
const routeMiddlewareConfigs: Array<z.output<typeof routeMiddlewareConfigSchema>> = [];
|
|
45
|
-
|
|
46
|
-
for (const {
|
|
47
|
-
hooks: { 'i18n:setup': i18nSetup },
|
|
48
|
-
} of pluginsConfig) {
|
|
49
|
-
if (i18nSetup) {
|
|
50
|
-
await i18nSetup({
|
|
51
|
-
injectTranslations(translations) {
|
|
52
|
-
// Merge the translations injected by the plugin.
|
|
53
|
-
for (const [locale, localeTranslations] of Object.entries(translations)) {
|
|
54
|
-
pluginTranslations[locale] ??= {};
|
|
55
|
-
Object.assign(pluginTranslations[locale], localeTranslations);
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const useTranslations = await createTranslationSystemFromFs(
|
|
63
|
-
starlightConfig,
|
|
64
|
-
context.config,
|
|
65
|
-
pluginTranslations
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
function absolutePathToLang(path: string) {
|
|
69
|
-
return getAbsolutePathFromLang(path, {
|
|
70
|
-
docsPath: getCollectionPosixPath('docs', context.config.srcDir),
|
|
71
|
-
starlightConfig,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// A list of Astro integrations added by the various plugins.
|
|
76
|
-
const integrations: AstroIntegration[] = [];
|
|
77
|
-
|
|
78
|
-
for (const {
|
|
79
|
-
name,
|
|
80
|
-
hooks: { 'config:setup': configSetup, setup: deprecatedSetup },
|
|
81
|
-
} of pluginsConfig) {
|
|
82
|
-
// A refinement in the schema ensures that at least one of the two hooks is defined.
|
|
83
|
-
const setup = (configSetup ?? deprecatedSetup)!;
|
|
84
|
-
|
|
85
|
-
await setup({
|
|
86
|
-
config: pluginsUserConfig ? { ...userConfig, plugins: pluginsUserConfig } : userConfig,
|
|
87
|
-
updateConfig(newConfig) {
|
|
88
|
-
// Ensure that plugins do not update the `plugins` config key.
|
|
89
|
-
if ('plugins' in newConfig) {
|
|
90
|
-
throw new AstroError(
|
|
91
|
-
`The \`${name}\` plugin tried to update the \`plugins\` config key which is not supported.`
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
if ('routeMiddleware' in newConfig) {
|
|
95
|
-
throw new AstroError(
|
|
96
|
-
`The \`${name}\` plugin tried to update the \`routeMiddleware\` config key which is not supported.`,
|
|
97
|
-
'Use the `addRouteMiddleware()` utility instead.\n' +
|
|
98
|
-
'See https://starlight.astro.build/reference/plugins/#addroutemiddleware for more details.'
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// If the plugin is updating the user config, re-validate it.
|
|
103
|
-
const mergedUserConfig = { ...userConfig, ...newConfig };
|
|
104
|
-
const mergedConfig = parseWithFriendlyErrors(
|
|
105
|
-
StarlightConfigSchema,
|
|
106
|
-
mergedUserConfig,
|
|
107
|
-
`Invalid config update provided by the '${name}' plugin`
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
// If the updated config is valid, keep track of both the user config and parsed config.
|
|
111
|
-
userConfig = mergedUserConfig;
|
|
112
|
-
starlightConfig = mergedConfig;
|
|
113
|
-
},
|
|
114
|
-
addIntegration(integration) {
|
|
115
|
-
// Collect any Astro integrations added by the plugin.
|
|
116
|
-
integrations.push(integration);
|
|
117
|
-
},
|
|
118
|
-
addRouteMiddleware(middlewareConfig) {
|
|
119
|
-
routeMiddlewareConfigs.push(middlewareConfig);
|
|
120
|
-
},
|
|
121
|
-
astroConfig: {
|
|
122
|
-
...context.config,
|
|
123
|
-
integrations: [...context.config.integrations, ...integrations],
|
|
124
|
-
},
|
|
125
|
-
command: context.command,
|
|
126
|
-
isRestart: context.isRestart,
|
|
127
|
-
logger: context.logger.fork(name),
|
|
128
|
-
useTranslations,
|
|
129
|
-
absolutePathToLang,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
applyPluginMiddleware(routeMiddlewareConfigs, starlightConfig);
|
|
134
|
-
|
|
135
|
-
return { integrations, starlightConfig, pluginTranslations, useTranslations, absolutePathToLang };
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/** Updates `routeMiddleware` in the Starlight config to add plugin middlewares in the correct order. */
|
|
139
|
-
function applyPluginMiddleware(
|
|
140
|
-
routeMiddlewareConfigs: { entrypoint: string; order: 'default' | 'pre' | 'post' }[],
|
|
141
|
-
starlightConfig: StarlightConfig
|
|
142
|
-
) {
|
|
143
|
-
const middlewareBuckets = routeMiddlewareConfigs.reduce<
|
|
144
|
-
Record<'pre' | 'default' | 'post', string[]>
|
|
145
|
-
>(
|
|
146
|
-
(buckets, { entrypoint, order = 'default' }) => {
|
|
147
|
-
buckets[order].push(entrypoint);
|
|
148
|
-
return buckets;
|
|
149
|
-
},
|
|
150
|
-
{ pre: [], default: [], post: [] }
|
|
151
|
-
);
|
|
152
|
-
starlightConfig.routeMiddleware.unshift(...middlewareBuckets.pre);
|
|
153
|
-
starlightConfig.routeMiddleware.push(...middlewareBuckets.default, ...middlewareBuckets.post);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export function injectPluginTranslationsTypes(
|
|
157
|
-
translations: PluginTranslations,
|
|
158
|
-
injectTypes: AstroHookParameters<'astro:config:done'>['injectTypes']
|
|
159
|
-
) {
|
|
160
|
-
const allKeys = new Set<string>();
|
|
161
|
-
|
|
162
|
-
for (const localeTranslations of Object.values(translations)) {
|
|
163
|
-
for (const key of Object.keys(localeTranslations)) {
|
|
164
|
-
allKeys.add(key);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// If there are no translations to inject, we don't need to generate any types or cleanup
|
|
169
|
-
// previous ones as they will not be referenced anymore.
|
|
170
|
-
if (allKeys.size === 0) return;
|
|
171
|
-
|
|
172
|
-
injectTypes({
|
|
173
|
-
filename: 'i18n-plugins.d.ts',
|
|
174
|
-
content: `declare namespace StarlightApp {
|
|
175
|
-
type PluginUIStringKeys = {
|
|
176
|
-
${[...allKeys].map((key) => `'${key}': string;`).join('\n\t\t')}
|
|
177
|
-
};
|
|
178
|
-
interface I18n extends PluginUIStringKeys {}
|
|
179
|
-
}`,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// https://github.com/withastro/astro/blob/910eb00fe0b70ca80bd09520ae100e8c78b675b5/packages/astro/src/core/config/schema.ts#L113
|
|
184
|
-
const astroIntegrationSchema = z.object({
|
|
185
|
-
name: z.string(),
|
|
186
|
-
hooks: z.looseObject({}).default({}),
|
|
187
|
-
}) as z.ZodType<AstroIntegration, AstroIntegration>;
|
|
188
|
-
|
|
189
|
-
const routeMiddlewareConfigSchema = z.object({
|
|
190
|
-
entrypoint: z.string(),
|
|
191
|
-
order: z.enum(['pre', 'post', 'default']).default('default'),
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
const baseStarlightPluginSchema = z.object({
|
|
195
|
-
/** Name of the Starlight plugin. */
|
|
196
|
-
name: z.string(),
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
type StarlightConfigUpdate = Partial<Omit<StarlightUserConfig, 'routeMiddleware'>>;
|
|
200
|
-
type StarlightI18nTFactory = Awaited<ReturnType<typeof createTranslationSystemFromFs>>;
|
|
201
|
-
|
|
202
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion --
|
|
203
|
-
The configSetupHookSchema casts `z.any()` to provide types but this rule can’t understand that. */
|
|
204
|
-
const configSetupHookSchema = z
|
|
205
|
-
.function({
|
|
206
|
-
input: [
|
|
207
|
-
z.object({
|
|
208
|
-
/**
|
|
209
|
-
* A read-only copy of the user-supplied Starlight configuration.
|
|
210
|
-
*
|
|
211
|
-
* Note that this configuration may have been updated by other plugins configured
|
|
212
|
-
* before this one.
|
|
213
|
-
*/
|
|
214
|
-
config: z.any() as z.ZodType<
|
|
215
|
-
// The configuration passed to plugins should contains the list of plugins.
|
|
216
|
-
StarlightUserConfigWithPlugins,
|
|
217
|
-
StarlightUserConfigWithPlugins
|
|
218
|
-
>,
|
|
219
|
-
/**
|
|
220
|
-
* A callback function to update the user-supplied Starlight configuration.
|
|
221
|
-
*
|
|
222
|
-
* You only need to provide the configuration values that you want to update but no deep
|
|
223
|
-
* merge is performed.
|
|
224
|
-
*
|
|
225
|
-
* @example
|
|
226
|
-
* {
|
|
227
|
-
* name: 'My Starlight Plugin',
|
|
228
|
-
* hooks: {
|
|
229
|
-
* 'config:setup'({ updateConfig }) {
|
|
230
|
-
* updateConfig({
|
|
231
|
-
* description: 'Custom description',
|
|
232
|
-
* });
|
|
233
|
-
* }
|
|
234
|
-
* }
|
|
235
|
-
* }
|
|
236
|
-
*/
|
|
237
|
-
updateConfig: z.function({
|
|
238
|
-
input: [
|
|
239
|
-
z.record(z.string(), z.any()) as z.ZodType<
|
|
240
|
-
StarlightConfigUpdate,
|
|
241
|
-
StarlightConfigUpdate
|
|
242
|
-
>,
|
|
243
|
-
],
|
|
244
|
-
output: z.void(),
|
|
245
|
-
}),
|
|
246
|
-
/**
|
|
247
|
-
* A callback function to add an Astro integration required by this plugin.
|
|
248
|
-
*
|
|
249
|
-
* @see https://docs.astro.build/en/reference/integrations-reference/
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* {
|
|
253
|
-
* name: 'My Starlight Plugin',
|
|
254
|
-
* hooks: {
|
|
255
|
-
* 'config:setup'({ addIntegration }) {
|
|
256
|
-
* addIntegration({
|
|
257
|
-
* name: 'My Plugin Astro Integration',
|
|
258
|
-
* hooks: {
|
|
259
|
-
* 'astro:config:setup': () => {
|
|
260
|
-
* // …
|
|
261
|
-
* },
|
|
262
|
-
* },
|
|
263
|
-
* });
|
|
264
|
-
* }
|
|
265
|
-
* }
|
|
266
|
-
* }
|
|
267
|
-
*/
|
|
268
|
-
addIntegration: z.function({
|
|
269
|
-
input: [astroIntegrationSchema],
|
|
270
|
-
output: z.void(),
|
|
271
|
-
}),
|
|
272
|
-
/**
|
|
273
|
-
* A callback function to register additional route middleware handlers.
|
|
274
|
-
*
|
|
275
|
-
* If the order of execution is important, a plugin can use the `order` option to enforce
|
|
276
|
-
* running first or last.
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* {
|
|
280
|
-
* name: 'My Starlight Plugin',
|
|
281
|
-
* hooks: {
|
|
282
|
-
* setup({ addRouteMiddleware }) {
|
|
283
|
-
* addRouteMiddleware({ entrypoint: '@me/my-plugin/route-middleware' });
|
|
284
|
-
* },
|
|
285
|
-
* },
|
|
286
|
-
* }
|
|
287
|
-
*/
|
|
288
|
-
addRouteMiddleware: z.function({
|
|
289
|
-
input: [routeMiddlewareConfigSchema],
|
|
290
|
-
output: z.void(),
|
|
291
|
-
}),
|
|
292
|
-
/**
|
|
293
|
-
* A read-only copy of the user-supplied Astro configuration.
|
|
294
|
-
*
|
|
295
|
-
* Note that this configuration is resolved before any other integrations have run.
|
|
296
|
-
*
|
|
297
|
-
* @see https://docs.astro.build/en/reference/integrations-reference/#config-option
|
|
298
|
-
*/
|
|
299
|
-
astroConfig: z.any() as z.ZodType<
|
|
300
|
-
StarlightPluginContext['config'],
|
|
301
|
-
StarlightPluginContext['config']
|
|
302
|
-
>,
|
|
303
|
-
/**
|
|
304
|
-
* The command used to run Starlight.
|
|
305
|
-
*
|
|
306
|
-
* @see https://docs.astro.build/en/reference/integrations-reference/#command-option
|
|
307
|
-
*/
|
|
308
|
-
command: z.any() as z.ZodType<
|
|
309
|
-
StarlightPluginContext['command'],
|
|
310
|
-
StarlightPluginContext['command']
|
|
311
|
-
>,
|
|
312
|
-
/**
|
|
313
|
-
* `false` when the dev server starts, `true` when a reload is triggered.
|
|
314
|
-
*
|
|
315
|
-
* @see https://docs.astro.build/en/reference/integrations-reference/#isrestart-option
|
|
316
|
-
*/
|
|
317
|
-
isRestart: z.any() as z.ZodType<
|
|
318
|
-
StarlightPluginContext['isRestart'],
|
|
319
|
-
StarlightPluginContext['isRestart']
|
|
320
|
-
>,
|
|
321
|
-
/**
|
|
322
|
-
* An instance of the Astro integration logger with all logged messages prefixed with the
|
|
323
|
-
* plugin name.
|
|
324
|
-
*
|
|
325
|
-
* @see https://docs.astro.build/en/reference/integrations-reference/#astrointegrationlogger
|
|
326
|
-
*/
|
|
327
|
-
logger: z.any() as z.ZodType<
|
|
328
|
-
StarlightPluginContext['logger'],
|
|
329
|
-
StarlightPluginContext['logger']
|
|
330
|
-
>,
|
|
331
|
-
/**
|
|
332
|
-
* A callback function to generate a utility function to access UI strings for a given
|
|
333
|
-
* language.
|
|
334
|
-
*
|
|
335
|
-
* @see https://starlight.astro.build/guides/i18n/#using-ui-translations
|
|
336
|
-
*
|
|
337
|
-
* @example
|
|
338
|
-
* {
|
|
339
|
-
* name: 'My Starlight Plugin',
|
|
340
|
-
* hooks: {
|
|
341
|
-
* 'config:setup'({ useTranslations, logger }) {
|
|
342
|
-
* const t = useTranslations('en');
|
|
343
|
-
* logger.info(t('builtWithStarlight.label'));
|
|
344
|
-
* // ^ Logs 'Built with Starlight' to the console.
|
|
345
|
-
* }
|
|
346
|
-
* }
|
|
347
|
-
* }
|
|
348
|
-
*/
|
|
349
|
-
useTranslations: z.any() as z.ZodType<StarlightI18nTFactory, StarlightI18nTFactory>,
|
|
350
|
-
/**
|
|
351
|
-
* A callback function to get the language for a given absolute file path. The returned
|
|
352
|
-
* language can be used with the `useTranslations` helper to get UI strings for that
|
|
353
|
-
* language.
|
|
354
|
-
*
|
|
355
|
-
* This can be particularly useful in remark or rehype plugins to get the language for
|
|
356
|
-
* the current file being processed and use it to get the appropriate UI strings for that
|
|
357
|
-
* language.
|
|
358
|
-
*
|
|
359
|
-
* @example
|
|
360
|
-
* {
|
|
361
|
-
* name: 'My Starlight Plugin',
|
|
362
|
-
* hooks: {
|
|
363
|
-
* 'config:setup'({ absolutePathToLang, useTranslations, logger }) {
|
|
364
|
-
* const lang = absolutePathToLang('/absolute/path/to/project/src/content/docs/fr/index.mdx');
|
|
365
|
-
* const t = useTranslations(lang);
|
|
366
|
-
* logger.info(t('aside.tip'));
|
|
367
|
-
* // ^ Logs 'Astuce' to the console.
|
|
368
|
-
* }
|
|
369
|
-
* }
|
|
370
|
-
* }
|
|
371
|
-
*/
|
|
372
|
-
absolutePathToLang: z.function({
|
|
373
|
-
input: [z.string()],
|
|
374
|
-
output: z.string(),
|
|
375
|
-
}),
|
|
376
|
-
}),
|
|
377
|
-
],
|
|
378
|
-
// We still rely on the deprecated `z.promise()` to define the function output as the only
|
|
379
|
-
// non-deprecated way to define an async function is to use `.implementAsync()` but we don't
|
|
380
|
-
// want to implement the function using Zod.
|
|
381
|
-
output: z.promise(z.void()),
|
|
382
|
-
})
|
|
383
|
-
.optional();
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* A plugin `config` and `updateConfig` argument are purposely not validated using the Starlight
|
|
387
|
-
* user config schema but properly typed for user convenience because we do not want to run any of
|
|
388
|
-
* the Zod `transform`s used in the user config schema when running plugins.
|
|
389
|
-
*/
|
|
390
|
-
const starlightPluginSchema = z
|
|
391
|
-
.object({
|
|
392
|
-
...baseStarlightPluginSchema.shape,
|
|
393
|
-
/** The different hooks available to the plugin. */
|
|
394
|
-
hooks: z.object({
|
|
395
|
-
/**
|
|
396
|
-
* Plugin internationalization setup function allowing to inject translations strings for the
|
|
397
|
-
* plugin in various locales. These translations will be available in the `config:setup` hook
|
|
398
|
-
* and plugin UI.
|
|
399
|
-
*/
|
|
400
|
-
'i18n:setup': z
|
|
401
|
-
.function({
|
|
402
|
-
input: [
|
|
403
|
-
z.object({
|
|
404
|
-
/**
|
|
405
|
-
* A callback function to add or update translations strings.
|
|
406
|
-
*
|
|
407
|
-
* @see https://starlight.astro.build/guides/i18n/#extend-translation-schema
|
|
408
|
-
*
|
|
409
|
-
* @example
|
|
410
|
-
* {
|
|
411
|
-
* name: 'My Starlight Plugin',
|
|
412
|
-
* hooks: {
|
|
413
|
-
* 'i18n:setup'({ injectTranslations }) {
|
|
414
|
-
* injectTranslations({
|
|
415
|
-
* en: {
|
|
416
|
-
* 'myPlugin.doThing': 'Do the thing',
|
|
417
|
-
* },
|
|
418
|
-
* fr: {
|
|
419
|
-
* 'myPlugin.doThing': 'Faire le truc',
|
|
420
|
-
* },
|
|
421
|
-
* });
|
|
422
|
-
* }
|
|
423
|
-
* }
|
|
424
|
-
* }
|
|
425
|
-
*/
|
|
426
|
-
injectTranslations: z.function({
|
|
427
|
-
input: [z.record(z.string(), z.record(z.string(), z.string()))],
|
|
428
|
-
output: z.void(),
|
|
429
|
-
}),
|
|
430
|
-
}),
|
|
431
|
-
],
|
|
432
|
-
// We still rely on the deprecated `z.promise()` to define the function output as the
|
|
433
|
-
// only non-deprecated way to define an async function is to use `.implementAsync()` but
|
|
434
|
-
// we don't want to implement the function using Zod.
|
|
435
|
-
output: z.promise(z.void()),
|
|
436
|
-
})
|
|
437
|
-
.optional(),
|
|
438
|
-
/**
|
|
439
|
-
* Plugin configuration setup function called with an object containing various values that
|
|
440
|
-
* can be used by the plugin to interact with Starlight.
|
|
441
|
-
*/
|
|
442
|
-
'config:setup': configSetupHookSchema,
|
|
443
|
-
/**
|
|
444
|
-
* @deprecated Use the `config:setup` hook instead as `setup` will be removed in a future
|
|
445
|
-
* version.
|
|
446
|
-
*/
|
|
447
|
-
setup: configSetupHookSchema,
|
|
448
|
-
}),
|
|
449
|
-
})
|
|
450
|
-
.superRefine((plugin, ctx) => {
|
|
451
|
-
if (!plugin.hooks['config:setup'] && !plugin.hooks.setup) {
|
|
452
|
-
ctx.issues.push({
|
|
453
|
-
code: 'custom',
|
|
454
|
-
message: 'A plugin must define at least a `config:setup` hook.',
|
|
455
|
-
input: plugin,
|
|
456
|
-
});
|
|
457
|
-
} else if (plugin.hooks['config:setup'] && plugin.hooks.setup) {
|
|
458
|
-
ctx.issues.push({
|
|
459
|
-
code: 'custom',
|
|
460
|
-
message:
|
|
461
|
-
'A plugin cannot define both a `config:setup` and `setup` hook. ' +
|
|
462
|
-
'As `setup` is deprecated and will be removed in a future version, ' +
|
|
463
|
-
'consider using `config:setup` instead.',
|
|
464
|
-
input: plugin,
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
const starlightPluginsConfigSchema = z.array(starlightPluginSchema).default([]);
|
|
470
|
-
|
|
471
|
-
type StarlightPluginsUserConfig = z.input<typeof starlightPluginsConfigSchema>;
|
|
472
|
-
|
|
473
|
-
export type StarlightPlugin = z.input<typeof starlightPluginSchema>;
|
|
474
|
-
|
|
475
|
-
export type HookParameters<
|
|
476
|
-
Hook extends keyof StarlightPlugin['hooks'],
|
|
477
|
-
HookFn = StarlightPlugin['hooks'][Hook],
|
|
478
|
-
> = HookFn extends (...args: any[]) => unknown ? Parameters<HookFn>[0] : never;
|
|
479
|
-
|
|
480
|
-
export type StarlightUserConfigWithPlugins = StarlightUserConfig & {
|
|
481
|
-
/**
|
|
482
|
-
* A list of plugins to extend Starlight with.
|
|
483
|
-
*
|
|
484
|
-
* @example
|
|
485
|
-
* // Add Starlight Algolia plugin.
|
|
486
|
-
* starlight({
|
|
487
|
-
* plugins: [starlightAlgolia({ … })],
|
|
488
|
-
* })
|
|
489
|
-
*/
|
|
490
|
-
plugins?: StarlightPluginsUserConfig;
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
export type StarlightPluginContext = Pick<
|
|
494
|
-
AstroHookParameters<'astro:config:setup'>,
|
|
495
|
-
'command' | 'config' | 'isRestart' | 'logger'
|
|
496
|
-
>;
|
|
497
|
-
|
|
498
|
-
export type PluginTranslations = Record<string, UserI18nSchema & Record<string, string>>;
|
package/utils/routing/data.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import type { APIContext, MarkdownHeading } from 'astro';
|
|
2
|
-
import project from 'virtual:starlight/project-context';
|
|
3
|
-
import config from 'virtual:starlight/user-config';
|
|
4
|
-
import { generateToC } from '../generateToC';
|
|
5
|
-
import { getNewestCommitDate } from 'virtual:starlight/git-info';
|
|
6
|
-
import { getPrevNextLinks, getSidebar } from '../navigation';
|
|
7
|
-
import { ensureTrailingSlash } from '../path';
|
|
8
|
-
import { getRouteBySlugParam, normalizeCollectionEntry } from '../routing';
|
|
9
|
-
import type { Route, StarlightDocsEntry, StarlightRouteData } from './types';
|
|
10
|
-
import { formatPath } from '../format-path';
|
|
11
|
-
import { useTranslations } from '../translations';
|
|
12
|
-
import { BuiltInDefaultLocale } from '../i18n';
|
|
13
|
-
import { getEntry, type RenderResult } from 'astro:content';
|
|
14
|
-
import { getCollectionPathFromRoot } from '../collection';
|
|
15
|
-
import { getHead } from '../head';
|
|
16
|
-
|
|
17
|
-
export interface PageProps extends Route {
|
|
18
|
-
headings: MarkdownHeading[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type RouteDataContext = Pick<APIContext, 'generator' | 'site' | 'url'>;
|
|
22
|
-
|
|
23
|
-
export async function getRoute(context: APIContext): Promise<Route> {
|
|
24
|
-
return (
|
|
25
|
-
('slug' in context.params && getRouteBySlugParam(context.params.slug)) ||
|
|
26
|
-
(await get404Route(context.locals))
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function useRouteData(
|
|
31
|
-
context: APIContext,
|
|
32
|
-
route: Route,
|
|
33
|
-
{ Content, headings }: RenderResult
|
|
34
|
-
): StarlightRouteData {
|
|
35
|
-
const routeData = generateRouteData({ props: { ...route, headings }, context });
|
|
36
|
-
return { ...routeData, Content };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function generateRouteData({
|
|
40
|
-
props,
|
|
41
|
-
context,
|
|
42
|
-
}: {
|
|
43
|
-
props: PageProps;
|
|
44
|
-
context: RouteDataContext;
|
|
45
|
-
}): StarlightRouteData {
|
|
46
|
-
const { entry, locale, lang } = props;
|
|
47
|
-
const sidebar = getSidebar(context.url.pathname, locale);
|
|
48
|
-
const siteTitle = getSiteTitle(lang);
|
|
49
|
-
return {
|
|
50
|
-
...props,
|
|
51
|
-
siteTitle,
|
|
52
|
-
siteTitleHref: getSiteTitleHref(locale),
|
|
53
|
-
sidebar,
|
|
54
|
-
hasSidebar: entry.data.template !== 'splash',
|
|
55
|
-
pagination: getPrevNextLinks(sidebar, config.pagination, entry.data),
|
|
56
|
-
toc: getToC(props),
|
|
57
|
-
lastUpdated: getLastUpdated(props),
|
|
58
|
-
editUrl: getEditUrl(props),
|
|
59
|
-
head: getHead(props, context, siteTitle),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function getToC({ entry, lang, headings }: PageProps) {
|
|
64
|
-
const tocConfig =
|
|
65
|
-
entry.data.template === 'splash'
|
|
66
|
-
? false
|
|
67
|
-
: entry.data.tableOfContents !== undefined
|
|
68
|
-
? entry.data.tableOfContents
|
|
69
|
-
: config.tableOfContents;
|
|
70
|
-
if (!tocConfig) return;
|
|
71
|
-
const t = useTranslations(lang);
|
|
72
|
-
return {
|
|
73
|
-
...tocConfig,
|
|
74
|
-
items: generateToC(headings, { ...tocConfig, title: t('tableOfContents.overview') }),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function getLastUpdated({ entry }: PageProps): Date | undefined {
|
|
79
|
-
const { lastUpdated: frontmatterLastUpdated } = entry.data;
|
|
80
|
-
const { lastUpdated: configLastUpdated } = config;
|
|
81
|
-
|
|
82
|
-
if (frontmatterLastUpdated ?? configLastUpdated) {
|
|
83
|
-
try {
|
|
84
|
-
return frontmatterLastUpdated instanceof Date
|
|
85
|
-
? frontmatterLastUpdated
|
|
86
|
-
: getNewestCommitDate(entry.filePath);
|
|
87
|
-
} catch {
|
|
88
|
-
// If the git command fails, ignore the error.
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function getEditUrl({ entry }: PageProps): URL | undefined {
|
|
97
|
-
const { editUrl } = entry.data;
|
|
98
|
-
// If frontmatter value is false, editing is disabled for this page.
|
|
99
|
-
if (editUrl === false) return;
|
|
100
|
-
|
|
101
|
-
let url: string | undefined;
|
|
102
|
-
if (typeof editUrl === 'string') {
|
|
103
|
-
// If a URL was provided in frontmatter, use that.
|
|
104
|
-
url = editUrl;
|
|
105
|
-
} else if (config.editLink.baseUrl) {
|
|
106
|
-
// If a base URL was added in Starlight config, synthesize the edit URL from it.
|
|
107
|
-
url = ensureTrailingSlash(config.editLink.baseUrl) + entry.filePath;
|
|
108
|
-
}
|
|
109
|
-
return url ? new URL(url) : undefined;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Get the site title for a given language. **/
|
|
113
|
-
export function getSiteTitle(lang: string): string {
|
|
114
|
-
const defaultLang = config.defaultLocale.lang as string;
|
|
115
|
-
if (lang && config.title[lang]) {
|
|
116
|
-
return config.title[lang];
|
|
117
|
-
}
|
|
118
|
-
return config.title[defaultLang] as string;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function getSiteTitleHref(locale: string | undefined): string {
|
|
122
|
-
return formatPath(locale || '/');
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Generate a route object for Starlight’s 404 page. */
|
|
126
|
-
async function get404Route(locals: App.Locals): Promise<Route> {
|
|
127
|
-
const { lang = BuiltInDefaultLocale.lang, dir = BuiltInDefaultLocale.dir } =
|
|
128
|
-
config.defaultLocale || {};
|
|
129
|
-
let locale = config.defaultLocale?.locale;
|
|
130
|
-
if (locale === 'root') locale = undefined;
|
|
131
|
-
|
|
132
|
-
const entryMeta = { dir, lang, locale };
|
|
133
|
-
|
|
134
|
-
const fallbackEntry: StarlightDocsEntry = {
|
|
135
|
-
id: '404',
|
|
136
|
-
body: '',
|
|
137
|
-
collection: 'docs',
|
|
138
|
-
data: {
|
|
139
|
-
title: '404',
|
|
140
|
-
template: 'splash',
|
|
141
|
-
editUrl: false,
|
|
142
|
-
head: [],
|
|
143
|
-
hero: { tagline: locals.t('404.text'), actions: [] },
|
|
144
|
-
pagefind: false,
|
|
145
|
-
sidebar: { hidden: false, attrs: {} },
|
|
146
|
-
draft: false,
|
|
147
|
-
},
|
|
148
|
-
filePath: `${getCollectionPathFromRoot('docs', project)}/404.md`,
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const userEntry = await getEntry('docs', '404');
|
|
152
|
-
const entry = userEntry ? normalizeCollectionEntry(userEntry) : fallbackEntry;
|
|
153
|
-
return { ...entryMeta, entryMeta, entry, id: entry.id };
|
|
154
|
-
}
|