-
Notifications
You must be signed in to change notification settings - Fork 195
Closed
Description
I often have content in my source that is strictly used for processing. Right now Contentlayer skips that content because they have extra content not defined in the schema.
Consider the following content structure:
---
title: "Post #1"
imageSrc: tools/open-source-project/2022-03-09-open-source-project.png
---
I want to process this image on S3 using some image delivery service, so I do this:
export const Post = defineDocumentType(() => ({
name: "Post",
filePathPattern: `posts/**/*.md`,
fields: {
title: {
type: "string",
required: true,
},
},
computedFields: {
image: {
type: "string",
resolve: (doc) => {
// process image ...
},
},
},
}));
This doesn't work unless I also define imageSrc
as a field. I don't necessarily want to do that, because that's extra data in my output that I'm not going to use in my app (after processing).
I think there are two related ways to approach this. Both may be applicable:
- Option to ignore fields in the content source. (Note: I think it's fine if this has to be explicitly stated for better/easier validations.)
- Ability to overwrite an existing field as a computed field. It would also be great to be able to define
image
in the content source and as a computed field. (This would be a better first step IMO over the previous point, as it would solve for this case.)
Somewhat related to #11, depending on the path CL takes with image processing, but there's more here.
Metadata
Metadata
Assignees
Labels
No labels