@astrojs/starlight 0.3.0 → 0.3.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,13 @@
1
1
  # @astrojs/starlight
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#257](https://github.com/withastro/starlight/pull/257) [`0502327`](https://github.com/withastro/starlight/commit/050232770c8a2d22f317def8e734e4abb36387c6) Thanks [@JosefJezek](https://github.com/JosefJezek)! - Add Czech language support
8
+
9
+ - [#261](https://github.com/withastro/starlight/pull/261) [`2062b9e`](https://github.com/withastro/starlight/commit/2062b9e21695b5dc3f116731dbfdf609e495018c) Thanks [@delucis](https://github.com/delucis)! - Fix autogenerated navigation for pages using fallback content
10
+
3
11
  ## 0.3.0
4
12
 
5
13
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
@@ -0,0 +1,22 @@
1
+ {
2
+ "skipLink.label": "Přeskočit na obsah",
3
+ "search.label": "Hledat",
4
+ "search.shortcutLabel": "(Vyhledejte stisknutím /)",
5
+ "search.cancelLabel": "Zrušit",
6
+ "search.devWarning": "Vyhledávání je dostupné pouze v produkčních sestaveních. \nZkuste sestavit a zobrazit náhled webu a otestovat jej lokálně.",
7
+ "themeSelect.accessibleLabel": "Vyberte motiv",
8
+ "themeSelect.dark": "Tmavý",
9
+ "themeSelect.light": "Světlý",
10
+ "themeSelect.auto": "Auto",
11
+ "languageSelect.accessibleLabel": "Vyberte jazyk",
12
+ "menuButton.accessibleLabel": "Nabídka",
13
+ "sidebarNav.accessibleLabel": "Hlavní",
14
+ "tableOfContents.onThisPage": "Na této stránce",
15
+ "tableOfContents.overview": "Přehled",
16
+ "i18n.untranslatedContent": "Tento obsah zatím není dostupný ve vašem jazyce.",
17
+ "page.editLink": "Upravit stránku",
18
+ "page.lastUpdated": "Poslední aktualizace:",
19
+ "page.previousLink": "Předchozí",
20
+ "page.nextLink": "Další",
21
+ "404.text": "Stránka nenalezena. Zkontrolujte adresu URL nebo zkuste použít vyhledávací pole."
22
+ }
@@ -1,4 +1,5 @@
1
1
  import { builtinI18nSchema } from '../schemas/i18n';
2
+ import cs from './cs.json';
2
3
  import en from './en.json';
3
4
  import es from './es.json';
4
5
  import de from './de.json';
@@ -10,5 +11,5 @@ import it from './it.json';
10
11
  const { parse } = builtinI18nSchema();
11
12
 
12
13
  export default Object.fromEntries(
13
- Object.entries({ en, es, de, ja, pt, fr, it }).map(([key, dict]) => [key, parse(dict)])
14
+ Object.entries({ cs, en, es, de, ja, pt, fr, it }).map(([key, dict]) => [key, parse(dict)])
14
15
  );
@@ -69,9 +69,9 @@ function groupFromAutogenerateConfig(
69
69
  const dirDocs = routes.filter(
70
70
  (doc) =>
71
71
  // Match against `foo.md` or `foo/index.md`.
72
- stripExtension(doc.entry.id) === localeDir ||
72
+ stripExtension(doc.id) === localeDir ||
73
73
  // Match against `foo/anything/else.md`.
74
- doc.entry.id.startsWith(localeDir + '/')
74
+ doc.id.startsWith(localeDir + '/')
75
75
  );
76
76
  const tree = treeify(dirDocs, localeDir);
77
77
  return {
@@ -136,7 +136,7 @@ function getBreadcrumbs(path: string, baseDir: string): string[] {
136
136
  function treeify(routes: Route[], baseDir: string): Dir {
137
137
  const treeRoot: Dir = {};
138
138
  routes.forEach((doc) => {
139
- const breadcrumbs = getBreadcrumbs(doc.entry.id, baseDir);
139
+ const breadcrumbs = getBreadcrumbs(doc.id, baseDir);
140
140
 
141
141
  // Walk down the route’s path to generate the tree.
142
142
  let currentDir = treeRoot;
package/utils/routing.ts CHANGED
@@ -3,6 +3,7 @@ import { CollectionEntry, getCollection } from 'astro:content';
3
3
  import config from 'virtual:starlight/user-config';
4
4
  import {
5
5
  LocaleData,
6
+ localizedId,
6
7
  localizedSlug,
7
8
  slugToLocaleData,
8
9
  slugToParam,
@@ -16,6 +17,7 @@ export interface Route extends LocaleData {
16
17
  entry: StarlightDocsEntry;
17
18
  entryMeta: LocaleData;
18
19
  slug: string;
20
+ id: string;
19
21
  isFallback?: true;
20
22
  [key: string]: unknown;
21
23
  }
@@ -41,6 +43,7 @@ function getRoutes(): Route[] {
41
43
  const routes: Route[] = docs.map((entry) => ({
42
44
  entry,
43
45
  slug: entry.slug,
46
+ id: entry.id,
44
47
  entryMeta: slugToLocaleData(entry.slug),
45
48
  ...slugToLocaleData(entry.slug),
46
49
  }));
@@ -61,11 +64,13 @@ function getRoutes(): Route[] {
61
64
  const localeDocs = getLocaleDocs(locale);
62
65
  for (const fallback of defaultLocaleDocs) {
63
66
  const slug = localizedSlug(fallback.slug, locale);
67
+ const id = localizedId(fallback.id, locale);
64
68
  const doesNotNeedFallback = localeDocs.some((doc) => doc.slug === slug);
65
69
  if (doesNotNeedFallback) continue;
66
70
  routes.push({
67
71
  entry: fallback,
68
72
  slug,
73
+ id,
69
74
  isFallback: true,
70
75
  lang: localeConfig.lang || 'en',
71
76
  locale,
package/utils/slugs.ts CHANGED
@@ -90,3 +90,24 @@ export function localizedSlug(
90
90
  }
91
91
  return slug ? locale + '/' + slug : locale;
92
92
  }
93
+
94
+ /**
95
+ * Convert a collection entry ID to a different locale.
96
+ * For example, passing an ID of `en/home.md` and a locale of `fr` results in `fr/home.md`.
97
+ * An undefined locale is treated as the root locale, resulting in `home.md`.
98
+ * @param id A collection entry ID
99
+ * @param locale The target locale
100
+ * @example
101
+ * localizedSlug('en/home.md', 'fr') // => 'fr/home.md'
102
+ * localizedSlug('en/home.md', undefined) // => 'home.md'
103
+ */
104
+ export function localizedId(id: string, locale: string | undefined): string {
105
+ const idLocale = slugToLocale(id);
106
+ if (idLocale) {
107
+ return id.replace(idLocale + '/', locale ? locale + '/' : '');
108
+ } else if (locale) {
109
+ return locale + '/' + id;
110
+ } else {
111
+ return id;
112
+ }
113
+ }