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

Body field is missing #13

Closed
kjetilhartveit opened this issue Feb 27, 2023 · 3 comments
Closed

Body field is missing #13

kjetilhartveit opened this issue Feb 27, 2023 · 3 comments

Comments

@kjetilhartveit
Copy link

kjetilhartveit commented Feb 27, 2023

Hello! It seems the body field is missing from my types. I haven't managed to track down the cause (don't have time now), but definitely happening in the transformType() function.

This console.log() could help in tracking down the cause.

if (widget.name === "body") {
    console.log('body types', types);
    // outputs: body types [ [ 'title: string;', 'date: string;' ], [] ]
    return types;
}

My config and generated type:

Config.yml

...
collections:
    - label: "Blog"
      name: "blog"
      folder: "content/post"
      create: true
      slug: "{{slug}}"
      fields:
          - { label: "Title", name: "title", widget: "string", required: true }
          - {
                label: "Publish date",
                name: "publishDate",
                widget: "datetime",
                required: true,
            }
          - {
                label: "Featured Image",
                name: "thumbnail",
                widget: "image",
                required: false,
            }
          - { label: "Body", name: "body", widget: "markdown", required: true }
          - {
                label: "Created date",
                name: "createdDate",
                widget: "datetime",
                required: true,
            }
...

Generated type:

export interface Blog {
  title: string;
  publishDate: string;
  thumbnail?: string;
  createdDate: string;
}
@kjetilhartveit kjetilhartveit changed the title Body fields is missing Body field is missing Feb 27, 2023
kjetilhartveit added a commit to kjetilhartveit/netlify-ts that referenced this issue Feb 27, 2023
@jsaari97
Copy link
Owner

Hello, thanks for checking out this library!

This is the intended behaviour, as body is a reserved field name in Netlify CMS, referring to the content after the frontmatter:

In files with frontmatter, one field should be named body. This special field represents the section of the document (usually markdown) that comes after the frontmatter.

Netlify CMS documentation

@kjetilhartveit
Copy link
Author

kjetilhartveit commented Feb 27, 2023

Yeah, I figured this was the reason in hindsight. It does assume you're using frontmatter though and that the metadata (frontmatter data) and content are separate interfaces. I guess it should work for most people though (me included), so I suggest perhaps just clarifying that the body field won't be included so that people (like me!) won't get confused.

Also: thanks for making this neat library :)

@jsaari97
Copy link
Owner

jsaari97 commented Mar 1, 2023

I'll definitely add a note of this in the documentation for future users.

@jsaari97 jsaari97 closed this as completed Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants