Generate different docpad collections for different languages -
i want tune multilungual docpad blog pages ended *.ru.md go /ru/ directory, , pages ended *.en.md go /en/ directory.
let's initial structire
src/ pages/ page1.ru.md page1.en.md page2.ru.md and want:
./ en/ page1.html ru/ page1.html page2.html ./ because going host gh-pages.
and same posts. 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 config docpad?
the 1st step renaming documents use dash language so: page1-en.html, , page1-ru.html, instead of page1.en.html , page1.ru.tml — otherwise @kizu correctly points out, cause problems docpad renders extension extension.
once done, can add following docpad configuration file:
collections: # fetch documents in different languages translate: (database) -> languageregex = /^(.+?)-(en|ru)$/ #docpadoutpath = @getconfig().outpath @getcollection('documents').findalllive({basename: languageregex}).on 'add', (document) -> # prepare = document.attributes parts = a.basename.match(languageregex) basename = parts[1] language = parts[2] relativeoutpath = "#{language}/#{a.relativeoutdirpath}/#{basename}.#{a.outextension}" #outpath = "#{docpadoutpath}/#{relativeoutpath}" urls = ["/#{relativeoutpath}"] # apply document .setmetadefaults({ #outpath url: urls[0] }) .addurl(urls) this have urls working in way want.
then run docpad in static environment cleanurls plugin installed, write documents desired locations.
docpad install cleanurls docpad generate --env static
Comments
Post a Comment