foundation / panini

A super simple flat file generator.
Other
592 stars 104 forks source link

recognize subfolders for pageLayout parameter? #107

Closed mmilano closed 6 years ago

mmilano commented 7 years ago

Hi,

A question regarding the pageLayout option.

Using panini in gulp-based workflow.

I have a folder structure (limited expansion for illustration purposes)

/src/content/projectPages

I want all of the pages under staples/ to generate with the staple.html layout, including all subfolders.

Currently, it appears that I have to do this with explicit reference to subfolders

paniniOptions  {
    root: "./src/content/projectPages“, 
    layouts: "./src/content/projectPages/layouts/",
    pageLayouts: {
             “projects/bread”: "staples",
             “projects/cheese”: "staples",
             "projects/beer”: "staples",
         },
    partials: "./src/content/projectPages/partials/",
    helpers: "./src/content/projectPages/helpers/", 
    data: "./src/content/projectPages/data/"  
}

const paniniBuildSources     = "./src/content/projectPages/projects/**/*.html";

gulp.task('panini:build', function() {
    gulp
    .src(paniniBuildSources)
    .pipe(panini(paniniOptions))
    .pipe(gulp.dest(paniniBuildDestination));
});

Is there.syntax I am missing in order to have this work - with globbing? - so that the generation process adapts, even as the directories change? So that when a new staple folder is added (e.g. “coffee”), the dir does not need to be explicit added to the pageLayouts definition?

Something like this:

…
    layouts: "./src/content/projectPages/layouts/",
         // All pages inside [root]/projects should use the staples.html layout
    pageLayouts: {
             “projects/**/*”: "staples"
         },
…

In contrast, partials appear to already gather everything in partials/ subdirectories, albeit without globbing.

gakimball commented 7 years ago

If we implement this, here's the behavior I'm thinking:

When you specify a folder, it captures all pages in that folder and in subfolders.

However, if you then also specify a folder within a folder, it takes precedence.

So, using your folder structure as an example:

{
  "projects": "projects",
  "projects/staples": "staples"
}

With this configuration, all pages within pages/projectswould get the projects layout, except the pages in pages/projects/staples, which would get the staples layout. Does that make sense?

mmilano commented 7 years ago

Yes, i think that matches what I was thinking.

Actually, I've done some work on this - if interested, you can take a look at my panini fork to see what I've done and offer advice or review (both on this ability, and adding a few other pieces - a verbose debug flag, exposing the panini/hbs instance, and some other small tweaks).

https://github.com/mmilano/panini

I haven't had time to write tests for this, so I haven't created a PR.

gakimball commented 7 years ago

If you'd like to incorporate it into the v2.0-alt branch you definitely can! Look for the getPageData() method, which is where the layout calculation happens.

Looking at your fork, the only difference is we won't support glob patterns. If a page is in a folder, it counts. That keeps things simple.

gakimball commented 6 years ago

Implemented in v2 via 3a49a4213926e773c784ca30f6d30a367a21c5b5