@astrojs/starlight 0.24.0 → 0.24.2

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.
@@ -43,10 +43,10 @@ export function vitePluginStarlightUserConfig(
43
43
  ? 'src' in opts.logo
44
44
  ? `import src from ${resolveId(
45
45
  opts.logo.src
46
- )}; export const logos = { dark: src, light: src };`
46
+ )}; export const logos = { dark: src, light: src };`
47
47
  : `import dark from ${resolveId(opts.logo.dark)}; import light from ${resolveId(
48
48
  opts.logo.light
49
- )}; export const logos = { dark, light };`
49
+ )}; export const logos = { dark, light };`
50
50
  : 'export const logos = {};',
51
51
  'virtual:starlight/collection-config': `let userCollections;
52
52
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.24.0",
3
+ "version": "0.24.2",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
@@ -22,10 +22,6 @@
22
22
  "exports": {
23
23
  ".": "./index.ts",
24
24
  "./components": "./components.ts",
25
- "./components/Badge.astro": {
26
- "types": "./components/Badge.astro.tsx",
27
- "import": "./components/Badge.astro"
28
- },
29
25
  "./components/LanguageSelect.astro": {
30
26
  "types": "./components/LanguageSelect.astro.tsx",
31
27
  "import": "./components/LanguageSelect.astro"
@@ -178,25 +174,25 @@
178
174
  "astro": "^4.8.6"
179
175
  },
180
176
  "devDependencies": {
181
- "@astrojs/markdown-remark": "^4.2.1",
182
- "@playwright/test": "^1.43.1",
177
+ "@astrojs/markdown-remark": "^5.1.0",
178
+ "@playwright/test": "^1.44.1",
183
179
  "@types/node": "^18.16.19",
184
180
  "@vitest/coverage-v8": "^1.6.0",
185
- "astro": "^4.8.6",
181
+ "astro": "^4.10.2",
186
182
  "vitest": "^1.6.0"
187
183
  },
188
184
  "dependencies": {
189
- "@astrojs/mdx": "^3.0.0",
190
- "@astrojs/sitemap": "^3.0.5",
185
+ "@astrojs/mdx": "^3.1.0",
186
+ "@astrojs/sitemap": "^3.1.5",
191
187
  "@pagefind/default-ui": "^1.0.3",
192
- "@types/hast": "^3.0.3",
193
- "@types/mdast": "^4.0.3",
194
- "astro-expressive-code": "^0.35.2",
188
+ "@types/hast": "^3.0.4",
189
+ "@types/mdast": "^4.0.4",
190
+ "astro-expressive-code": "^0.35.3",
195
191
  "bcp-47": "^2.1.0",
196
192
  "hast-util-from-html": "^2.0.1",
197
193
  "hast-util-select": "^6.0.2",
198
194
  "hast-util-to-string": "^3.0.0",
199
- "hastscript": "^8.0.0",
195
+ "hastscript": "^9.0.0",
200
196
  "mdast-util-directive": "^3.0.0",
201
197
  "mdast-util-to-markdown": "^2.1.0",
202
198
  "pagefind": "^1.0.3",
package/schema.ts CHANGED
@@ -126,8 +126,8 @@ type BaseSchema = BaseSchemaWithoutEffects | z.ZodEffects<BaseSchemaWithoutEffec
126
126
  type ExtendedSchema<T extends BaseSchema | never = never> = [T] extends [never]
127
127
  ? DefaultSchema
128
128
  : T extends BaseSchema
129
- ? z.ZodIntersection<DefaultSchema, T>
130
- : DefaultSchema;
129
+ ? z.ZodIntersection<DefaultSchema, T>
130
+ : DefaultSchema;
131
131
 
132
132
  interface DocsSchemaOpts<T extends BaseSchema> {
133
133
  /**
package/schemas/social.ts CHANGED
@@ -31,6 +31,7 @@ export const socialLinks = [
31
31
  'hackerOne',
32
32
  'blueSky',
33
33
  'discourse',
34
+ 'zulip',
34
35
  ] as const;
35
36
 
36
37
  export const SocialLinksSchema = () =>
@@ -77,6 +78,7 @@ export const SocialLinksSchema = () =>
77
78
  hackerOne: 'Hacker One',
78
79
  blueSky: 'BlueSky',
79
80
  discourse: 'Discourse',
81
+ zulip: 'Zulip',
80
82
  }[key];
81
83
  labelledLinks[key] = { label, url };
82
84
  }
@@ -26,6 +26,7 @@ import uk from './uk.json';
26
26
  import hi from './hi.json';
27
27
  import zhTW from './zh-TW.json';
28
28
  import pl from './pl.json';
29
+ import sk from './sk.json';
29
30
 
30
31
  const { parse } = builtinI18nSchema();
31
32
 
@@ -58,5 +59,6 @@ export default Object.fromEntries(
58
59
  hi,
59
60
  'zh-TW': zhTW,
60
61
  pl,
62
+ sk,
61
63
  }).map(([key, dict]) => [key, parse(dict)])
62
64
  );
@@ -24,6 +24,6 @@
24
24
  "aside.tip": "팁",
25
25
  "aside.caution": "주의",
26
26
  "aside.danger": "위험",
27
- "fileTree.directory": "Directory",
28
- "builtWithStarlight.label": "Built with Starlight"
27
+ "fileTree.directory": "디렉터리",
28
+ "builtWithStarlight.label": "Starlight로 제작됨"
29
29
  }
@@ -0,0 +1,29 @@
1
+ {
2
+ "skipLink.label": "Preskočiť na obsah",
3
+ "search.label": "Hľadať",
4
+ "search.shortcutLabel": "(Stlačením / hľadajte)",
5
+ "search.cancelLabel": "Zrušiť",
6
+ "search.devWarning": "Vyhľadávanie je dostupné len v produkčných zostaveniach. \nSkúste vytvoriť a zobraziť náhľad stránky lokálne.",
7
+ "themeSelect.accessibleLabel": "Vyberte tému",
8
+ "themeSelect.dark": "Tmavý",
9
+ "themeSelect.light": "Svetlý",
10
+ "themeSelect.auto": "Auto",
11
+ "languageSelect.accessibleLabel": "Vyberte jazyk",
12
+ "menuButton.accessibleLabel": "Menu",
13
+ "sidebarNav.accessibleLabel": "Hlavný",
14
+ "tableOfContents.onThisPage": "Na tejto stránke",
15
+ "tableOfContents.overview": "Prehľad",
16
+ "i18n.untranslatedContent": "Tento obsah zatiaľ nie je dostupný vo vašom jazyku.",
17
+ "page.editLink": "Upraviť stránku",
18
+ "page.lastUpdated": "Posledná aktualizácia:",
19
+ "page.previousLink": "Predchádzajúce",
20
+ "page.nextLink": "Nasledujúce",
21
+ "page.draft": "Tento obsah je koncept a nebude zahrnutý do produkčných zostavení.",
22
+ "404.text": "Stránka nenájdená. Skontrolujte URL alebo skúste použiť vyhľadávacie pole.",
23
+ "aside.note": "Poznámka",
24
+ "aside.tip": "Tip",
25
+ "aside.caution": "Upozornenie",
26
+ "aside.danger": "Nebezpečenstvo",
27
+ "fileTree.directory": "Adresár",
28
+ "builtWithStarlight.label": "Postavené so Starlight"
29
+ }
@@ -25,5 +25,5 @@
25
25
  "aside.caution": "Thận trọng",
26
26
  "aside.danger": "Nguy hiểm",
27
27
  "fileTree.directory": "Danh mục",
28
- "builtWithStarlight.label": "Built with Starlight"
28
+ "builtWithStarlight.label": "Tạo với Starlight"
29
29
  }
@@ -119,12 +119,12 @@ const { html, panels } = processPanels(panelHtml);
119
119
  e.key === 'ArrowLeft'
120
120
  ? index - 1
121
121
  : e.key === 'ArrowRight'
122
- ? index + 1
123
- : e.key === 'Home'
124
- ? 0
125
- : e.key === 'End'
126
- ? this.tabs.length - 1
127
- : null;
122
+ ? index + 1
123
+ : e.key === 'Home'
124
+ ? 0
125
+ : e.key === 'End'
126
+ ? this.tabs.length - 1
127
+ : null;
128
128
  if (nextIndex === null) return;
129
129
  if (this.tabs[nextIndex]) {
130
130
  e.preventDefault();
@@ -63,7 +63,7 @@ const errorMap: z.ZodErrorMap = (baseError, ctx) => {
63
63
  .map(([key, error]) =>
64
64
  key === baseErrorPath
65
65
  ? // Avoid printing the key again if it's a base error
66
- `> ${getTypeOrLiteralMsg(error)}`
66
+ `> ${getTypeOrLiteralMsg(error)}`
67
67
  : `> ${prefix(key, getTypeOrLiteralMsg(error))}`
68
68
  );
69
69
 
package/utils/i18n.ts CHANGED
@@ -5,6 +5,15 @@ import type { StarlightConfig } from './user-config';
5
5
  /** Informations about the built-in default locale used as a fallback when no locales are defined. */
6
6
  export const BuiltInDefaultLocale = { ...getLocaleInfo('en'), lang: 'en' };
7
7
 
8
+ /**
9
+ * A list of well-known right-to-left languages used as a fallback when determining the text
10
+ * direction of a locale is not supported by the `Intl.Locale` API in the current environment.
11
+ *
12
+ * @see getLocaleDir()
13
+ * @see https://en.wikipedia.org/wiki/IETF_language_tag#List_of_common_primary_language_subtags
14
+ */
15
+ const wellKnownRTL = ['ar', 'fa', 'he', 'prs', 'ps', 'syc', 'ug', 'ur'];
16
+
8
17
  /**
9
18
  * Processes the Astro and Starlight i18n configurations to generate/update them accordingly:
10
19
  *
@@ -52,8 +61,8 @@ function getAstroI18nConfig(config: StarlightConfig): NonNullable<AstroConfig['i
52
61
  codes: [localeConfig?.lang ?? locale],
53
62
  path: locale === 'root' ? localeConfig?.lang ?? BuiltInDefaultLocale.lang : locale,
54
63
  };
55
- })
56
- : [BuiltInDefaultLocale.lang],
64
+ })
65
+ : [config.defaultLocale.lang],
57
66
  routing: {
58
67
  prefixDefaultLocale:
59
68
  // Sites with multiple languages without a root locale.
@@ -86,11 +95,11 @@ function getStarlightI18nConfig(
86
95
  isDefaultAstroLocale(astroI18nConfig, locale) && !prefixDefaultLocale
87
96
  ? 'root'
88
97
  : isAstroLocaleExtendedConfig(locale)
89
- ? locale.path
90
- : locale,
98
+ ? locale.path
99
+ : locale,
91
100
  inferStarlightLocaleFromAstroLocale(locale),
92
101
  ])
93
- );
102
+ );
94
103
 
95
104
  const defaultAstroLocale = astroI18nConfig.locales.find((locale) =>
96
105
  isDefaultAstroLocale(astroI18nConfig, locale)
@@ -112,8 +121,8 @@ function getStarlightI18nConfig(
112
121
  locale: isMonolingualWithRootLocale
113
122
  ? undefined
114
123
  : isAstroLocaleExtendedConfig(defaultAstroLocale)
115
- ? defaultAstroLocale.codes[0]
116
- : defaultAstroLocale,
124
+ ? defaultAstroLocale.codes[0]
125
+ : defaultAstroLocale,
117
126
  },
118
127
  };
119
128
  }
@@ -150,8 +159,7 @@ function getLocaleInfo(lang: string) {
150
159
  if (!label || lang === label) throw new Error('Label not found.');
151
160
  return {
152
161
  label: label[0]?.toLocaleUpperCase(locale) + label.slice(1),
153
- // @ts-expect-error - `textInfo` is not part of the `Intl.Locale` type but is available in Node.js 18.0.0+.
154
- dir: locale.textInfo.direction as 'ltr' | 'rtl',
162
+ dir: getLocaleDir(locale),
155
163
  };
156
164
  } catch (error) {
157
165
  throw new AstroError(
@@ -161,6 +169,23 @@ function getLocaleInfo(lang: string) {
161
169
  }
162
170
  }
163
171
 
172
+ /**
173
+ * Returns the direction of the passed locale.
174
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
175
+ */
176
+ function getLocaleDir(locale: Intl.Locale): 'ltr' | 'rtl' {
177
+ if ('textInfo' in locale) {
178
+ // @ts-expect-error - `textInfo` is not typed but is available in v8 based environments.
179
+ return locale.textInfo.direction;
180
+ } else if ('getTextInfo' in locale) {
181
+ // @ts-expect-error - `getTextInfo` is not typed but is available in some non-v8 based environments.
182
+ return locale.getTextInfo().direction;
183
+ }
184
+ // Firefox does not support `textInfo` or `getTextInfo` yet so we fallback to a well-known list
185
+ // of right-to-left languages.
186
+ return wellKnownRTL.includes(locale.language) ? 'rtl' : 'ltr';
187
+ }
188
+
164
189
  /**
165
190
  * Get the string for the passed language from a dictionary object.
166
191
  *
@@ -223,7 +223,7 @@ function getOrder(routeOrDir: Route | Dir): number {
223
223
  return isDir(routeOrDir)
224
224
  ? Math.min(...Object.values(routeOrDir).flatMap(getOrder))
225
225
  : // If no order value is found, set it to the largest number possible.
226
- routeOrDir.entry.data.sidebar.order ?? Number.MAX_VALUE;
226
+ routeOrDir.entry.data.sidebar.order ?? Number.MAX_VALUE;
227
227
  }
228
228
 
229
229
  /** Sort a directory’s entries by user-specified order or alphabetically if no order specified. */
@@ -67,8 +67,8 @@ export function getToC({ entry, locale, headings }: PageProps) {
67
67
  entry.data.template === 'splash'
68
68
  ? false
69
69
  : entry.data.tableOfContents !== undefined
70
- ? entry.data.tableOfContents
71
- : config.tableOfContents;
70
+ ? entry.data.tableOfContents
71
+ : config.tableOfContents;
72
72
  if (!tocConfig) return;
73
73
  const t = useTranslations(locale);
74
74
  return {
package/utils/slugs.ts CHANGED
@@ -52,8 +52,8 @@ export function slugToParam(slug: string): string | undefined {
52
52
  return slug === 'index' || slug === ''
53
53
  ? undefined
54
54
  : slug.endsWith('/index')
55
- ? slug.replace(/\/index$/, '')
56
- : slug;
55
+ ? slug.replace(/\/index$/, '')
56
+ : slug;
57
57
  }
58
58
 
59
59
  export function slugToPathname(slug: string): string {
@@ -292,10 +292,10 @@ type RemoveIndexSignature<T> = {
292
292
  [K in keyof T as string extends K
293
293
  ? never
294
294
  : number extends K
295
- ? never
296
- : symbol extends K
297
- ? never
298
- : K]: T[K];
295
+ ? never
296
+ : symbol extends K
297
+ ? never
298
+ : K]: T[K];
299
299
  };
300
300
 
301
301
  // https://www.totaltypescript.com/concepts/the-prettify-helper
@@ -225,7 +225,11 @@ export const StarlightConfigSchema = UserConfigSchema.strict().transform(
225
225
  // Monolingual sites with only one non-root locale needs their configuration to be defined in
226
226
  // `config.locales` so that slugs can be correctly generated by taking into consideration the
227
227
  // base path at which a language is served which is the key of the `config.locales` object.
228
- if (locales !== undefined && configuredLocales.length >= 1) {
228
+ if (
229
+ locales !== undefined &&
230
+ (configuredLocales.length > 1 ||
231
+ (configuredLocales.length === 1 && locales.root === undefined))
232
+ ) {
229
233
  // Make sure we can find the default locale and if not, help the user set it.
230
234
  // We treat the root locale as the default if present and no explicit default is set.
231
235
  const defaultLocaleConfig = locales[defaultLocale || 'root'];