@astrojs/starlight 0.28.5 → 0.28.6

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.28.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2565](https://github.com/withastro/starlight/pull/2565) [`236467b`](https://github.com/withastro/starlight/commit/236467bb745cea7a284ae3d398874d3edbcd846e) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes an issue with custom UI strings defined in YAML files not being loaded in some contexts.
8
+
3
9
  ## 0.28.5
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.28.5",
3
+ "version": "0.28.6",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
@@ -172,6 +172,7 @@
172
172
  "devDependencies": {
173
173
  "@astrojs/markdown-remark": "^5.1.0",
174
174
  "@playwright/test": "^1.45.0",
175
+ "@types/js-yaml": "^4.0.9",
175
176
  "@types/node": "^18.16.19",
176
177
  "@vitest/coverage-v8": "^1.6.0",
177
178
  "astro": "^4.15.3",
@@ -191,6 +192,7 @@
191
192
  "hast-util-to-string": "^3.0.0",
192
193
  "hastscript": "^9.0.0",
193
194
  "i18next": "^23.11.5",
195
+ "js-yaml": "^4.1.0",
194
196
  "mdast-util-directive": "^3.0.0",
195
197
  "mdast-util-to-markdown": "^2.1.0",
196
198
  "mdast-util-to-string": "^4.0.0",
@@ -1,9 +1,14 @@
1
1
  import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import yaml from 'js-yaml';
2
5
  import type { i18nSchemaOutput } from '../schemas/i18n';
3
6
  import { createTranslationSystem } from './createTranslationSystem';
4
7
  import type { StarlightConfig } from './user-config';
5
8
  import type { AstroConfig } from 'astro';
6
9
 
10
+ const contentCollectionFileExtensions = ['.json', '.yaml', '.yml'];
11
+
7
12
  /**
8
13
  * Loads and creates a translation system from the file system.
9
14
  * Only for use in integration code.
@@ -23,15 +28,18 @@ export function createTranslationSystemFromFs<T extends i18nSchemaOutput>(
23
28
  // Load the user’s i18n directory
24
29
  const files = fs.readdirSync(i18nDir, 'utf-8');
25
30
  // Load the user’s i18n collection and ignore the error if it doesn’t exist.
26
- userTranslations = Object.fromEntries(
27
- files
28
- .filter((file) => file.endsWith('.json'))
29
- .map((file) => {
30
- const id = file.slice(0, -5);
31
- const data = JSON.parse(fs.readFileSync(new URL(file, i18nDir), 'utf-8'));
32
- return [id, data] as const;
33
- })
34
- );
31
+ for (const file of files) {
32
+ const filePath = path.parse(file);
33
+ if (!contentCollectionFileExtensions.includes(filePath.ext)) continue;
34
+ const id = filePath.name;
35
+ const url = new URL(filePath.base, i18nDir);
36
+ const content = fs.readFileSync(new URL(file, i18nDir), 'utf-8');
37
+ const data =
38
+ filePath.ext === '.json'
39
+ ? JSON.parse(content)
40
+ : yaml.load(content, { filename: fileURLToPath(url) });
41
+ userTranslations[id] = data as i18nSchemaOutput;
42
+ }
35
43
  } catch (e: unknown) {
36
44
  if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {
37
45
  // i18nDir doesn’t exist, so we ignore the error.