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

Using yaml anchors crashes with sanitize_filename #68

Open
tgermer opened this issue Jan 28, 2020 · 4 comments
Open

Using yaml anchors crashes with sanitize_filename #68

tgermer opened this issue Jan 28, 2020 · 4 comments
Labels
fixed? Issue fixed, waiting for confirmation

Comments

@tgermer
Copy link

tgermer commented Jan 28, 2020

Hi
thank you for that great and very useful plugin.

jekyll serve --trace produce the following error:

_plugins/data_page_generator.rb:14:in `sanitize_filename': undefined method `tr' for ["BW", "-", "B"]:Array (NoMethodError)

My data-file:

- stg: Betriebswirtschaftslehre
  stg_kurz: &stg_kurz BW
  abschluss: Bachelor
  abschluss_kurz: &abschluss_kurz B
  grade: Bachelor of Administration
  grade_kurz: B.A.
  stg_kurz_abschluss_kurz: [*stg_kurz, '-', *abschluss_kurz]
- stg: Maschinenbau
  stg_kurz: &stg_kurz MA
  abschluss: Bachelor
  abschluss_kurz: &abschluss_kurz B
  grade: Bachelor of Enginering
  grade_kurz: B.Eng.
  stg_kurz_abschluss_kurz: [*stg_kurz, '-', *abschluss_kurz]

I configured in _config.yml

page_gen:
  - index_files: 
    data: stg
    template: stg
    name: stg_kurz_abschluss_kurz

Is't it possible to use anchors with jekyll-datapage_gen?
Can you please solve the problem or give me an advice?

Thank you very much in advance.
Tristan

@tgermer
Copy link
Author

tgermer commented Jan 30, 2020

I used https://learnxinyminutes.com/docs/yaml/ to learn about anchors.

@avillafiorita
Copy link
Owner

Hi
[sorry I took ages to get back to you]

the issue is with the data type used to generate the name. The plugin expects a string and the argument passed is an array.

One solution could be using join at the end of the array. Something like:

stg_kurz_abschluss_kurz: [*stg_kurz, '-', *abschluss_kurz].join

Another possibility could be that of using string interpolators, e.g.:

 stg_kurz_abschluss_kurz: "#{*stg_kurz}-#{*abschluss_kurz}"

but I am not sure whether you can use these constructs in a YAML file.
If you have not yet solved it and you want to give it a try, let me know if it works!
thanks!

@tgermer
Copy link
Author

tgermer commented Feb 28, 2020

Thank you very much for your replay @avillafiorita

Unfortunately none of your suggestions work.

I have found the following websites:

But even this one doesn't get me anywhere.
Do you have another tip?

@avillafiorita
Copy link
Owner

You can try changing the sanitize_filename function in lib/data_page_generator.rb as follows:

def sanitize_filename(name)
  if(name.is_a? Integer)
    return name.to_s
  end

  ### MANAGE ARRAYS IN INPUT ###
  if (name.is_a? Array)
      name = name.join("")
  end

  return name.tr("ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÑñÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž","AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz").downcase.strip.gsub(' ', '-').gsub(/[^\w.-]/, '')
end

the important lines are those checking whether the input is an Array and making it into a string, if it is.

If you do not care about replacing accented chars, you can directly return from the condition, that is:

  if (name.is_a? Array)
      return name.join("")
  end

let me know!

@avillafiorita avillafiorita added the fixed? Issue fixed, waiting for confirmation label Apr 16, 2020
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

2 participants