foundation/panini

Listing pages in menu list automatically as they are created

sensaetions opened this issue · 10 comments

Hello,
I have a desire to automatically list pages to a menu list. How can I go about doing this (creating the menu list of pages automatically) with panini when the pages are created in the /src/pages folder?

Thank you in advance!

I am also in need of this functionality.

You might want to create a custom handlebars helper for this as panini is based on handlebars.

Is there a way to add these helpers to the foundation stack to use them?
https://github.com/helpers/handlebars-helpers
Panini's custom helpers seem to require each helper have it's own .js file while these helpers have multiples in different .js files.

Yes, you can define it in the configuration.

https://github.com/foundation/panini/blob/develop/index.js#L27

https://github.com/foundation/panini/blob/develop/lib/loadHelpers.js#L6-L10

image

https://github.com/foundation/panini#usage

Panini's custom helpers seem to require each helper have it's own .js file while these helpers have multiples in different .js files.

I'm not 100% sure but this should not be a problem. But self-contained helpers are often probably better. Best it you try what works as I have not used Panini for a long time.

Ok, this is going to be a really noob question, but if I have the handlerbars-helpers package installed how do I point my config to those helpers? I shouldn't have to/can't point it to the node_modules folder its in right?
If they do require being individuals js thats going to make this a huge pain because now I need to port all the helpers I need -_-

Ok, this is going to be a really noob question, but if I have the handlerbars-helpers package installed how do I point my config to those helpers? I shouldn't have to/can't point it to the node_modules folder its in right?

Technically you can do it but it's better to copy the needed helpers into your project and reference this path like we do it in the readme.

image
According to this the helper ends up being the name of the js file. Maybe I can do it by proxy?
Include the handlebars-helper in the helpers/myhelper.js file and then call the helper function I want from there?
image
https://github.com/helpers/handlebars-helpers/tree/master/lib
Problem is like I said their helpers js files have multiple helpers in them. would I be able to do something like array.withSort if I got it to include the array.js from their helper libs?

According to this the helper ends up being the name of the js file. Maybe I can do it by proxy?
Include the handlebars-helper in the helpers/myhelper.js file and then call the helper function I want from there?

That shouldwork, yes, the required / imported packages / modules inside of them should be resolved by Nodejs itself so you can do anything you want in there, even require / import things from node_modules by package name or path).

Problem is like I said their helpers js files have multiple helpers in them. would I be able to do something like array.withSort if I got it to include the array.js from their helper libs?

Probably not possible, but I never tried to achieve something like this. Maybe there is some way.

I got this to work inside my own helper.js

var fs = require("handlebars-helpers/lib/fs")

module.exports = function (dir, filters) {
    var items = fs.readdir(dir, filters);
    for (var i = 0; i < items.length; i++) {
        items[i] = items[i].replace('src\\pages\\', '');
    }
    return items;
}

A bit modified from the main helper, but it works. So it is possible to, just kind of a pain.
Now my only problem is I can't iterate through the list I get

<div>
    <h1>Kutztown University</h1>
    <h2>Templates</h2>
    <ul class="zebra-striping">
        {{#readdir 'src/pages'}}
        {{#each this}}
        <li><a href="{{ this }}.html">{{ this }}</a></li>
        {{/each}}
        {{/readdir}}
    </ul>
</div>

I don't know how to actually go through it. If I just put {{ this }} in between the readdir it outputs it, but removing the each doesn't work