metalsmith / layouts

A metalsmith plugin for layouts
MIT License
116 stars 49 forks source link

Layouts in sub directories cannot find partials #129

Closed kellyChap closed 7 years ago

kellyChap commented 7 years ago

I have the following folder structure within my project:

root |-- build |-- content | |-- index.md | |-- robots.txt | |-- sitemap.xml | |-- state-of-storage-data.md | |-- water-environment-data.md | |-- img | |-- scripts | |-- water-environment-data | | |-- rain-and-river-data.md | | |-- rain-and-river-data | | | |-- scheme.md |-- layouts | |-- index.html | |-- robots.html | |-- sitemap.html | |-- partials | | |-- default.html | | |-- footer.html | | |-- header.html | | |-- home.html | | |-- navigation.html | |-- rain-and-river-data | | |-- scheme.html

And I am getting the following error when transforming the content/water-environment-data/rain-and-river-data/scheme.md:

  metalsmith-layouts stringifying file: index.md +0ms
  metalsmith-layouts found new template: root\layouts\index.html +0ms
  metalsmith-layouts stringifying file: robots.txt +0ms
  metalsmith-layouts found new template: root\layouts\robots.html +0ms
  metalsmith-layouts stringifying file: sitemap.xml +0ms
  metalsmith-layouts found new template: root\layouts\sitemap.html +0ms
  metalsmith-layouts stringifying file: state-of-storage-data.md +0ms
  metalsmith-layouts stringifying file: water-environment-data.md +0ms
  metalsmith-layouts stringifying file: water-environment-data\rain-and-river-data.md +10ms
  metalsmith-layouts stringifying file: water-environment-data\rain-and-river-data\scheme.md +0ms
  metalsmith-layouts found new template: root\layouts\rain-and-river-data\scheme.html +0ms
  metalsmith-layouts converting file: index.md +0ms
  metalsmith-layouts converting file: robots.txt +0ms
  metalsmith-layouts converting file: sitemap.xml +0ms
  metalsmith-layouts converting file: water-environment-data\rain-and-river-data\scheme.md +0ms
{ Error: ENOENT: no such file or directory, open 'root\layouts\rain-and-river-data\partials\default.html'
    at Error (native)
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'root\\layouts\\rain-and-river-data\\partials\\default.html' }

My configuration is as follows:

 "metalsmith-layouts": {
   "engine": "handlebars",
   "directory": "layouts",
   "partials": "layouts/partials/",
  "partialExtension": ".html"
 },

layouts/rain-and-river-data/scheme.html contains:

 {{#extend "default"}}
  {{#content "main"}}
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="col-xs-12">
                <h3>{{ title }}</h3>
                <p>Content to be entered here</p>
            </div>
        </div>
    </div>
  {{/content}}
{{/extend}}

content/water-environment-data/rain-and-river-data/scheme.md:

title: Rain & River by Scheme url: /water-environment-data/rain-and-river-data description: Rain & River data Page layout: rain-and-river-data/scheme.html permalink: false function: home

It is expected that default.html gets picked up from layout/partials folder.

It appears that it is looking for partials that are relative to the content directory, rather than using the absolute path.

At the moment it only works if I place all files in the layouts directory only and no sub-directories.

Please help.

ismay commented 7 years ago

Hi @kellyChap. Apologies, but the issues aren't for troubleshooting build problems. Try posting a reduced testcase on stack overflow or asking for help in the metalsmith slack channel.

Currently all unit tests are passing, so it's very likely that it has something to do with your build and not with metalsmith layouts. However, if you do find a bug, please submit a PR with a failing test and I'll take a look. Thank you!