-
-
Notifications
You must be signed in to change notification settings - Fork 829
Add YAML support to the FS translation system #2565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 6420bc5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
| "hast-util-to-string": "^3.0.0", | ||
| "hastscript": "^9.0.0", | ||
| "i18next": "^23.11.5", | ||
| "js-yaml": "^4.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the same parser used in Astro.
| const data = | ||
| filePath.ext === '.json' | ||
| ? JSON.parse(content) | ||
| : yaml.load(content, { filename: fileURLToPath(url) }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As YAML is a superset of JSON, we could technically have only used the YAML parser, although I decided against it for 2 reasons:
- We have a test erroring when parsing an empty JSON file, which would no longer have been an error if we used the YAML parser.
- For malformed JSON files, an YAMLException would be thrown, which I think could be confusing for users to mention YAML when they are using JSON files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic and tests all look perfect — thanks @HiDeoo!
Hitting this does make me a tiny bit nervous about the content loader future of all formats being available, but at least for now we can align with Astro’s built-in support 🎉
* main: (82 commits) i18n(ja): Update site-search.mdx (withastro#2577) i18n(ja): Update pages.mdx (withastro#2576) i18n(fr): Update `reference/plugins.mdx` from withastro#2549 (withastro#2574) [ci] format docs: update showcase-sites.astro (withastro#2562) Throw an error if a showcase image does not have the required dimensions (withastro#2573) i18n(ja): Update frontmatter.md (withastro#2566) Fixes import name typo in Customize icons example (withastro#2572) [ci] release (withastro#2570) Prettier ignore a malformed YAML test file (withastro#2571) Add YAML support to the FS translation system (withastro#2565) i18n(ja): Update reference/icons.mdx (withastro#2564) i18n(ja): Update overrides.md (withastro#2567) i18n(zh-cn): Update `plugins.mdx` (withastro#2568) i18n(ja): Update customization.mdx (withastro#2560) i18n(ja): Update css-and-tailwind.mdx (withastro#2559) i18n(ru): update `icons.mdx` and `overrides.md` (withastro#2558) i18n(ru): update `i18n.mdx` and `overriding-components.mdx` (withastro#2557) i18n(ko-KR): update `plugins.mdx` (withastro#2556) i18n(ru): update `plugins.mdx` (withastro#2555) ...
Description
This PR fixes an issue where the FS translation system (only used with some internal integrations or remark plugins at the moment) was not handling YAML files even though Astro Content Collections support YAML files.