@astrojs/starlight 0.29.0 → 0.29.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @astrojs/starlight
2
2
 
3
+ ## 0.29.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2616](https://github.com/withastro/starlight/pull/2616) [`128cc51`](https://github.com/withastro/starlight/commit/128cc51b416a1a934eabb1989c04b76517e77a04) Thanks [@delucis](https://github.com/delucis)! - Fixes an edge case to correctly avoid a trailing slash when navigating from a root locale homepage to another language via Starlight’s language switcher when `trailingSlash: 'never'` is set
8
+
9
+ ## 0.29.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#2611](https://github.com/withastro/starlight/pull/2611) [`6059d96`](https://github.com/withastro/starlight/commit/6059d961a6b31fd7848b0c59411fc6370e62abab) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes a UI string type issue in projects with multiple data content collections.
14
+
15
+ - [#2606](https://github.com/withastro/starlight/pull/2606) [`10b15a7`](https://github.com/withastro/starlight/commit/10b15a7fcda4805dda622f893b6671b96a349161) Thanks [@delucis](https://github.com/delucis)! - Makes `<CardGrid>` more resilient to complex child content on smaller viewports
16
+
17
+ - [#2605](https://github.com/withastro/starlight/pull/2605) [`ec7ab4f`](https://github.com/withastro/starlight/commit/ec7ab4f1df83052aa00c5f560adf7e7b8d61c9db) Thanks [@brianzelip](https://github.com/brianzelip)! - Exposes `SidebarPersister` component in package exports for use in custom overrides
18
+
19
+ - [#2614](https://github.com/withastro/starlight/pull/2614) [`9a31980`](https://github.com/withastro/starlight/commit/9a319807c698f65b461f456c54c413081ab551f0) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes an issue with custom pages using the `<StarlightPage />` component and a custom sidebar missing highlighting for the active page and navigation links.
20
+
21
+ - [#2600](https://github.com/withastro/starlight/pull/2600) [`49aef17`](https://github.com/withastro/starlight/commit/49aef173811d05ae132729c92c3920a142ceeb7d) Thanks [@jdevega](https://github.com/jdevega)! - Adds Backstage social icon
22
+
23
+ - [#2613](https://github.com/withastro/starlight/pull/2613) [`a73780f`](https://github.com/withastro/starlight/commit/a73780fb280feb5b96ffa94539633b2930bd8e76) Thanks [@delucis](https://github.com/delucis)! - Fixes support for `sidebar` frontmatter options in sidebar entries using `slug` or the string shorthand for internal links
24
+
3
25
  ## 0.29.0
4
26
 
5
27
  ### Minor Changes
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  import type { z } from 'astro/zod';
3
+ import context from 'virtual:starlight/project-context';
3
4
  import config from 'virtual:starlight/user-config';
4
5
  import { version } from '../package.json';
5
6
  import type { HeadConfigSchema } from '../schemas/head';
@@ -66,7 +67,7 @@ if (canonical && config.isMultilingual) {
66
67
  attrs: {
67
68
  rel: 'alternate',
68
69
  hreflang: localeOpts.lang,
69
- href: localizedUrl(canonical, locale).href,
70
+ href: localizedUrl(canonical, locale, context.trailingSlash).href,
70
71
  },
71
72
  });
72
73
  }
@@ -160,6 +160,8 @@ export const BuiltInIcons = {
160
160
  jsr: '<path d="M3.7 5.54v3.7H0v7.38h7.38v1.84h12.93v-3.7H24V7.39h-7.38V5.54Zm1.84 1.85h1.85v7.38H1.84v-3.7h1.84v1.85h1.85zm3.7 0h5.53v1.84h-3.7v1.85h3.7v5.53H9.23v-1.84h3.7v-1.85h-3.7Zm7.38 1.84h5.53v3.7h-1.84v-1.85h-1.85v5.54h-1.84z"/>',
161
161
  nostr:
162
162
  '<path d="M21.6 10.6v9.7a.7.7 0 0 1-.6.6h-8a.7.7 0 0 1-.6-.6v-1.8c0-2.2.3-4.4.8-5.3a2 2 0 0 1 1.3-1c1-.4 2.9-.2 3.7-.2 0 0 2.3 0 2.3-1.3 0-1-1-1-1-1-1.2 0-2 0-2.6-.2-1-.4-1-1.1-1-1.3 0-2.7-4-3-7.5-2.4-3.9.7 0 6.2 0 13.5v1a.7.7 0 0 1-.7.6H3.8a.7.7 0 0 1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4.6 5c-1 1-2.5 1.6-4.1 1.6a6.8 6.8 0 0 1-3.5-1l-5.6-3.4v1.3l6 3.6a6.1 6.1 0 0 0 3 1c1.5 0 2.8-.5 3.7-1.5.7-.6 1.1-1.5 1.1-2.2V20l-.6.7zM19.7 9l-.1.2-1.2.8a5.2 5.2 0 0 1-1.5.5 5.2 5.2 0 0 1-.8 0l.1.4V12a4.6 4.6 0 0 0 1.5-.3A4.4 4.4 0 0 0 19 11l.1-.1a4.5 4.5 0 0 0 .8-1.1 2.6 2.6 0 0 0 .3-1.1v-.1l-.2.1-.4.6zm0 4.3a6 6 0 0 1-.1.1 5.2 5.2 0 0 1-3.3 1.5v1.4a4.5 4.5 0 0 0 2.8-1.2l1-1.2.2-1v-.1l-.2.2a4.8 4.8 0 0 1-.4.5zm0-2.1-.1.1a4.8 4.8 0 0 1-.6.5 5.2 5.2 0 0 1-2.7 1v1.4A4.5 4.5 0 0 0 19 13h.1a4.2 4.2 0 0 0 .8-1.2l.3-.9v-.3a4 4 0 0 1-.2.2l-.4.5z"/>',
163
165
  };
164
166
 
165
167
  export const Icons = {
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import context from 'virtual:starlight/project-context';
2
3
  import config from 'virtual:starlight/user-config';
3
4
  import { localizedUrl } from '../utils/localizedUrl';
4
5
  import Select from './Select.astro';
@@ -8,7 +9,7 @@ import type { Props } from '../props';
8
9
  * Get the equivalent of the current page path for the passed locale.
9
10
  */
10
11
  function localizedPathname(locale: string | undefined): string {
11
- return localizedUrl(Astro.url, locale).pathname;
12
+ return localizedUrl(Astro.url, locale, context.trailingSlash).pathname;
12
13
  }
13
14
  ---
14
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.29.0",
3
+ "version": "0.29.2",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
@@ -47,6 +47,10 @@
47
47
  "types": "./components/MarkdownContent.astro.tsx",
48
48
  "import": "./components/MarkdownContent.astro"
49
49
  },
50
+ "./components/SidebarPersister.astro": {
51
+ "types": "./components/SidebarPersister.astro.tsx",
52
+ "import": "./components/SidebarPersister.astro"
53
+ },
50
54
  "./components/SidebarSublist.astro": {
51
55
  "types": "./components/SidebarSublist.astro.tsx",
52
56
  "import": "./components/SidebarSublist.astro"
package/schemas/social.ts CHANGED
@@ -36,6 +36,7 @@ export const socialLinks = [
36
36
  'pinterest',
37
37
  'tiktok',
38
38
  'nostr',
39
+ 'backstage',
39
40
  ] as const;
40
41
 
41
42
  export const SocialLinksSchema = () =>
@@ -87,6 +88,7 @@ export const SocialLinksSchema = () =>
87
88
  pinterest: 'Pinterest',
88
89
  tiktok: 'TikTok',
89
90
  nostr: 'Nostr',
91
+ backstage: 'Backstage',
90
92
  }[key];
91
93
  labelledLinks[key] = { label, url };
92
94
  }
@@ -11,6 +11,7 @@ const { stagger = false } = Astro.props;
11
11
  <style>
12
12
  .card-grid {
13
13
  display: grid;
14
+ grid-template-columns: 100%;
14
15
  gap: 1rem;
15
16
  }
16
17
 
@@ -121,7 +121,11 @@ function buildResources<T extends Record<string, string | undefined>>(
121
121
  return { [I18nextNamespace]: dictionary as BuiltInStrings & T };
122
122
  }
123
123
 
124
- export type I18nKeys = UserI18nKeys | keyof StarlightApp.I18n;
124
+ // `keyof BuiltInStrings` and `UserI18nKeys` may contain some identical keys, e.g. the built-in UI
125
+ // strings. We let TypeScript merge them into a single union type so that plugins with a TypeScript
126
+ // configuration preventing `UserI18nKeys` to be properly inferred can still get auto-completion
127
+ // for built-in UI strings.
128
+ export type I18nKeys = keyof BuiltInStrings | UserI18nKeys | keyof StarlightApp.I18n;
125
129
 
126
130
  export type I18nT = TFunction<'starlight', undefined> & {
127
131
  all: () => UserI18nSchema;
@@ -1,10 +1,15 @@
1
1
  import config from 'virtual:starlight/user-config';
2
2
  import { stripTrailingSlash } from './path';
3
+ import type { AstroConfig } from 'astro';
3
4
 
4
5
  /**
5
6
  * Get the equivalent of the passed URL for the passed locale.
6
7
  */
7
- export function localizedUrl(url: URL, locale: string | undefined): URL {
8
+ export function localizedUrl(
9
+ url: URL,
10
+ locale: string | undefined,
11
+ trailingSlash: AstroConfig['trailingSlash']
12
+ ): URL {
8
13
  // Create a new URL object to void mutating the global.
9
14
  url = new URL(url);
10
15
  if (!config.locales) {
@@ -41,5 +46,6 @@ export function localizedUrl(url: URL, locale: string | undefined): URL {
41
46
  }
42
47
  // Restore base
43
48
  if (hasBase) url.pathname = base + url.pathname;
49
+ if (trailingSlash === 'never') url.pathname = stripTrailingSlash(url.pathname);
44
50
  return url;
45
51
  }
@@ -142,8 +142,8 @@ function linkFromInternalSidebarLinkItem(
142
142
  // Astro passes root `index.[md|mdx]` entries with a slug of `index`
143
143
  const slug = item.slug === 'index' ? '' : item.slug;
144
144
  const localizedSlug = locale ? (slug ? locale + '/' + slug : locale) : slug;
145
- const entry = routes.find((entry) => localizedSlug === entry.slug);
146
- if (!entry) {
145
+ const route = routes.find((entry) => localizedSlug === entry.slug);
146
+ if (!route) {
147
147
  const hasExternalSlashes = item.slug.at(0) === '/' || item.slug.at(-1) === '/';
148
148
  if (hasExternalSlashes) {
149
149
  throw new AstroError(
@@ -158,9 +158,15 @@ function linkFromInternalSidebarLinkItem(
158
158
  );
159
159
  }
160
160
  }
161
+ const frontmatter = route.entry.data;
161
162
  const label =
162
- pickLang(item.translations, localeToLang(locale)) || item.label || entry.entry.data.title;
163
- return makeSidebarLink(entry.slug, label, getSidebarBadge(item.badge, locale, label), item.attrs);
163
+ pickLang(item.translations, localeToLang(locale)) ||
164
+ item.label ||
165
+ frontmatter.sidebar?.label ||
166
+ frontmatter.title;
167
+ const badge = item.badge ?? frontmatter.sidebar?.badge;
168
+ const attrs = { ...frontmatter.sidebar?.attrs, ...item.attrs };
169
+ return makeSidebarLink(route.slug, label, getSidebarBadge(badge, locale, label), attrs);
164
170
  }
165
171
 
166
172
  /** Process sidebar link options to create a link entry. */
@@ -342,7 +348,7 @@ const intermediateSidebars = new Map<string | undefined, SidebarEntry[]>();
342
348
  export function getSidebar(pathname: string, locale: string | undefined): SidebarEntry[] {
343
349
  let intermediateSidebar = intermediateSidebars.get(locale);
344
350
  if (!intermediateSidebar) {
345
- intermediateSidebar = getSidebarFromConfig(config.sidebar, pathname, locale);
351
+ intermediateSidebar = getIntermediateSidebarFromConfig(config.sidebar, pathname, locale);
346
352
  intermediateSidebars.set(locale, intermediateSidebar);
347
353
  }
348
354
  return getSidebarFromIntermediateSidebar(intermediateSidebar, pathname);
@@ -353,6 +359,16 @@ export function getSidebarFromConfig(
353
359
  sidebarConfig: StarlightConfig['sidebar'],
354
360
  pathname: string,
355
361
  locale: string | undefined
362
+ ): SidebarEntry[] {
363
+ const intermediateSidebar = getIntermediateSidebarFromConfig(sidebarConfig, pathname, locale);
364
+ return getSidebarFromIntermediateSidebar(intermediateSidebar, pathname);
365
+ }
366
+
367
+ /** Get the intermediate sidebar for the current page using the specified sidebar config. */
368
+ function getIntermediateSidebarFromConfig(
369
+ sidebarConfig: StarlightConfig['sidebar'],
370
+ pathname: string,
371
+ locale: string | undefined
356
372
  ): SidebarEntry[] {
357
373
  const routes = getLocaleRoutes(locale);
358
374
  if (sidebarConfig) {
@@ -5,8 +5,13 @@ import type { i18nSchemaOutput } from '../schemas/i18n';
5
5
  import { createTranslationSystem } from './createTranslationSystem';
6
6
  import type { RemoveIndexSignature } from './types';
7
7
 
8
+ // @ts-ignore - This may be a type error in projects without an i18n collection and running
9
+ // `tsc --noEmit` in their project. Note that it is not possible to inline this type in
10
+ // `UserI18nSchema` because this would break types for users having multiple data collections.
11
+ type i18nCollection = CollectionEntry<'i18n'>;
12
+
8
13
  export type UserI18nSchema = 'i18n' extends DataCollectionKey
9
- ? CollectionEntry<'i18n'> extends { data: infer T }
14
+ ? i18nCollection extends { data: infer T }
10
15
  ? i18nSchemaOutput & T
11
16
  : i18nSchemaOutput
12
17
  : i18nSchemaOutput;