@astrojs/starlight 0.30.0 → 0.30.1

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,11 @@
1
1
  # @astrojs/starlight
2
2
 
3
+ ## 0.30.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2688](https://github.com/withastro/starlight/pull/2688) [`5c6996c`](https://github.com/withastro/starlight/commit/5c6996cd248e9da735a14e7fcaf638b51f2796bc) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes an issue with autogenerated sidebars when using Starlight with Astro's new Content Layer API where group names would be sluggified.
8
+
3
9
  ## 0.30.0
4
10
 
5
11
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.30.0",
3
+ "version": "0.30.1",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
@@ -1,5 +1,6 @@
1
1
  import { AstroError } from 'astro/errors';
2
2
  import config from 'virtual:starlight/user-config';
3
+ import project from 'virtual:starlight/project-context';
3
4
  import type { Badge, I18nBadge, I18nBadgeConfig } from '../schemas/badge';
4
5
  import type { PrevNextLinkConfig } from '../schemas/prevNextLink';
5
6
  import type {
@@ -14,8 +15,9 @@ import { formatPath } from './format-path';
14
15
  import { BuiltInDefaultLocale, pickLang } from './i18n';
15
16
  import { ensureLeadingSlash, ensureTrailingSlash, stripLeadingAndTrailingSlashes } from './path';
16
17
  import { getLocaleRoutes, routes, type Route } from './routing';
17
- import { localeToLang, slugToPathname } from './slugs';
18
+ import { localeToLang, localizedId, slugToPathname } from './slugs';
18
19
  import type { StarlightConfig } from './user-config';
20
+ import { getCollectionPathFromRoot } from './collection';
19
21
 
20
22
  const DirKey = Symbol('DirKey');
21
23
  const SlugKey = Symbol('SlugKey');
@@ -108,7 +110,7 @@ function groupFromAutogenerateConfig(
108
110
  // Match against `foo/anything/else.md`.
109
111
  doc.id.startsWith(localeDir + '/')
110
112
  );
111
- const tree = treeify(dirDocs, localeDir);
113
+ const tree = treeify(dirDocs, locale, localeDir);
112
114
  const label = pickLang(item.translations, localeToLang(locale)) || item.label;
113
115
  return {
114
116
  type: 'group',
@@ -205,8 +207,8 @@ function pathsMatch(pathA: string, pathB: string) {
205
207
  function getBreadcrumbs(path: string, baseDir: string): string[] {
206
208
  // Strip extension from path.
207
209
  const pathWithoutExt = stripExtension(path);
208
- // Index paths will match `baseDir` but we still need to consider them as a single segment.
209
- if (pathWithoutExt === baseDir) return [path];
210
+ // Index paths will match `baseDir` and don’t include breadcrumbs.
211
+ if (pathWithoutExt === baseDir) return [];
210
212
  // Ensure base directory ends in a trailing slash.
211
213
  baseDir = ensureTrailingSlash(baseDir);
212
214
  // Strip base directory from path if present.
@@ -218,16 +220,28 @@ function getBreadcrumbs(path: string, baseDir: string): string[] {
218
220
  }
219
221
 
220
222
  /** Turn a flat array of routes into a tree structure. */
221
- function treeify(routes: Route[], baseDir: string): Dir {
223
+ function treeify(routes: Route[], locale: string | undefined, baseDir: string): Dir {
222
224
  const treeRoot: Dir = makeDir(baseDir);
225
+ const collectionPathFromRoot = getCollectionPathFromRoot('docs', project);
223
226
  routes
224
227
  // Remove any entries that should be hidden
225
228
  .filter((doc) => !doc.entry.data.sidebar.hidden)
229
+ // Compute the path of each entry from the root of the collection ahead of time.
230
+ .map(
231
+ (doc) =>
232
+ [
233
+ project.legacyCollections
234
+ ? doc.id
235
+ : // For collections with a loader, use a localized filePath relative to the collection
236
+ localizedId(doc.entry.filePath.replace(`${collectionPathFromRoot}/`, ''), locale),
237
+ doc,
238
+ ] as const
239
+ )
226
240
  // Sort by depth, to build the tree depth first.
227
- .sort((a, b) => b.id.split('/').length - a.id.split('/').length)
241
+ .sort(([a], [b]) => b.split('/').length - a.split('/').length)
228
242
  // Build the tree
229
- .forEach((doc) => {
230
- const parts = getBreadcrumbs(doc.id, baseDir);
243
+ .forEach(([filePathFromContentDir, doc]) => {
244
+ const parts = getBreadcrumbs(filePathFromContentDir, baseDir);
231
245
  let currentNode = treeRoot;
232
246
 
233
247
  parts.forEach((part, index) => {
@@ -374,7 +388,7 @@ function getIntermediateSidebarFromConfig(
374
388
  if (sidebarConfig) {
375
389
  return sidebarConfig.map((group) => configItemToEntry(group, pathname, locale, routes));
376
390
  } else {
377
- const tree = treeify(routes, locale || '');
391
+ const tree = treeify(routes, locale, locale || '');
378
392
  return sidebarFromDir(tree, pathname, locale, false);
379
393
  }
380
394
  }
package/utils/slugs.ts CHANGED
@@ -82,7 +82,8 @@ export function localizedSlug(slug: string, locale: string | undefined): string
82
82
  }
83
83
 
84
84
  /**
85
- * Convert a legacy collection entry ID to a different locale.
85
+ * Convert a legacy collection entry ID or filePath relative to the collection root to a different
86
+ * locale.
86
87
  * For example, passing an ID of `en/home.md` and a locale of `fr` results in `fr/home.md`.
87
88
  * An undefined locale is treated as the root locale, resulting in `home.md`.
88
89
  * @param id A collection entry ID