-
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Demo repo here: https://github.com/dtothefp/assemble-yfm-nunj
"version": "0.8.0"
Essentially, overwritting pre-existing data on the file.data
context does not seem to work in preRender
hook
app.preRender(/\.(?:hbs|md|html)$/, (file, next) => {
console.log('Append Pre-Render Data Before Merge', file.data);
file.data = Object.assign({}, file.data, {
title: 'From Pre-Render',
custom_stuff: 'Custom stuff from Pre-Render'
});
console.log('Append Pre-Render Data After Merge', file.data);
next();
});
if app.cache.data.title
or file.data.title
exists then the above doesn't work. I solve this by doing merge in onLoad
app.onLoad(/\.(?:hbs|md|html)$/, (file, next) => {
matter.parse(file, (err, file) => {
if (err) return next(err);
_.assign(file.data, {title: 'blahhhh'});
next(null, file);
});
});
or by making a stream plugin
app.task('build', () => {
return app.src('./templates/pages/**/*.html')
.pipe(through.obj(function(file, enc, cb) {
file.data = {title: 'blaahhhhh'}
this.push(file);
cb();
}))
.pipe(app.renderFile())
.pipe(app.dest('dist'))
.on('error', (err) => {
console.error('Error [assemble]: build');
})
.on('data', (file) => {
console.log('data', file.path);
})
.on('end', () => {
console.log('ended');
});
});
Metadata
Metadata
Assignees
Labels
No labels