grunt中ejs-static配置
Gruntfile.js中添加ejs-static:
ejs_static: require(‘./tasks/ejs_static‘)(grunt)
配置方法一:
ejs_static.js
module.exports=function(grunt){ var config={ dest: ‘app/html‘, path_to_data: ‘data/data.json‘, path_to_layouts: ‘app/assets/html/‘, index_page: ‘index‘, parent_dirs: false, underscores_to_dashes: true, file_extension: ‘.html‘ } return { preview: { options: config }, release:{ options: grunt.util._.merge({ }, config, { dest:‘<%= yeoman.dist %>/html‘ }) } } }
data.json
{ "index": { "meta": { "title": "Home", "description": "Compile static html from ejs templates", "keywords": "gruntplugin, ejs, static html, static site generator, templates, templating engine, template, embedded js" } }, "about": { "path_to_layout": "app/assets/html/about.ejs", "meta": { "title": "About", "description": "Compile static html from ejs templates", "keywords": "gruntplugin, ejs, static html, static site generator, templates, templating engine, template, embedded js" } } }
ejs模板页中引用方法(对应各文件名的meta):<%= meta.title %>
配置方法二:
ejs_static.js
module.exports=function(grunt){ var config={ dest: ‘app/html‘, path_to_data: ‘data/routes.json‘, path_to_layouts: ‘app/assets/html/‘, index_page: ‘index‘, parent_dirs: false, underscores_to_dashes: true, file_extension: ‘.html‘ } return { preview: { options: config }, release:{ options: grunt.util._.merge({ }, config, { dest:‘<%= yeoman.dist %>/html‘ }) } } }
routes.json
{ "home": { "path_to_layout": "app/assets/html/index.ejs", "path_to_data": [ "data/global.json", {"data/meta.json": "home"} ] }, "a": { "path_to_layout": "app/assets/html/about.ejs", "path_to_data": [ "data/global.json", "data/a.json" ] }, "b": { "path_to_layout": "app/assets/html/about.ejs", "path_to_data": "data/a.json" } }
{ "home": { "title": "Grunt EJS Static | Home", "description": "The demo page for Grunt EJS Static", "keywords": "gruntplugin, ejs, static html, static site generator, templates, templating engine, template, embedded js" } }
global.json
{ "site_name": "Grunt EJS Static", "google_analytics": "XOXOXO" }
a.json
{ "title": "About", "description": "Compile static html from ejs templates", "keywords": "gruntplugin, ejs, static html, static site generator, templates, templating engine, template, embedded js" }
注意:global.site_name中的global对应的是该path_to_data载入的json文件名
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。