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

Gray-matter error when using frontmatter in .njk layout #1208

Open
matt-auckland opened this issue May 24, 2020 · 3 comments
Open

Gray-matter error when using frontmatter in .njk layout #1208

matt-auckland opened this issue May 24, 2020 · 3 comments
Labels
bug: plugin A report for a third party plugin

Comments

@matt-auckland
Copy link

matt-auckland commented May 24, 2020

I'll preface this with the fact I'm not sure if this is a case of the docs being wrong, or a bug in 11ty.

I'm getting an error when I try to use frontmatter in .njk files, this is what is shown in the 11ty docs, so I assume it's possible (I haven't worked with njk before)

To Reproduce

  1. Follow the docs here (https://www.11ty.dev/docs/layouts/) and create a new layout (myLayout.njk) and a new markdown file (content-using-layout.md)
  2. Use the example code from the docs for the files
  3. Run eleventy --serve
  4. See error
File added: _includes/myLayout.njk
Problem writing Eleventy templates: (more in DEBUG output)
> gray-matter engine "title: My Rad Blog ---" is not registered

`Error` was thrown:
    Error: gray-matter engine "title: My Rad Blog ---" is not registered
        at module.exports (/Users/matt/.config/yarn/global/node_modules/gray-matter/lib/engine.js:6:11)
        at module.exports (/Users/matt/.config/yarn/global/node_modules/gray-matter/lib/parse.js:8:18)
        at parseMatter (/Users/matt/.config/yarn/global/node_modules/gray-matter/index.js:109:17)
        at matter (/Users/matt/.config/yarn/global/node_modules/gray-matter/index.js:50:10)
        at TemplateLayout.read (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/TemplateContent.js:82:16)
        at async TemplateLayout.getFrontMatterData (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/TemplateContent.js:141:7)
        at async TemplateLayout.getTemplateLayoutMapEntry (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/TemplateLayout.js:55:24)
        at async TemplateLayout.getTemplateLayoutMap (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/TemplateLayout.js:66:20)
        at async TemplateLayout.getData (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/TemplateLayout.js:89:15)
        at async Template.getData (/Users/matt/.config/yarn/global/node_modules/@11ty/eleventy/src/Template.js:244:28)
Wrote 0 files in 0.04 seconds (v0.11.0)

Expected behavior
11ty renders the markdown using the layout, as described in the docs.

Environment:

  • OS and Version: Mac 10.15.4
  • Eleventy Version 0.11.0
@projckt
Copy link

projckt commented May 25, 2020

I was facing the same problem. For me, the error was occurring because the NJK prettier plugin in VS Code converted valid syntax into single line while saving.

That is

---
title: My Rad Blog
---

was converted to (invalid)

--- title: My Rad Blog ---

I disabled the plugin for now. However, I am looking for a better solution.

@matt-auckland
Copy link
Author

I was facing the same problem. For me, the error was occurring because the NJK prettier plugin in VS Code converted valid syntax into single line while saving.

...

I disabled the plugin for now. However, I am looking for a better solution.

Oh yeah that was it! Maybe a warning could be added to the docs 🤔

@winston0410
Copy link

Facing the same issue here. Is there any beautifier can handle this properly? I am using Atom.

@zachleat zachleat added bug: plugin A report for a third party plugin and removed needs-triage labels Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: plugin A report for a third party plugin
Projects
None yet
Development

No branches or pull requests

4 participants