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

gems/jekyll-datapage-generator-1.2.0/lib/jekyll-datapage-generator.rb:96:in `[]': no implicit conversion of String into Integer (TypeError) #78

Open
drewbroadley opened this issue Jul 14, 2020 · 2 comments
Labels
fixed? Issue fixed, waiting for confirmation

Comments

@drewbroadley
Copy link

drewbroadley commented Jul 14, 2020

I am not sure how this is working for anyone?

The value bring provided to the "data" variable on line 93 is an array, yet the code is treating it like a hash. This makes the do loop not needed.

I need to remove the loop and rename "data_spec" to "data" and it works.

`
data = site.config['page_gen']
if data

    index_files_for_this_data = data["index_files"] ? true : index_files
    template = data['template'] || data['data']
    name = data['name']
    name_expr = data['name_expr']
    dir = data['dir'] || data['data']
    extension = data['extension'] || "html"

    if site.layouts.key? template
      # records is the list of records defined in _data.yml
      # for which we want to generate different pages
      records = nil
      data['data'].split('.').each do |level|
        if records.nil?
          records = site.data[level]
        else
          records = records[level]
        end
      end
      if (records.kind_of?(Hash))
        records = records.values
      end

      # apply filtering conditions:
      # - filter requires the name of a boolean field
      # - filter_condition evals a ruby expression
      records = records.select { |r| r[data['filter']] } if data['filter']
      records = records.select { |record| eval(data['filter_condition']) } if data['filter_condition']

      records.each do |record|
        site.pages << DataPage.new(site, site.source, index_files_for_this_data, dir, record, name, name_expr, template, extension)
      end
    else
      puts "error (datapage_gen). could not find template #{template}" if not site.layouts.key? template
    end
  end

`

I'm using Jekyll 3.8.x and Ruby 2.7.0.

@avillafiorita
Copy link
Owner

Hi,
thanks for the report. Is the issue you are running into a configuration problem, namely the fact that page_gen is not specified in config.yml as an array of hashes?

Even if you have a single data structure for which you want to generate individual pages, you still need to define page_gen an array (of one element). Example:

  page_gen:
  - data: [name of a data set in _data]
    template: [name of template in _layouts: will be used to render pages]
    dir: [directory where filenames will be generated]
    index_files: [true|false]
    name: [field used to generate the filename]
    name_expr: [a Ruby expression to generate the filename (alternative to name)]
    title: [field used to generate the page title]
    title_expr: [a Ruby expression to generate the filename (alternative to title)]
    extension: [extension used to generate the filename]
    filter: [property to filter data records by]
    filter_condition: [a Ruby expression to filter data]

(note the "-" in front of data)

Let me know if it solves the issue or I'll dig more into it.

@avillafiorita avillafiorita added the fixed? Issue fixed, waiting for confirmation label Oct 16, 2020
@N7K4
Copy link

N7K4 commented Jan 11, 2021

Hey, I had a similiar error (no implicit conversion of String into Integer (TypeError)), but it was on my side!

Here is the part of my correct _config_yml.

page_gen-dirs: true

page_gen:
  - data: 'product_categories'
    template: 'product_category'
    name: 'name'
    dir: 'products'

Here is my WRONG _config_yml. I had the file extension (.json) included near the data. Just omit the file extension and the issue was gone for me.

page_gen-dirs: true

page_gen:
  - data: 'product_categories.json'
    template: 'product_category'
    name: 'name'
    dir: 'products'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed? Issue fixed, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants