編集: この回答が最初に投稿されたので、これを非常に簡単にするパーマリンク プラグインが公開されました: https://github.com/assemble/assemble-contrib-permalinks
http://github.com/assemble/assemble/issuesで機能リクエストを作成するのがより良いアプローチだと思いますが、gruntfile 内の lodash テンプレートでカスタム ロジックを使用する方法を見つけたい場合は、私の提案です。テンプレートで使用できるミックスインを作成することです。
ミックスインを追加するには、オブジェクトの外側で次のようにし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(...);
};
このアプローチの課題は、src
ファイルの YAML フロントマターからコンテキストを取得し、dest
パスで使用される日付を返すことです。あるいは、これをアセンブルのネイティブ機能として実装することは難しくありません。他の人も同様に恩恵を受けると思います。