Skip to content

Use content collections instead of astro.glob [issue 2945]#3182

Merged
sarah11918 merged 8 commits into
withastro:mainfrom
donovangg:iss2945
May 12, 2023
Merged

Use content collections instead of astro.glob [issue 2945]#3182
sarah11918 merged 8 commits into
withastro:mainfrom
donovangg:iss2945

Conversation

@donovangg
Copy link
Copy Markdown
Contributor

What kind of changes does this PR include?

  • New or updated content

Description

  • Closes Don't use Glob with content collections #2945

  • What does this PR change?
    Adds another section: Astro.glob() vs Content collections.
    Mention content collections and src/content directory is the way to go for md and mdx.

  • Did you change something visual? A before/after screenshot can be helpful.
    content collection

I apologize for my writing lol.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 5, 2023

Deploy Preview for astro-docs-2 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a0148ba
🔍 Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/645e1d031637f7000786c31a
😎 Deploy Preview https://deploy-preview-3182--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@sarah11918 sarah11918 added the improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes) label May 5, 2023
Comment thread src/content/docs/en/guides/imports.mdx Outdated
Copy link
Copy Markdown
Member

@yanthomasdev yanthomasdev left a comment

Choose a reason for hiding this comment

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

Thanks @donovangomez, that's a lovely contribution. I added a small suggestion for you 🙌

Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>
Comment thread src/content/docs/en/guides/imports.mdx Outdated

#### `Astro.glob()` vs Content Collections

[Content collections](/en/guides/content-collections/) were introduced in `astro@2.0.0`. It's the best way to work with Markdown and MDX files in an Astro project. If your directory contains only Markdown and MDX files, it's best to use Content collections and the `src/content` directory.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this @donovangomez!

I’ll let @sarah11918 decide here, but I think we don’t generally tell people what is “best” but try to describe some differences and allow people to decide for themselves. Hard to do in a short paragraph where we don’t want to repeat to much of what’s in the content collections guide itself. Maybe something like this?

Suggested change
[Content collections](/en/guides/content-collections/) were introduced in `astro@2.0.0`. It's the best way to work with Markdown and MDX files in an Astro project. If your directory contains only Markdown and MDX files, it's best to use Content collections and the `src/content` directory.
[Content collections](/en/guides/content-collections/) provide a `getCollection()` API for loading multiple files instead of `Astro.glob()`. If you are working with Markdown and MDX files, you can store them in the `src/content/` directory to take advantage of content collection features.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @delucis ! My bad that was totally mentioned in the writing guide. I do like the rewrite a lot more, it's more neutral.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yup, @delucis' edit is much more in keeping with our docs style. I'm going to adjust it just a bit, to help make it more future-proof (e.g. Markdoc...) but it's absolutely the way to go! 🙌

Copy link
Copy Markdown
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.

Thanks for grabbing this issue and adding this very helpful contribution, @donovangomez! 🚀

I've left some suggestions to massage this into docs style. What does everyone think?

Comment thread src/content/docs/en/guides/imports.mdx Outdated
Comment thread src/content/docs/en/guides/imports.mdx Outdated

#### `Astro.glob()` vs Content Collections

[Content collections](/en/guides/content-collections/) were introduced in `astro@2.0.0`. It's the best way to work with Markdown and MDX files in an Astro project. If your directory contains only Markdown and MDX files, it's best to use Content collections and the `src/content` directory.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yup, @delucis' edit is much more in keeping with our docs style. I'm going to adjust it just a bit, to help make it more future-proof (e.g. Markdoc...) but it's absolutely the way to go! 🙌

Comment thread src/content/docs/en/guides/imports.mdx Outdated
@sarah11918
Copy link
Copy Markdown
Member

Going to tag in @yan-thomas, @kevinzunigacuellar, @ElianCodes and @delucis in case anyone wants to help refine the text here! 🙌

Comment thread src/components/PageContent/PageContent.astro Outdated
@sarah11918
Copy link
Copy Markdown
Member

Finally the checks pass! Sorry for the delay @donovangomez , but GitHub was acting up and then we needed to implement a fix for some of our automated checks.

NOW we can finally welcome you to Team Docs, and thanks again for jumping on a much needed issue! 🙌

@sarah11918 sarah11918 merged commit 69f7ff2 into withastro:main May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't use Glob with content collections

5 participants