jsonberry / metalsmith-hbs-relative-partial Goto Github PK
View Code? Open in Web Editor NEWMetalsmith Plugin - Easily create relative HBS partials
Metalsmith Plugin - Easily create relative HBS partials
After many try that failed, I try to reproduce your example, so I copied the directory structure the main template src/index.hbs and the partial src/about/components heading.hbs. I wrote an index.js like this
var Metalsmith = require('metalsmith');
var partials = require('metalsmith-hbs-relative-partial');
var inplace = require('metalsmith-in-place');
Metalsmith(__dirname)
.source('./src')
.destination('./build')
.use(partials({
dirName: 'components'
}))
.use(inplace())
.build(function (err) {
// For error handling
if (err) {
throw err;
}
});
and when I execute this code with node v8.9.3 I get
$ node index.js
/home/marc/metaltest/index.js:15
throw err;
^
Error: The partial about/heading could not be found
at Object.invokePartial (/home/marc/metaltest/node_modules/jstransformer-handlebars/node_modules/handlebars/dist/cjs/handlebars/runtime.js:281:11)
at Object.invokePartialWrapper [as invokePartial] (/home/marc/metaltest/node_modules/jstransformer-handlebars/node_modules/handlebars/dist/cjs/handlebars/runtime.js:68:39)
at Object.eval [as main] (eval at createFunctionContext (/home/marc/metaltest/node_modules/jstransformer-handlebars/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:5:31)
at main (/home/marc/metaltest/node_modules/jstransformer-handlebars/node_modules/handlebars/dist/cjs/handlebars/runtime.js:175:32)
at Object.ret (/home/marc/metaltest/node_modules/jstransformer-handlebars/node_modules/handlebars/dist/cjs/handlebars/runtime.js:178:12)
at Object.ret [as fn] (/home/marc/metaltest/node_modules/jstransformer-handlebars/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:526:21)
at Transformer.render (/home/marc/metaltest/node_modules/metalsmith-in-place/node_modules/jstransformer/index.js:289:25)
at resolve (/home/marc/metaltest/node_modules/metalsmith-in-place/lib/index.js:60:33)
at new Promise (<anonymous>)
at render (/home/marc/metaltest/node_modules/metalsmith-in-place/lib/index.js:29:10)
The versions of package I use is
"dependencies": {
"jstransformer-handlebars": "^1.1.0",
"metalsmith": "^2.3.0",
"metalsmith-in-place": "^4.1.1",
"metalsmith-jstransformer": "^0.13.0"
}
You say that this plugin is aimed to be used with metalsmith-in-place, which has had a major change with version 2.0 the 2017-01-01, when it adopted jstransformer. As your plugin is from march 2017, I have assumed it rely on metalsmith-in-place greater than 2.0, but as there is presently no test data, and so metalsmith-in-place is not in your package.json, there is no way (except go through the code!) to know the targeted version.
What about this error, in which context your example is working?
There should be a gate for a file not existing
Along the lines of:
if (invalidFile(file)) {
throw new Error('file is invalid');
}
what might be more appropriate here is allowing the plugin to gracefully exit if no file is found
There should be a gate for the listed directory name not existing
Along the lines of:
if (invalidDirName(dirName)) {
throw new Error('directory name is invalid');
}
There should be a gate for the listed source directory not existing
Along the lines of:
if (invalidSource(source)) {
throw new Error('source is invalid');
}
The key in the JSON config is "pattern", but it should be "dirName"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.