汇编:如何从json / yaml生成页面? [英] Assemble: How can I generate pages from json/yaml?

查看:177
本文介绍了汇编:如何从json / yaml生成页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您提供布局,是否有办法从json / yaml生成页面?我认为这是可能的,但无法在文档中找到。



目前正在GitHub中对此进行跟踪: http://webb.li/QjTX

解决方案

code> options.pages 功能已经实现,您可以添加这样的页面:

 选项:{
pages:{
about:{
data:{
title:关于

content:{{title}}
},
...
}
}


我们不支持自动加载json / yml文件,但是您可以在Gruntfile中执行此操作,并将该对象添加到选项中。

  module.exports = function(grunt){

grunt.initConfig({

// package.json
pkg:grunt.file.readJSON('package.json'),

汇编:{
选项:{
flatten:true,
layoutdir:'src / layouts',
资产:'dest / assets'
},
博客:{
options:{
引擎:'handlebars',
layout:'post.hbs',
site:{
title:'这是我的博客'
},
页面: grunt.file.readJSON('pages.json')
},
文件:{'dest /':['src / index.hbs']}
}
}
});

//载入npm插件以提供必要的任务。
grunt.loadNpmTasks('assemble');

//默认任务。
grunt.registerTask('default',['assemble']);

};

这个例子使用 post.hbs 文件作为在 pages.json 文件中定义的任何页面的布局。它还将为文件src数组中指定的 index.hbs 建立一个页面。目前,dest / src文件是必需的,因此Assemble知道在哪里编写文件,但我想我们会将它添加到选项或页面对象中,以便它可以在没有文件对象的情况下运行。


Is there a way to generate pages from json/yaml if you provide a layout? I thought this was possible, but can't find in docs.

This is currently being tracked here in GitHub: http://webb.li/QjTX

解决方案

Since the options.pages feature has been implemented, you can add pages like this:

options: {
  pages: {
    "about": {
      "data": {
        "title": "About"
      },
      "content": "Content for {{title}}"
    },
    ...
  }
}

We aren't supporting automatic loading of a json/yml file, but you can do this inside your Gruntfile and add the object to options.pages that way...

module.exports = function(grunt) {

  grunt.initConfig({

    // package.json
    pkg: grunt.file.readJSON('package.json'),

    assemble: {
      options: {
        flatten: true,
        layoutdir: 'src/layouts',
        assets: 'dest/assets'
      },
      blog: {
        options: {
          engine: 'handlebars',
          layout: 'post.hbs',
          site: {
            title: 'This is my Blog'
          },
          pages: grunt.file.readJSON('pages.json')
        },
        files: { 'dest/': ['src/index.hbs'] }
      }
    }
  });

  // Load npm plugins to provide necessary tasks.
  grunt.loadNpmTasks('assemble');

  // Default task.
  grunt.registerTask('default', ['assemble']);

};

This example uses the post.hbs file as the layout for any pages defined in the pages.json file. It will also build a page for the index.hbs specified in the files src array. Right now, the files dest/src is required so Assemble knows where to write the files, but I think we'll add that to the options, or the page object so it can be run without the files object.

这篇关于汇编:如何从json / yaml生成页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆