avillafiorita / jekyll-datapage_gen

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

datapage_url usage throwing undefined method `tr' #85

Open sahilk opened 3 years ago

sahilk commented 3 years ago

Not sure if I'm using it correctly. {{ page_name | datapage_url: dir }} is mentioned in the docs for generating links to generated pages. I use name_expr in _config.yml to generate the files in an acts folder, so is {{ name_expr | datapage_url: acts }} the right way to do this?

Liquid Exception: undefined method `tr' for nil:NilClass in index.html
Error: undefined method `tr' for nil:NilClass

Would you like to see the --trace output as well?

(Sorry, but I'm also not entirely clear on how to use this liquid tag in my template to generate links for each of the items from the data file.)

As a fallback, I'm currently using slugify to create the page URLs manually, which works just fine, but raising this here to be sure if I'm doing something wrong or if there's a bug.

avillafiorita commented 3 years ago

Hi, it is indeed a bug, datapage_url is not able to manage name_expr. Thanks for reporting, I will look into it.

To give a bit of context, datapage_url has not been updated for a while and, in particular, it is not "aware" of name_expr.

avillafiorita commented 3 years ago

Problem: the value of name_expr cannot be directly used in Liquid.

To generate the link, therefore, we need to:

  1. find the record for which we want to generate the URL (this requires an id for the record and the name of the data file in which the record is stored)
  2. get the data for the record (yaml)
  3. check the configuration for the data file and generate the link according to it (e.g., by looking at page_gen and applying the appropriate piece of code to data; that is, getting name or executing name_expr)

Current syntax of datapage_url is inadequate. Proposal for new syntax:

{{ | datapage_url_for: }}

where:

is a unique identifier of the record for which we want to generate the URL. It should probably be the value assigned to the `name` field in the record (even if `name_expr` is used). [Alternatively, a new key, `id`, has to be added to the configuration.] is the name of the data structure (= data file) to which the record belongs. The name of the data is needed to 1. read the appropriate specification in `page_gen` 2. read the content of the record (for instance to apply name_expr)