moyus / laravel-mix-nunjucks

Laravel Mix extension to compile Nunjucks templates
MIT License
11 stars 5 forks source link

Files in 'hidden' directories are still rendered #12

Closed SamBrishes closed 2 years ago

SamBrishes commented 2 years ago

Hello,

I ran into the issue that your extension also rendered files within a _* directory, and I guess that's an Windows only (with node.js v18.0.0) issue due to the path separator \ passed to globby. At least I could fix it by adding the path replacement regex, on the patterns, on the remaining 2 ones as well:

    const patterns = [
      this.from.path().replace(/\\/g, '/'),
      "!" + path.posix.join(this.base.replace(/\\/g, '/'), `**/_**/*`),
      "!" + path.posix.join(this.base.replace(/\\/g, '/'), `**/_*`),
    ];

I guess this should be better placed directly in the constructor, where this.base gets assigned.

Thanks for your extension.

moyus commented 2 years ago

Cross platforms compatibility is really a pain in the ass 😂, I will fix it in the next release version.

SamBrishes commented 2 years ago

That's true. ^^

Could you also change the glob value from

"!" + path.posix.join(this.base, `**/_**/*`)

to

"!" + path.posix.join(this.base, `**/_**/**/*`)

since then it would be possible creating folders in hidden directories without the need of another underscore on each sub-folder... Like the following structure:

_partials/
    page/
        ...
    content/
        ...
    macros/
        ...

Without the changed glob, the sub-folders are rendered (at least on Windows).


I also tried the front-matter header today, and noticed a small bug (?): I guess this line should be formatter.body instead of template, otherwise the whole front-matter content is passed to the resulting HTML file. (at least if you declare a layout value within the front-matter header... without that you just get the No layout declared in ... message in the console.)

moyus commented 2 years ago

Fixed in v1.2.2