Repository: contentlayerdev/contentlayer

Issue #594: When defining the `number` field at the end of the frontmatter, it doesn't parse.
Created: 2023-11-11T19:04:49Z
Hi! Very minor issue but found something that might be worth fixing. When I don't define it at the end of the line, it works fine. I'm also using Windows so not sure if that's an issue with line-endings.
When I define my number field at the end of the frontmatter:
---
title: ScolioVis
date: 2023-04-14
description: 'my undergrad thesis: automatic assessment of scoliosis'
demoURL: https://myapp.app/
featuredImage: /imgs/scoliovis_featured-project-img.webp
featureOrder: 1
---

Logs:
Warning: Contentlayer might not work as expected on Windows
 ✓ Ready in 8.1s
Contentlayer config change detected. Updating type definitions and data...
Warning: Found 1 problems in 3 documents.

 └── 1 documents contain field data which didn't match the structure defined in the document type definition. (Skipping documents)
     
     • "projects/scoliovis.mdx" of type "Project" has the following incompatible fields:
       • featureOrder: "1\r" 


As a workaround, you can just define the number above a field with a string type. ☑️
---
title: ScolioVis
date: 2023-04-14
description: 'my undergrad thesis: automatic assessment of scoliosis'
demoURL: https://myapp.app/
featureOrder: 1
featuredImage: /imgs/scoliovis_featured-project-img.webp
---


The document type I'm using:
export const Project = defineDocumentType(() => ({
  name: 'Project',
  filePathPattern: `**/projects/*.mdx`,
  contentType: 'mdx',
  fields: {
    title: { type: 'string', required: true },
    description: { type: 'string', required: true },
    date: { type: 'date', required: true },
    featuredImage: { type: 'string', required: true },
    featureOrder: { type: 'number' },
    demoURL: { type: 'string' },
    featuredYoutubeURL: { type: 'string' },
    tags: { type: 'list', of: { type: 'string' } },
  },
  computedFields: {
    slug: {
      type: 'string',
      resolve: (post) => `${post._raw.flattenedPath.split('/').at(1)}`,
    },
    url: {
      type: 'string',
      resolve: (project) => `/content/projects/${project._raw.flattenedPath}`,
    },
  },
}))

Duplicate issue #543: YAMLParseError occurs with CRLF document endings followed by a quotation mark or similar characters
Created: 2023-08-30T13:40:16Z
---
title: "If it ends with a quotation mark, it doesn't work."
---
## ...

A document like the above throws the YAMLParseError when CRLF is used.
It is because gray-matter gives the custom YAML engine a string that ends with '\r'.
The problem can be easily resolved by a simple check on the last character, like below.
matter(markdownString, {
        engines: {
          // Provide custom YAML engine to avoid parsing of date values https://github.com/jonschlinkert/gray-matter/issues/62)
          yaml: (str) => {
            if(str.length > 0 && str[str.length-1] == '\r'){
              str = str.slice(0, str.length-1);
            }
            return yaml.parse(str)
          }
        },
      }),

line 223 in "/node_modules/@contentlayer/source-files/src/fetchData/makeCacheItemFromFilePath.ts"
So, I'm wondering whether the issue mentioned above would be addressed in future versions,
or should I make all my documents use LF instead of CRLF?

Closing comment (2024-02-07T19:14:35Z): Still happening. Would be great if looked at... It's similar to #594. The issue is different, but the cause is the same.