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

Improve built-in loader docs #10147

Open
delucis opened this issue Dec 3, 2024 · 5 comments
Open

Improve built-in loader docs #10147

delucis opened this issue Dec 3, 2024 · 5 comments
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. help wanted Issues looking for someone to run with them!

Comments

@delucis
Copy link
Member

delucis commented Dec 3, 2024

📋 Explain your issue

Right now we document glob() and file() in a single “Built-in loaders” subheading, but we don’t have dedicated docs anywhere for each of these. Importantly this means we’re not documenting the glob pattern stuff in detail, including what pattern matching looks like.

Example use case

A user was trying to match a pattern that included a +. I suspect that may be interpreted in a specific way by the glob implementation, but docs don’t show or link to how glob patterns work.

@ArmandPhilippot
Copy link
Contributor

Another example that seems related:

  • loader: glob({ pattern: "*.mdx?", base: "./src/collections/blog" }) doesn't work
  • loader: glob({ pattern: "**/*.(md|mdx)", base: "./src/collections/blog/" }) works

It seems the culprit was the ?.
(see https://discord.com/channels/830184174198718474/1313620697846911140)

So yes maybe we should detail the pattern property a bit more.

@HiDeoo
Copy link
Member

HiDeoo commented Dec 4, 2024

Not sure if it could be worth or not, but when dealing with glob syntax, I usually link to the DO Glob Tool to test them and have a cheat sheet of the syntax: https://www.digitalocean.com/community/tools/glob

In the case of the ?, I assume it's because ? matches exactly one character so *.mdx? would match something like test.mdxy.

@ascorbic
Copy link
Contributor

ascorbic commented Dec 4, 2024

We use micromatch for matching

@sarah11918 sarah11918 added add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. help wanted Issues looking for someone to run with them! labels Dec 4, 2024
@sarah11918
Copy link
Member

Would happily accept more detail on the two built-in loaders! Probably on the Content Loaders API reference page makes sense?

See also my comment in Issue #10152 to make sure we are unifying the code samples with similar syntax throughout. This could do some double duty with that issue!

@sarah11918
Copy link
Member

sarah11918 commented Dec 19, 2024

On Talking and Doc'ing discussed that a super quick fix (while we're in the process of improving loader docs in general) would be to add a link to micromatch:

Current:
It accepts a pattern of entry files to match, and a base file path of where your files are located.

Proposal:
It accepts a pattern of entry files to match using glob patterns supported by micromatch, and a base file path of where your files are located.

Also, this line needs to be update to include YAML:

"Collections stored locally in your project or on your filesystem can have entries of Markdown, MDX, Markdoc, or JSON files:"

A longer-term fix would be to separate each built-in loader and give them each more attention and explain how they work e.g. that the path is relative to the file you're in, supported file types, unique id properties etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. help wanted Issues looking for someone to run with them!
Projects
None yet
Development

No branches or pull requests

5 participants