2017-01-30 77 views
1

我试图将我从grunt-assembleassemble(与gulp)的旧站点迁移到assemble在最新版本的Assemble中排序帖子集合

我已经设法解决了很多差异,但我不确定集合现在如何工作以及如何制作帖子集合然后对它们进行排序。

的旧的配置我在繁重的组装是这样的:

grunt.initConfig({ 
    assemble: { 
    posts: { 
     options: { 
     collections: [{ 
      name: 'post', 
      sortby: 'posted', 
      sortorder: 'descending' 
     }], 
     permalinks: { 
      structure: ':url.html' 
     } 
     }, 
     files: [{ 
     cwd: './src/templates/pages/blog/', 
     dest: '<%= site.destination %>/blog', 
     expand: true, 
     src: ['**/*.hbs', '**/*.md'] 
     }] 
    } 
    } 
}); 

我如何转换这在组装的最新版本的工作?

回答

0

您可以使用{{items}} helper from assemble-helpershandlebars-helperswithSort助手的组合来实现自己的目标:

{{#withSort "data.posted" (items "posts") reverse=true}} 
    {{this.data.title}} 
{{/withSort}} 

这还假定您已经创建了一个“上岗”的观点收集和你加载你的“帖子”:

// create the "posts" view collection (usually done outside of a task) 
app.create('posts'); 

// load markdown posts into the "posts" view collection (usually done in a "load" task 
app.posts('path/to/posts/*.md');