可以這樣做,但三個地變化的文件結構:
正如DocPad的路徑點在那裏劃定不同的渲染器,我不知道怎麼做我想建議在渲染器裏面,所以不會拋出Rendering the extension … didn't do anything.
錯誤,我建議使用_en
/_ru
而不是.en
/.ru
,這樣你就可以做基於文件名的東西而沒有任何額外的麻煩。
最好使用Docpad的初始路徑,即將您的pages
和blog
文件夾放入documents
文件夾中。
可能有一種方法可以在不使用.html.md
部件的情況下使用這些文件,但由於它是DocPad方式,因此應該使用它。
也許有辦法做你想做什麼這個沒有這些變化,但它是沒有價值的:)
所以,代碼在docpadConfig
放在(這裏是一個example project at GitHub):
docpadConfig = {
collections:
# Declare `ru` and `en` collections
ruDocuments: ->
@getCollection("documents").findAllLive({
basename: /_ru$/
})
enDocuments: ->
@getCollection("documents").findAllLive({
basename: /_en$/
})
events:
renderBefore:() ->
# Rewrite `pages/` to the root and `posts/` to the `blog/`.
this.docpad.getCollection('documents').forEach (page) ->
newOutPath = page.get('outPath')
.replace('/out/pages/', '/out/')
.replace('/out/posts/', '/out/blog/')
newUrl = page.get('url')
.replace('pages/', '')
.replace('posts/', 'blog/')
page.set('outPath', newOutPath)
page.setUrl(newUrl)
# Rewrite `_ru` to the `/ru/`
this.docpad.getCollection('ruDocuments').forEach (page) ->
newOutPath = page.get('outPath')
.replace('/out/', '/out/ru/')
.replace('_ru.', '.')
newUrl = '/ru' + page.get('url')
page.set('outPath', newOutPath)
page.setUrl(newUrl)
# Rewrite `_en` to the `/en/`
this.docpad.getCollection('enDocuments').forEach (page) ->
newOutPath = page.get('outPath')
.replace('/out/', '/out/en/')
.replace('_en.', '.')
page.set('outPath', newOutPath)
newUrl = '/en' + page.get('url').replace('_en.', '.')
page.setUrl(newUrl)
}
module.exports = docpadConfig
首先我們聲明兩個集合:一個用於所有ru文檔,另一個用於所有en文檔。
然後我們在第一改寫pages/
到根,然後_en
/_ru
文件改寫爲/en/
和/ru/
。
請注意,這些更改只是源文件的存儲方式,結果輸出將與您的問題相同。
所以,與其
src/
pages/
page1.ru.md
page1.en.md
page2.ru.md
posts/
post-about-docpad.ru.md
post-about-docpad.en.md
你應該寫這樣:
src/
documents/
pages/
page1_ru.html.md
page1_en.html.md
page2_ru.html.md
posts/
post-about-docpad_ru.html.md
post-about-docpad_en.html.md
但是,你會得到你就像你需要所需的輸出。唯一的是我不明白關於gh-pages
的部分:你是否要將結果和源碼存儲在同一分支中?我建議使用master
作爲源代碼,gh-pages
作爲結果。
但是,如果你需要只有一個分支,好了,好了,你可以很容易重寫所有你想要的東西用.replace('/out/', '/ru/')
等替代.replace('/out/', '/out/ru/')
- 這會把渲染的文件上面達到一個水平out
。
謝謝!這一切我需要。 –