avillafiorita / jekyll-datapage_gen

Generate one page per yaml record in Jekyll sites.
367 stars 79 forks source link

NoMethodError: undefined method `each' for nil:NilClass #96

Closed inetbiz closed 3 years ago

inetbiz commented 3 years ago

I'm running into generating pages because your plug-in fouls out with the <head> content in the include file for default layout.

Default layout

---
layout: compress
---
<!DOCTYPE html>
<html lang="{{site.language}}">
   {% include head.html %}
  <body>
  </body>
</html>

Single Layout

---
layout: default
---
{% include header.html %}
      <div class="banner">
         <div class="container">
            {% include banner.html %}
         </div>
      </div>
      {% assign product = site.data.products[sku] %}

Output Error

 bundle exec jekyll build --trace
Configuration file: /home/denverpr/furn1/_config.yml
            Source: /home/denverpr/furn1
       Destination: /home/denverpr/furn1/public
 Incremental build: disabled. Enable with --incremental
      Generating...
bundler: failed to load command: jekyll (/home/denverpr/rubyvenv/ruby/2.6/bin/jekyll)
NoMethodError: undefined method `each' for nil:NilClass
  /home/denverpr/furn1/_plugins/jekyll-datapage-generator.rb:180:in `block in generate'
  /home/denverpr/furn1/_plugins/jekyll-datapage-generator.rb:142:in `each'
  /home/denverpr/furn1/_plugins/jekyll-datapage-generator.rb:142:in `generate'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/lib/jekyll/site.rb:193:in `block in generate'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/lib/jekyll/site.rb:191:in `each'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/lib/jekyll/site.rb:191:in `generate'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/lib/jekyll/site.rb:79:in `process'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/lib/jekyll/command.rb:28:in `process_site'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/lib/jekyll/commands/build.rb:65:in `build'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/lib/jekyll/commands/build.rb:36:in `process'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `block in process_with_graceful_fail'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `each'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `process_with_graceful_fail'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/lib/jekyll/commands/build.rb:18:in `block (2 levels) in init_with_program'
  /home/denverpr/rubyvenv/ruby/2.6/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `block in execute'
  /home/denverpr/rubyvenv/ruby/2.6/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `each'
  /home/denverpr/rubyvenv/ruby/2.6/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `execute'
  /home/denverpr/rubyvenv/ruby/2.6/gems/mercenary-0.4.0/lib/mercenary/program.rb:44:in `go'
  /home/denverpr/rubyvenv/ruby/2.6/gems/mercenary-0.4.0/lib/mercenary.rb:21:in `program'
  /home/denverpr/rubyvenv/ruby/2.6/gems/jekyll-4.2.0/exe/jekyll:15:in `<top (required)>'
  /home/denverpr/rubyvenv/ruby/2.6/bin/jekyll:23:in `load'
  /home/denverpr/rubyvenv/ruby/2.6/bin/jekyll:23:in `<top (required)>'

Data

# Best Books of the 20th Century according to goodreads
# (Notice that "The Catcher in the Rye" appears twice in the original listing)
- author: Harper Lee
  title: To Kill a Mockingbird
  read: no
  rating: 4.26
  year: 1960
  position: 1
- author: George Orwell
  title: 1984
  read: yes
  rating: 4.15
  year: 1949
  position: 2
- author: F. Scott Fitzgerald
  title: The Great Gatsby
  read: no
  rating: 3.89
  year: 1925
  position: 3
- title: "Harry Potter and the Sorcerer's Stone (Harry Potter, #1)"
  author: J.K. Rowling 
  read: no
  rating: 4.45
  position: 4
  year: 1998
- author: George Orwell
  title: Animal Farm
  read: yes
  rating: 3.88
  year: 1945
  position: 5
- author: J.R.R. Tolkien
  title: The Hobbit
  read: no
  rating: 4.25
  year: 1937
  position: 6
- author: Anne Frank
  title: The Diary of a Young Girl
  rating: 4.10
  read: no
  position: 7
- author: J.D. Salinger
  title: The Catcher in the Rye
  read: no
  rating: 3.79
  year: 1951
  position: 8
- author: Ray Bradbury
  title: Fahrenheit 451
  read: yes
  rating: 3.98
  year: 1953
  position: 9
- author: John Steinbeck
  title: The Grapes of Wrath
  read: yes
  rating: 3.93
  year: 1939
  position: 10
- author: C.S. Lewis
  title: The Lion, the Witch, and the Wardrobe (Chronicles of Narnia, \#1)
  read: no
  rating: 4.19
  year: 
  position: 11
- author: Gabriel García Márquez
  title: One Hundred Years of Solitude
  read: yes
  rating: 4.04
  year: 1967
  position: 12
- author: Aldous Huxley
  title: Brave New World
  read: yes
  rating: 3.97
  position: 13
- author: Antoine de Saint-Exupéry
  title: The Little Prince
  read: yes
  rating: 4.29
  year: 1943
  position: 14
- author: John Steinbeck 
  title:  Of Mice and Men
  rating: 3.84
  read: yes
  year: 1937
  position: 16

### Versions
Jekyll 4.2.0
ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-linux]
avillafiorita commented 3 years ago

Did you downloaded the sources directly from GitHub with "save as"? In case make sure you choose the "raw" option first, or you might end up with an HTML rather than a ruby file.

Consider also using the gem, which is simpler to install.

Let me know if it solves your issue or we will dig deeper.

avillafiorita commented 3 years ago

_config.yml?

inetbiz commented 3 years ago

Config Section

# DATA GEN
page_gen-dirs: true

page_gen:
- data: products.study
  template: single
  dir: products/office
  index_files: true
  name: filename
  title: name
  extension: html
avillafiorita commented 3 years ago

ok, make sure all the required data (products.study, _layouts/single.html) exist. Make also sure there are a "filename" and a "name" field in your records. If in doubt, you can add

debug:true

and run again, it should show what is going on.

avillafiorita commented 3 years ago

the data does not look like an array. This is the issue, I believe. Run with debug:true and you will see.

avillafiorita commented 3 years ago

I am closing this issue.

There is no need to use this plugin if the input data is not an array.

inetbiz commented 3 years ago

@avillafiorita I've tried using sample data from your own repo. I still get NoMethodError: undefined method each for nil:NilClass That error output is listed further up in this thread.

avillafiorita commented 3 years ago

I just downloaded the repo and run the example available in the example directory. It works fine on my machine.

Start from the site in the example directory (rather than using only the data file) and then move on with your own website. Make sure you have _config.yml, YAML data and a template in _layouts as described in the documentation.

Read the documentation if in doubt. Use the debug option to understand what is causing the error.