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

Add support for named scopes ("computed collection") #71

Open
seancdavis opened this issue Dec 15, 2021 · 1 comment
Open

Add support for named scopes ("computed collection") #71

seancdavis opened this issue Dec 15, 2021 · 1 comment
Labels
feature New feature or request

Comments

@seancdavis
Copy link
Collaborator

Defining a document type brings the entirety of content for that document into the data object that we import into pages. I'm potentially importing much more information than I need to work with. It also forces me to write filtering logic in the template. And while this is a fairly typical pattern with Next.js, it's not a pleasant developer experience.

Proposal is to allow for named scopes when defining a document type. Something like this:

const Doc = defineDocumentType(() => ({
  name: "Doc",
  // ...
  fields: { /* ... */ },
  scopes: [
    {
      name: "mostRecent",
      resolve: (docs) => /* sorting/filtering logic ... */
    }
  ]
))

I don't have a strong opinion on how this would then be used, but maybe something like this:

import { allDocs, mostRecentDocs } from ".contentlayer/data"

The key decision here is finding a balance between being too magical (appending "Docs" to the scope name) and having to validate that scopes across all types be unique.

(Inpsired from a conversation with @smnh.)

@seancdavis seancdavis added the feature New feature or request label Dec 15, 2021
@schickling schickling changed the title Add support for named scopes Add support for named scopes ("computed collection") Jan 3, 2022
@ruchernchong
Copy link

Is there any update to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants