Ollie_W
Ollie_W

Reputation: 337

Jekyll config.yml did not find expected key while parsing a block mapping

I'm getting this error in the command line terminal:

did not find expected key while parsing a block mapping at line 18 column 7

My jekyll _config.yml YAML file looks like this:

title: Oliver Williams - Portfolio
url: "http://yourdomain.com" # the base hostname & protocol for your site

# Build settings
markdown: kramdown
permalink: /:title

defaults:
  -
    scope:
      path: "" # an empty string here means all files in the project
      type: "posts" # previously `post` in Jekyll 2.2.
    values:
      layout: "post"

       -
    scope:
      path: "" # an empty string here means all files in the project
      type: "pages" 
    values:
      layout: "page"

Upvotes: 8

Views: 21938

Answers (4)

Sean Phillips
Sean Phillips

Reputation: 1

I had to replace "but wait, there's more!" with "but wait, there is more!", which was actually enclosed in single quotes, the apostrophe in the text string breaking it!

Upvotes: -1

pk_code
pk_code

Reputation: 2766

Somewhere in your YAML, you have extra spaces (or not enough spaces) before a key value.

this YAML linter may help as it tells you a correct line with error(if any): https://jsonformatter.org/yaml-formatter.

Upvotes: 0

Anthon
Anthon

Reputation: 76599

The problem is in your second list element for defaults. The marker is indented too much, possible because you used a tab instead of a two spaces.

There is no reason to put the mappings that are elements of those lists on a separate line. You also don't have to indent list elements if the list is a mapping value. Nor is it necessary to quote simple scalars like "posts", "page", etc. (You don't have that for your title value either)

So you can do:

title: Oliver Williams - Portfolio
url: http://yourdomain.com   # the base hostname & protocol for your site

# Build settings
markdown: kramdown
permalink: /:title

defaults:
- scope:
    path: ''         # an empty string here means all files in the project
    type: posts      # previously `post` in Jekyll 2.2.
  values:
    layout: post
- scope:
    path: ''         # an empty string here means all files in the project
    type: pages
  values:
    layout: page

which is equivalent to your input (corrected for the overindented -)

Upvotes: 6

David Jacquel
David Jacquel

Reputation: 52809

I'm not sure of your formating/indentation for _config.yml.

This one is correct :

title: Oliver Williams - Portfolio
url: "http://yourdomain.com"
markdown: kramdown 
permalink: /:title

defaults: 
  - 
    scope: 
      path: "" 
      type: "posts" 
    values: 
      layout: "post"
  -
    scope:
      path: ""
      type: "pages" 
    values:
      layout: "page"

Upvotes: 8

Related Questions