可以这样做,但三个地变化的文件结构:
正如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
。
谢谢!这一切我需要。 –