Skip to content
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

feat: custom file formats in file content loader #12047

Merged
merged 12 commits into from
Sep 29, 2024

Conversation

rgodha24
Copy link
Contributor

@rgodha24 rgodha24 commented Sep 20, 2024

Changes

  • changes only the file() content layer loader.
  • adds native support for yaml data sources
  • adds support for custom (e.g. toml, csv) data formats by passing in a custom parsing function
  • adds support for nested data in a file
    • e.g. {"dogs": [{...}], "cats":[{...}]} can be in one file by parsing a parse function like (text) => JSON.parse(text).cats

Testing

I added tests for a file loader with a yaml source, a toml source, and a nested json source. the toml source is also nested (that's the only way toml can be used in this scenario).

Docs

This definitely will need doc updates.
some parts that will be out of date:

I would definitely be willing to contribute docs for this feature

/cc @withastro/maintainers-docs

Copy link

changeset-bot bot commented Sep 20, 2024

🦋 Changeset detected

Latest commit: 1fb4e2d

The changes in this PR will be included in the next version bump.

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

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release labels Sep 20, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

Copy link
Contributor

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great addition, thanks

.changeset/lovely-pianos-breathe.md Outdated Show resolved Hide resolved
packages/astro/src/content/loaders/file.ts Outdated Show resolved Hide resolved
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @rgodha24 , this looks like an amazingly helpful addition to the file() loader!

I've added some comments and questions here about making a helpful changeset, which can also provide the basis for the documentation we'll need before this feature is released.

Mostly, my suggestions here are to give you an example of the kind of text/explanation I'd expect to see for this. I am the writer/editor, not the person who knows the feature, so it's up to you to help make this actually correct and meaningful! My suggestions are just to give you a model to use! Please do correct/improve as necessary!

Also, for @ascorbic - I've noticed this is for the main branch. Just checking that this will be for a minor 4.x release, and is not exclusively for the beta? This just determines exactly where/how we add to docs!

.changeset/lovely-pianos-breathe.md Outdated Show resolved Hide resolved
.changeset/lovely-pianos-breathe.md Outdated Show resolved Hide resolved
.changeset/lovely-pianos-breathe.md Outdated Show resolved Hide resolved
.changeset/lovely-pianos-breathe.md Outdated Show resolved Hide resolved
.changeset/lovely-pianos-breathe.md Outdated Show resolved Hide resolved
@rgodha24
Copy link
Contributor Author

tysm for the review on the changeset! I implemented all of your suggestions.

Also, for @/ascorbic - I've noticed this is for the main branch. Just checking that this will be for a minor 4.x release, and is not exclusively for the beta? This just determines exactly where/how we add to docs!

I think this should be for the 5.0 release. Does that mean the PR should be merging into next?

@ascorbic
Copy link
Contributor

@rgodha24 yes, if it's just for 5.0 then it'll need to be rebased on next

@rgodha24 rgodha24 changed the base branch from main to next September 25, 2024 16:46
@github-actions github-actions bot added pkg: example Related to an example package (scope) 🚨 action Modifies GitHub Actions docs pr labels Sep 25, 2024
@github-actions github-actions bot removed pkg: example Related to an example package (scope) 🚨 action Modifies GitHub Actions docs pr labels Sep 25, 2024
@rgodha24
Copy link
Contributor Author

@rgodha24 yes, if it's just for 5.0 then it'll need to be rebased on next

that was so painful but it should be good for review now!

Copy link
Contributor

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Thanks for sorting it out!

@ascorbic ascorbic merged commit 21b5e80 into withastro:next Sep 29, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants