问题描述
我正在努力处理 grunt任务配置,如下所示:
汇编:{
options:{
flatten:false,
expand:true,
assets:'',
layout:'default.hbs',
layoutdir:'templates / layouts',
partials:['templates / includes / *。hbs'],
helpers:['templates / helpers / *。js'],
data:['templates / data / *。 {json,yml}']
},
dev:{
src:'templates / pages / ** / *。hbs',
dest:' build /'
}
用于assemble.io的项目模板的脚手架如下所示:
模板
├──佣工
├──包括
│├──页面-footer.hbs
│├──page-header.hbs
│└──scripts.hbs
├──布局
│└──default.hbs
└──网页
├──en
│└─index.hbs
├──fr
│└──index.hbs
└──index.hbs
我的愿望是去得到像这样的东西:
build
├──en
│└──index .html
├──fr
│└──index.html
└──index.html
但取而代之的是:
build
└──模板
└──网页
├──en
│└──index.html
├──fr
│└──index.html
└──index.html
我确实尝试了一些(实际上很多)组合 flatten 和展开以及 cwd 选项),但我被卡住了。
使用 fl atten 结果会使 index.html 文件覆盖其他文件。
因此,我实际上将渲染放入 .tmp 目录,然后将文件移至 build 目录。
我不喜欢那个解决方案,因为 page.assets 仍然是 broken (它的值是 ../../ .. ,为root index.html)。 grunt-assemble
(请注意,此信息特指grunt-assemble 0.4.x,这是用于汇编的grunt插件但有一个完全不同的API)
@doowb几乎没错,尝试添加 expand:true 和 ext:'.html'到文件config:
组合:{
options:{
flatten:false,
expand:true,
assets:'',
layout:' default.hbs',
layoutdir:'templates / layouts',
partials:['templates / includes / *。hbs'],
helpers:['templates / helpers /*.js'],
data:['templates / data / *。{json,yml}']
},
dev:{
files :[
{expand:true,cwd:'templates / pages /',src:'** / *。hbs',dest:'build /',ext:'.html'}
]
}
}
另请参阅
汇编0.7.x
汇编在汇编0.7.0中是一流的,就像插件一样,所以像生成相对链接,构建分页和创建自定义永久链接要容易得多。
如果您使用汇编0.7.x或更高版本,是您想要使用的插件。
I am struggling with the grunt-assemble grunt task configuration which looks like this:
assemble: { options: { flatten: false, expand: true, assets: '', layout: 'default.hbs', layoutdir: 'templates/layouts', partials: ['templates/includes/*.hbs'], helpers: ['templates/helpers/*.js'], data: ['templates/data/*.{json,yml}'] }, dev: { src: 'templates/pages/**/*.hbs', dest: 'build/' }
The scaffolding of the project templates for assemble.io looks like:
templates ├── helpers ├── includes │ ├── page-footer.hbs │ ├── page-header.hbs │ └── scripts.hbs ├── layouts │ └── default.hbs └── pages ├── en │ └── index.hbs ├── fr │ └── index.hbs └── index.hbs
My wish is go get something like:
build ├── en │ └── index.html ├── fr │ └── index.html └── index.html
But instead I get something like:
build └── templates └── pages ├── en │ └── index.html ├── fr │ └── index.html └── index.html
I did try a few (a lot actually) of combinations (with the flatten and expand as well as the cwd options) but I am stuck.
Using flatten has for consequence to make the index.html files to overwrite each others.
So I actually do the rendering into a .tmp directory and then move the files to the build directory.I do not like that solution because then, the page.assets is still broken (its value would be ../../.., for the root index.html).
grunt-assemble
(Note that this information refers specifically to grunt-assemble 0.4.x, which is the grunt plugin for assemble but has a completely different API)
@doowb almost has it right, try adding expand: true and ext: '.html' to the files config:
assemble: { options: { flatten: false, expand: true, assets: '', layout: 'default.hbs', layoutdir: 'templates/layouts', partials: ['templates/includes/*.hbs'], helpers: ['templates/helpers/*.js'], data: ['templates/data/*.{json,yml}'] }, dev: { files: [ {expand: true, cwd: 'templates/pages/', src: '**/*.hbs', dest: 'build/', ext: '.html'} ] } }
Also take a look at https://github.com/assemble/assemble-contrib-permalinks
assemble 0.7.x
Collections are first-class in assemble 0.7.0, as are plugins, so things like generating relative links, building pagination, and creating custom permalinks are much easier to do.
If you're using assemble 0.7.x and up, assemble-permalinks is the plugin you'd want to use.
这篇关于汇编生成的页面的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!