Cleanup in templates.rb plugin code

Support src and dst directory for future
Apply correct page url with a starting "/"
This commit is contained in:
Saivann 2013-06-17 21:56:43 -04:00
parent a0b03f18f3
commit 590769a395

View file

@ -1,14 +1,13 @@
module Jekyll module Jekyll
class TranslatePage < Page class TranslatePage < Page
def initialize(site, base, lang, src, dst) def initialize(site, base, lang, srcdir, src, dstdir, dst)
@site = site @site = site
@base = base @base = base
@dir = lang @dir = '/'+dstdir
@name = dst @name = dst
self.process(dst) self.process(dst)
self.read_yaml(File.join(base, '_templates'), src) self.read_yaml(File.join(base, srcdir), src)
self.data['lang'] = lang self.data['lang'] = lang
end end
end end
@ -24,15 +23,16 @@ module Jekyll
end end
#generate each translated page based on templates #generate each translated page based on templates
locs.each do |lang,value| locs.each do |lang,value|
Dir.foreach('_templates') do |src| Dir.foreach('_templates') do |file|
next if src == '.' or src == '..' next if file == '.' or file == '..'
id=src.split('.')[0] id = file.split('.')[0]
dst = locs[lang]['url'][id] dst = locs[lang]['url'][id]
next if dst.nil? next if dst.nil?
src = file
dst = dst+'.html' dst = dst+'.html'
site.pages << TranslatePage.new(site, site.source, lang, src, dst) site.pages << TranslatePage.new(site, site.source, lang, '_templates', src, lang, dst)
end end
site.pages << TranslatePage.new(site, site.source, lang, 'index.html', 'index.html') site.pages << TranslatePage.new(site, site.source, lang, '_templates', 'index.html', lang, 'index.html')
end end
end end
end end