@astrojs/starlight 0.28.4 → 0.28.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @astrojs/starlight
2
2
 
3
+ ## 0.28.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2546](https://github.com/withastro/starlight/pull/2546) [`bf42300`](https://github.com/withastro/starlight/commit/bf42300e76241a2df888dc458c59a7478a8b2d61) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes an issue where i18n content collection related errors, e.g. malformed JSON or YAML, would not be reported.
8
+
9
+ - [#2548](https://github.com/withastro/starlight/pull/2548) [`07673c8`](https://github.com/withastro/starlight/commit/07673c80114021a269065e451e660337237f76e1) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes a URL localization edge case. In projects without a root locale configured, slugs without a locale prefix did not fall back to the default locale as expected.
10
+
11
+ - [#2547](https://github.com/withastro/starlight/pull/2547) [`91e1dd7`](https://github.com/withastro/starlight/commit/91e1dd731a06657890a68b2d474199455df2756f) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes a Firefox Markdown content rendering issue for text sentences separated by a line break.
12
+
13
+ - [#2524](https://github.com/withastro/starlight/pull/2524) [`1b46783`](https://github.com/withastro/starlight/commit/1b4678325fb10714fc3508bd87a7563b10a0f803) Thanks [@jsparkdev](https://github.com/jsparkdev)! - Fixes a broken link to Astro’s Docs in an error message
14
+
3
15
  ## 0.28.4
4
16
 
5
17
  ### Patch Changes
@@ -1,14 +1,6 @@
1
1
  import type { AstroConfig } from 'astro';
2
2
  import type { StarlightConfig } from '../../types';
3
-
4
- function slugToLocale(
5
- slug: string | undefined,
6
- localesConfig: StarlightConfig['locales']
7
- ): string | undefined {
8
- const locales = Object.keys(localesConfig || {});
9
- const baseSegment = slug?.split('/')[0];
10
- return baseSegment && locales.includes(baseSegment) ? baseSegment : undefined;
11
- }
3
+ import { slugToLocale } from './slugToLocale';
12
4
 
13
5
  /** Get current locale from the full file path. */
14
6
  export function pathToLocale(
@@ -17,7 +9,7 @@ export function pathToLocale(
17
9
  starlightConfig,
18
10
  astroConfig,
19
11
  }: {
20
- starlightConfig: { locales: StarlightConfig['locales'] };
12
+ starlightConfig: Pick<StarlightConfig, 'defaultLocale' | 'locales'>;
21
13
  astroConfig: { root: AstroConfig['root']; srcDir: AstroConfig['srcDir'] };
22
14
  }
23
15
  ): string | undefined {
@@ -31,5 +23,5 @@ export function pathToLocale(
31
23
  // Strip docs path leaving only content collection file ID.
32
24
  // Example: /Users/houston/repo/src/content/docs/en/guide.md => en/guide.md
33
25
  const slug = path?.replace(docsDir.pathname, '');
34
- return slugToLocale(slug, starlightConfig.locales);
26
+ return slugToLocale(slug, starlightConfig);
35
27
  }
@@ -0,0 +1,18 @@
1
+ import type { StarlightConfig } from '../../types';
2
+
3
+ /**
4
+ * Get the “locale” of a slug. This is the base path at which a language is served.
5
+ * For example, if French docs are in `src/content/docs/french/`, the locale is `french`.
6
+ * Root locale slugs will return `undefined`.
7
+ * @param slug A collection entry slug
8
+ */
9
+ export function slugToLocale(
10
+ slug: string | undefined,
11
+ config: Pick<StarlightConfig, 'defaultLocale' | 'locales'>
12
+ ): string | undefined {
13
+ const localesConfig = config.locales ?? {};
14
+ const baseSegment = slug?.split('/')[0];
15
+ if (baseSegment && localesConfig[baseSegment]) return baseSegment;
16
+ if (!localesConfig.root) return config.defaultLocale.locale;
17
+ return undefined;
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.28.4",
3
+ "version": "0.28.5",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
@@ -1,6 +1,6 @@
1
1
  .sl-markdown-content
2
- :not(a, strong, em, del, span, input, code)
3
- + :not(a, strong, em, del, span, input, code, :where(.not-content *)) {
2
+ :not(a, strong, em, del, span, input, code, br)
3
+ + :not(a, strong, em, del, span, input, code, br, :where(.not-content *)) {
4
4
  margin-top: 1rem;
5
5
  }
6
6
 
@@ -163,7 +163,7 @@ function linkFromInternalSidebarLinkItem(
163
163
  throw new AstroError(
164
164
  `The slug \`"${item.slug}"\` specified in the Starlight sidebar config does not exist.`,
165
165
  'Update the Starlight config to reference a valid entry slug in the docs content collection.\n' +
166
- 'Learn more about Astro content collection slugs at https://docs.astro.build/en/reference/api-reference/#getentry'
166
+ 'Learn more about Astro content collection slugs at https://docs.astro.build/en/reference/modules/astro-content/#getentry'
167
167
  );
168
168
  }
169
169
  }
package/utils/slugs.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import config from 'virtual:starlight/user-config';
2
2
  import { BuiltInDefaultLocale } from './i18n';
3
3
  import { stripTrailingSlash } from './path';
4
+ import { slugToLocale as getLocaleFromSlug } from '../integrations/shared/slugToLocale';
4
5
 
5
6
  export interface LocaleData {
6
7
  /** Writing direction. */
@@ -18,10 +19,7 @@ export interface LocaleData {
18
19
  * @param slug A collection entry slug
19
20
  */
20
21
  function slugToLocale(slug: string): string | undefined {
21
- const locales = Object.keys(config.locales || {});
22
- const baseSegment = slug.split('/')[0];
23
- if (baseSegment && locales.includes(baseSegment)) return baseSegment;
24
- return undefined;
22
+ return getLocaleFromSlug(slug, config);
25
23
  }
26
24
 
27
25
  /** Get locale information for a given slug. */
@@ -14,17 +14,13 @@ export type UserI18nKeys = keyof RemoveIndexSignature<UserI18nSchema>;
14
14
 
15
15
  /** Get all translation data from the i18n collection, keyed by `id`, which matches locale. */
16
16
  async function loadTranslations() {
17
- let userTranslations: Record<string, UserI18nSchema> = {};
18
17
  // Briefly override `console.warn()` to silence logging when a project has no i18n collection.
19
18
  const warn = console.warn;
20
19
  console.warn = () => {};
21
- try {
22
- // Load the user’s i18n collection and ignore the error if it doesn’t exist.
23
- userTranslations = Object.fromEntries(
24
- // @ts-ignore — may be an error in projects without an i18n collection
25
- (await getCollection('i18n')).map(({ id, data }) => [id, data] as const)
26
- );
27
- } catch {}
20
+ const userTranslations: Record<string, UserI18nSchema> = Object.fromEntries(
21
+ // @ts-ignore may be a type error in projects without an i18n collection
22
+ (await getCollection('i18n')).map(({ id, data }) => [id, data] as const)
23
+ );
28
24
  // Restore the original warn implementation.
29
25
  console.warn = warn;
30
26
  return userTranslations;