编辑:由于最初发布了这个答案,因此发布了一个永久链接插件,使这变得超级简单:https ://github.com/assemble/assemble-contrib-permalinks
我认为更好的方法是在http://github.com/assemble/assemble/issues创建一个功能请求,但是,如果您希望找到一种在 gruntfile 内的 lodash 模板中使用自定义逻辑的方法,那么我的建议将是创建可以在您的模板中使用的mixin。
要添加 mixins,只需在initConfig
对象之外执行类似的操作(还有其他方法,但这是最简单的):
module.exports = function (grunt) {
grunt.util._.mixin({
year: function(foo) {
return date.getFullYear(foo);
},
month: function(foo) {
return date.getMonth(foo);
},
day: function(foo) {
return date.getDay(foo);
}
});
grunt.initConfig({
foo: {
src: 'path/to/my/files/**`
// Now we can use the mixins like this:
dest: <%= _.year() %>/<%= _.month() %>/<%= _.day() %>'
});
grunt.registerTask(...);
};
这种方法的挑战是从文件的 YAML 前端获取上下文src
,然后返回要在dest
路径中使用的日期。或者,这应该不难实现为 assemble 中的本机功能,我认为其他人也会从中受益。