I want to tune my multilungual DocPad blog so that pages ended with *.ru.md go into /ru/ directory, and pages ended with *.en.md go into /en/ directory.
Let's say this is the initial structire
src/
pages/
page1.ru.md
page1.en.md
page2.ru.md
And this is what I want:
./
en/
page1.html
ru/
page1.html
page2.html
./
because I am going to host with gh-pages
.
And the same for posts. I would like to store them in
src/
posts/
post-about-docpad.ru.md
post-about-docpad.en.md
And get
./
en/
posts/
post-about-docpad.html
ru/
posts/
post-about-docpad.html
How should I config docpad?
This could be done, but with three changes in the file structure:
As dots in DocPad's path are there to delimit the different renderers and I'm not sure how to do what I'd propose inside a renderer, so it won't throw
Rendering the extension … didn't do anything.
error, I propose to use the_en
/_ru
instead of.en
/.ru
, this way you could then do stuff based on filenames without any extra hassle.It is better to use the Docpad's initial paths, i.e. put your
pages
andblog
folders insidedocuments
folder.There could be a way to use the files without the
.html.md
part, but as it is a DocPad way, you should use it.Maybe there are ways to do what you want this without those changes, but it would be less trivial :)
So, the code to place at
docpadConfig
indocpad.coffee
(here is an example project at GitHub):At first we declare two collections: one for all ru documents and another for all en documents.
Then we at first rewrite the
pages/
to the root, and then rewrite the_en
/_ru
files to/en/
and/ru/
.Note that the changes are only how the source files are stored, the resulting output would be the same as you want in your question.
So, instead of
You should write this way:
But you would get you desired output just as you need. The only thing is that I didn't understand the part about the
gh-pages
: are you going to store the result and the source in the same branch? I'd propose to use themaster
for the source and thegh-pages
for the result.But if you'd need to have only one branch, well, ok, you can easy rewrite all the things you'd like by replacing
.replace('/out/', '/out/ru/')
with.replace('/out/', '/ru/')
etc. — this would put the rendered files up to one level aboveout
.The 1st step is renaming your documents to use a dash for the language like so:
page1-en.html
, andpage1-ru.html
, instead ofpage1.en.html
andpage1.ru.tml
— as otherwise as @kizu correctly points out, it will cause problems as DocPad renders from extension to extension.Once that is done, you can add the following to your docpad configuration file:
This will have URLs working in the way you want.
Then run DocPad in the static environment with the cleanurls plugin installed, to write the documents to the desired locations.