在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):gianlucamancini/gulp-nunjucks-html开源软件地址(OpenSource Url):https://github.com/gianlucamancini/gulp-nunjucks-html开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):
Issues with the output should be reported on the Nunjucks issue tracker. Install
Usagevar gulp = require('gulp');
var nunjucks = require('gulp-nunjucks-html');
gulp.task('nunjucks', function() {
return gulp.src('app/templates/**/*.html')
.pipe(nunjucks({
searchPaths: ['app/templates']
}))
.pipe(gulp.dest('dist'));
}); Error handlingThis plugin will emit an error for cases such as invalid Nunjucks syntax or missing imported files. If uncaught, the error will crash Gulp. You will need to attach a listener for the error event emitted by the stream: gulp.task('nunjucks', function() {
return gulp.src('src/templates/*.html')
.pipe(nunjucks({
searchPaths: ['src/templates']
}))
.on('error', function(err) {
// err is the error thrown by the Nunjucks compiler.
})
.pipe(gulp.dest('dist'));
}); Use with other pluginsThe context used for rendering (i.e. the object passed to nunjucks.renderString) is created by merging the Note that gulp.task('nunjucks', function() {
return gulp.src('src/templates/contact.html')
// Get data from a JSON file
.pipe(data(function(file) {
return require('./metadata/' + path.basename(file.path) + '.json');
}))
// Extract the FrontMatter
.pipe(frontMatter())
// Context is the FrontMatter of the file and the JSON data, plus the locals object.
.pipe(nunjucks({
locals: { apiKey: 'secret-key-here' }
}))
.pipe(gulp.dest('dist'));
}); APInunjucks(options)options.searchPathsType: Default: A list of paths to look for templates (see FileSystemLoader). Can also be a single path for where templates live, and it defaults to the current working directory. options.localsType: Default: An hash used as context for compiling the templates. options.autoescapeType: Default: Controls if output with dangerous characters are escaped automatically. options.tagsType: Default: Defines the syntax for Nunjucks tags. See Customizing Syntax. options.setUpType: Default: Use this function to extend the Nunjuck's gulp.task('html', function() {
return gulp.src('src/templates/*.html')
.pipe(nunjucks({
searchPaths: ['src/templates'],
setUp: function(env) {
env.addFilter('greet', function(name) {
return 'Hello ' + name;
});
return env;
}
}))
.pipe(gulp.dest('dist'));
}); options.extType: Default: Change generated files extension by this extension instead of templates extension. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论