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

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

Open
jvanulde opened this issue Nov 17, 2020 · 1 comment
Open

Comments

@jvanulde
Copy link

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
Copy link
Owner

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

  • record-1
  • record-2

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.

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

No branches or pull requests

2 participants