avillafiorita / jekyll-datapage_gen

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

Is it possible to use the root element key name as the page title? #90

Open jvanulde opened 3 years ago

jvanulde commented 3 years ago

For example I have the following data.yml:

records:
    record-1:
        title: My First Record
    record-2:
        title: My Second Record

My configuration for page-gen is as follows:

page_gen:
    - data: 'data.records'
       name: 'title'

This results in filenames like my-first-record.html but I require them to be like record-1.html.

How can I configure page-gen to do this?

avillafiorita commented 3 years ago

sorry for taking so long.

The simplest answer is restructuring the yaml, so that the key is accessible as a field, e.g., something like:

records:
  - id: record-1
    title: My First Record
  - id: record-2
    title: My Second Record

If that does not work for you, you could try with name_expr, using the same expression you would use in a for loop in Liquid, For instance on the assumption the following code:

{% for data in site.data.records.records %}
- {{ EXPR_TO_GET_KEY }}
{% endfor %}

generates

then a configuration which might work is:

page_gen:
    - data: 'data.records'
      name_expr: EXPR_TO_GET_KEY 

I hope it helps. Let me know if it answer your question.