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

Provide a resolve key on fields to generate a default value when one is not provided #275

Open
ispringle opened this issue Jul 27, 2022 · 1 comment
Milestone

Comments

@ispringle
Copy link

My idea is to add a resolve key to the fields, so that when a value is not provided for that field the resolve function will fire, which then creates a default value for the field instead.

So for example I might have the following:

  fields: {
    title: {
      type: 'string',
      description: 'The title of the post',
      required: true,
    },
    url: {
      type: 'string',
      description: 'The URL of the post',
      required: false,
      resolve: (doc: any) => `/${doc._raw.flattenedPath}`,
  },
...

With this I can provide a URL value in the frontmatter of the markdown file if I am interested in providing a very specific URL for something, but otherwise it will generate the field automatically.

@schickling schickling added feature New feature or request pkg/source-files labels Aug 1, 2022
@schickling schickling added this to the Pre-1.0 milestone Aug 1, 2022
@schickling
Copy link
Collaborator

Thanks a lot for suggesting this feature/improvement. I agree it's a useful idea. I'll try to incorporate this suggestion in the coming releases.

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

No branches or pull requests

2 participants