grunt中ejs-static配置

來源:互聯網
上載者:User

 

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  }}

 

 

meta.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}

 

 

ejs模板頁中引用:<%= global.site_name%> <%= meta.title%> <%= a.title %>
注意:global.site_name中的global對應的是該path_to_data載入的json檔案名稱

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.