mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 09:46:12 +00:00
Move page generation code to templates.rb
This commit is contained in:
parent
8dd3bd5ad5
commit
a0b03f18f3
2 changed files with 40 additions and 41 deletions
40
_plugins/templates.rb
Normal file
40
_plugins/templates.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
module Jekyll
|
||||||
|
|
||||||
|
class TranslatePage < Page
|
||||||
|
def initialize(site, base, lang, src, dst)
|
||||||
|
@site = site
|
||||||
|
@base = base
|
||||||
|
@dir = lang
|
||||||
|
@name = dst
|
||||||
|
|
||||||
|
self.process(dst)
|
||||||
|
self.read_yaml(File.join(base, '_templates'), src)
|
||||||
|
self.data['lang'] = lang
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class TranslatePageGenerator < Generator
|
||||||
|
def generate(site)
|
||||||
|
#load translations files
|
||||||
|
locs = {}
|
||||||
|
Dir.foreach('_translations') do |file|
|
||||||
|
next if file == '.' or file == '..'
|
||||||
|
lang=file.split('.')[0]
|
||||||
|
locs[lang] = YAML.load_file("_translations/"+file)[lang]
|
||||||
|
end
|
||||||
|
#generate each translated page based on templates
|
||||||
|
locs.each do |lang,value|
|
||||||
|
Dir.foreach('_templates') do |src|
|
||||||
|
next if src == '.' or src == '..'
|
||||||
|
id=src.split('.')[0]
|
||||||
|
dst=locs[lang]['url'][id]
|
||||||
|
next if dst.nil?
|
||||||
|
dst=dst+'.html'
|
||||||
|
site.pages << TranslatePage.new(site, site.source, lang, src, dst)
|
||||||
|
end
|
||||||
|
site.pages << TranslatePage.new(site, site.source, lang, 'index.html', 'index.html')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -78,44 +78,3 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
Liquid::Template.register_tag('translate', Jekyll::TranslateTag)
|
Liquid::Template.register_tag('translate', Jekyll::TranslateTag)
|
||||||
|
|
||||||
module Jekyll
|
|
||||||
|
|
||||||
class TranslatePage < Page
|
|
||||||
def initialize(site, base, lang, src, dst)
|
|
||||||
@site = site
|
|
||||||
@base = base
|
|
||||||
@dir = lang
|
|
||||||
@name = dst
|
|
||||||
|
|
||||||
self.process(dst)
|
|
||||||
self.read_yaml(File.join(base, '_templates'), src)
|
|
||||||
self.data['lang'] = lang
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class TranslatePageGenerator < Generator
|
|
||||||
def generate(site)
|
|
||||||
#load translations files
|
|
||||||
locs = {}
|
|
||||||
Dir.foreach('_translations') do |file|
|
|
||||||
next if file == '.' or file == '..'
|
|
||||||
lang=file.split('.')[0]
|
|
||||||
locs[lang] = YAML.load_file("_translations/"+file)[lang]
|
|
||||||
end
|
|
||||||
#generate each translated page based on templates
|
|
||||||
locs.each do |lang,value|
|
|
||||||
Dir.foreach('_templates') do |src|
|
|
||||||
next if src == '.' or src == '..'
|
|
||||||
id=src.split('.')[0]
|
|
||||||
dst=locs[lang]['url'][id]
|
|
||||||
next if dst.nil?
|
|
||||||
dst=dst+'.html'
|
|
||||||
site.pages << TranslatePage.new(site, site.source, lang, src, dst)
|
|
||||||
end
|
|
||||||
site.pages << TranslatePage.new(site, site.source, lang, 'index.html', 'index.html')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue