avillafiorita / jekyll-datapage_gen

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

Support for custom data mapping #110

Open mooperd opened 3 years ago

mooperd commented 3 years ago

Hello,

Is it possible to use custom data mapping? For example I would like to be able to control other elements - specifically the subtitle, and perhaps show_sidebar which is part of the ??front matter??. Please excuse my ignorance - I'm very new to jekyll.

Right now subtitle: scenario seems to be ignored

page_gen:
- data: skill-sprints
  template: skill-sprint
  dir: skill-sprints
  index_files: false
  name: url
  title: name
  subtitle: scenario
---
title: Title Text
subtitle: Subtitle Text
layout: category
show_sidebar: false
---

Thanks,

Andrew

jakubheglas commented 2 years ago

+1 here! Specifically not being able to set description and other front matter SEO related items is very limiting.

avillafiorita commented 2 years ago

Hi - thanks for the feedback. There is a workaround. I am not even sure it is an issue with the plugin.

More in details: substitution of liquid tags does not seem to be recursively applied. In other words: you can reference and use data fields directly in your layouts, but you cannot define a front-matter variable in a layout, based on a data field and have its content replaced in the layout. Hence if you use the data fields directly, you should be fine. (Detailed explanation below.)

Whether this is a bug of the plugin, a bug of Jekyll or a feature of both, to be honest, I can't tell.

Detailed Explanation

Consider the example directory and let us use a new layout:

- data: 'members'
  template: 'default'
  dir: 'metadata'
  name: 'full_name'

where _layouts/default.html= is.

<html>
  <head>
    <title>{{page.title}}</title>
    <meta author="{{page.full_name}}">
    <meta description="{{page.description}}">
  </head>
  <body>
    {{content}}
  </body>
</html>

Notice that the author field references a field in member.yml, while, at the moment, the description field does not reference any field. The generation works fine and the metadata is correctly generated, that is, we get:

[...]
<meta author="Adolfo Villafiorita">
[...]

The line referencing {{page.description}} will result in the empty string, since there is no description field in members.yml.

However, if we use one level of "indirection", that is, we define variables in the front-matter of a layout and try to use them in another layout, the liquid tags are not replaced.

That is, if:

- data: 'members'
  template: 'metadata'
  dir: 'metadata'
  name: 'full_name'

where _layouts/metadata.html is:

---
title: {{page.name}}
layout: default
description: Homepage of {{page.full_name}}
---
{{ content }}

Then we get the following:

[...]
<meta author="Adolfo Villafiorita">
<meta description="Homepage of {{page.full_name}}">
[...]

That is, {{description}} in default.html gets substituted with its value defined in metadata.html, but {{page.full_name}} in the definition of the description field does not.

ttuhub commented 1 year ago

Anybody think of a way to solve this problem using this plugin

https://github.com/gemfarmer/jekyll-liquify