metalsmith / layouts

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

From v2.0.0 the metalsmith example static-site is not working #174

Closed mcapodici closed 3 years ago

mcapodici commented 4 years ago

To reproduce:

git clone https://github.com/segmentio/metalsmith
cd metalsmith
cd examples
cd static-site
npm i
node ./index.js

This works, now edit package.json and replace "metalsmith-layouts": "^1.4.1" with "metalsmith-layouts": "^2.0.0"

npm i
node ./index.js

Result:

    if (err) { throw err; }
               ^

Error: no files to process. See https://www.npmjs.com/package/metalsmith-layouts#no-files-to-process
    at Ware.<anonymous> (c:\temp\metalsmith\examples\static-site\node_modules\metalsmith-layouts\lib\index.js:133:12)
    at Ware.<anonymous> (c:\temp\metalsmith\examples\static-site\node_modules\wrap-fn\index.js:45:19)
    at Immediate.next (c:\temp\metalsmith\examples\static-site\node_modules\ware\lib\index.js:85:20)
    at Immediate.<anonymous> (c:\temp\metalsmith\examples\static-site\node_modules\wrap-fn\index.js:121:18)
    at processImmediate (internal/timers.js:439:21)

Obviously being a major version upgrade there could be a breaking change, but I couldn't see what from the release notes. If there is a breaking change I can raise an issue with https://github.com/segmentio/metalsmith to upgrade their example.

madooei commented 4 years ago

I had the same issue and here is how I fixed it.

  1. jstransformer-handlebars is now a dependency that is not installed through metalsmith-layouts

Under the hood this plugin uses jstransformers to render your layouts. Since there are over a 100 jstransformers we don't install them automatically, so you'll need to install the jstransformer for the language you want to use. For example, to render handlebars you would install jstransformer-handlebars, etc.

npm install jstransformer-handlebars --save
  1. jstransformer-handlebars expects the template files extensions to be hbs so you must rename all the *.html files in the layouts folder to *.hbs.

  2. You must now also update the layout property in the YAML front-matter of all the *.md files in the src folder. For example, in first-post.md

- layout: post.html
+ layout: post.hbs

It will work then! So, yes: you should probably raise an issue with https://github.com/segmentio/metalsmith to upgrade their example.

ismay commented 3 years ago

Apologies for the (very) late response. @madooei's right, the example should be updated. It's one of the things we really need to tackle for this project. In the meantime, the readmes and wikis of layouts and in-place are accurate and are the best place to start when you're looking for examples.

I'll close this, but feel free to respond if anything's unclear.

Malvineous commented 3 years ago

Just got stuck on this too - couldn't for the life of me figure out why I was following the static site example perfectly and it just wasn't working.

It would be great if the example could be updated so it works with the latest versions of everything!