avillafiorita / jekyll-datapage_gen

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

IDEA: Create also an index.html file on the group level, not only on the subfolders. #94

Open N7K4 opened 3 years ago

N7K4 commented 3 years ago

I like this plugin, it saved me a lot of time! Many thanks.

But I reconginzed one issue. The data generator created only the index.html for the subfolders, not also for the group folder.

My config file _config.yml.

plugins:
  - jekyll-datapage-generator

page_gen-dirs: true

page_gen:
  - data: 'product_categories'
    template: 'product_category'
    name: 'name'
    dir: 'products'

My reduced data file product_categories.json.

[
  {
    "name": "CatA"
  }, {
    "name": "CatB"
  }, {
    "name": "CatC"
  }, {
    "name": "CatD"
  }
]

Will generate the following structure under _site.

.
├── products
│   ├── cata
│   │   └── index.html
│   ├── catb
│   │   └── index.html
│   ├── catc
│   │   └── index.html
│   └── catd
│       └── index.html

But when the user navigate to https://blog.domain.tld/products/ there is nothing (404 HTML error). Because there is no index.html on group folder, or no redirect to an other page.

Would it be possible to generate also the index.html on the group folder products in my case? So that would be the output?

.
├── products
│   ├── cata
│   │   └── index.html
│   ├── catb
│   │   └── index.html
│   ├── catc
│   │   └── index.html
│   ├── catd
│   │   └── index.html
│   └── index.html

MY WORKAROUND

Create a file products.md in the pages folder.

---
layout: page
title: Producs
permalink: /products/
---
<ul>
{% for cat in site.data.product_categories %}
  <li><a href="{{ cat.name | datapage_url: '.' }}" target="_self">{{cat.name}}</a></li>
{% endfor %}
</ul>

This will generate a index.html under _site/products.

desirtech commented 3 years ago

Interesting Idea. What would go in the group index file? DataPage correlates one page per record, nested or not. To 'wrap' up the collection into a hub page, like you did, you could make another record with a 'permalink' prop.

- name: cata 
  perma: /products # /:collection/ if collections enabled

OR Add plugin option from group_index: true and have it output something like:


--- 
permalink: /{{ site.page_gen[0].dir }}/
title: /:name/ 
--- 

{% for item in site.data.[{{ collection.name }}] %}
 <li> 
  <a href="{{ item.name | datapage_url: '-' }}">{{ cat.name}}</a>
 </li>
{% endfor %}

Personally, I'd just use another data_entry and add a permalink variable to it's template file.