2013-11-21 42 views
9

我與grunt-assemble繁重的任務配置看起來像這樣掙扎:路徑與組裝

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/' 
    } 

爲assemble.io的項目模板腳手架的樣子:

templates 
├── helpers 
├── includes 
│   ├── page-footer.hbs 
│   ├── page-header.hbs 
│   └── scripts.hbs 
├── layouts 
│   └── default.hbs 
└── pages 
    ├── en 
    │   └── index.hbs 
    ├── fr 
    │   └── index.hbs 
    └── index.hbs 

我的願望是去得到像這樣的東西:

build 
├── en 
│   └── index.html 
├── fr 
│   └── index.html 
└── index.html 

但是,而是我得到像這樣的東西:

build 
└── templates 
    └── pages 
     ├── en 
     │   └── index.html 
     ├── fr 
     │   └── index.html 
     └── index.html 

我也嘗試組合的幾個(很多實際)(與flattenexpand還有cwd期權),但我堅持。

使用flatten必然導致index.html文件相互覆蓋。

所以我實際上做渲染成.TMP目錄,然後將文件移動到構建目錄。 我不喜歡那個解決方案,因爲那樣,page.assets仍然是(其值爲../../..,對於根index.html)。

回答

8

咕嚕組裝

(請注意,此信息具體是指咕嚕組裝0.4.x,這是繁重的插件用於組裝,但具有完全不同的API)

@doowb幾乎沒錯,試試在文件配置中加入expand: trueext: '.html'

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'} 
    ] 
    } 
} 

而且看看https://github.com/assemble/assemble-contrib-permalinks

組裝0.7.x

集合是一流的裝配0.7.0,因爲是插件,所以像產生相對鏈接,建立分頁,並創建定製永久鏈接要容易得多。

如果您使用的是彙編0.7.x及更高版本,則assemble-permalinks是您想要使用的插件。

+2

非常感謝!我在尋找正確的位置,但是它對'files'對象或其他可能的語法有點混淆。 – zeropaper

+0

這將如何使用節點集合@jonschlinkert @doowb完成? 它會像... app.pages([路徑頁],{[文件配置]}或這只是一個咕嚕東西atm? –

2

您是否嘗試過使用擴展的files對象與具有cwd屬性的grunt目標?

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: [ 
     { cwd: 'templates/pages/', src: '**/*.hbs', dest: 'build/' } 
    ] 
    } 
} 
+1

我其實也是。 獲得有關文件未找到的錯誤,看起來像這樣 錯誤:無法讀取「index.hbs」文件(錯誤代碼:ENOENT)。 (..../node_modules/grunt/lib/grunt/util.js:57:39) 在Object.file.read(..../node_modules/grunt/lib/grunt/file.js:237:22) at buildPage(..../node_modules/assemble/tasks/assemble.js:289:78) at ..../node_modules/assemble/tasks/assemble.js:345:23 – zeropaper