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

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

Open
N7K4 opened this issue Jan 11, 2021 · 1 comment

Comments

@N7K4
Copy link

N7K4 commented Jan 11, 2021

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

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. 

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