mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 01:36:13 +00:00
Merge pull request #207 from bitcoin/simplemenu
Re-structure and simplify menu layout
This commit is contained in:
commit
45c360b626
11 changed files with 392 additions and 167 deletions
|
@ -19,6 +19,13 @@ module Jekyll
|
|||
lang=file.split('.')[0]
|
||||
locs[lang] = YAML.load_file('_translations/'+file)[lang]
|
||||
end
|
||||
#Load redirections
|
||||
redirects = YAML.load_file('_redirects.yml')['redirects']
|
||||
rredirects = {}
|
||||
redirects.each do |id,value|
|
||||
dst = value['dst']
|
||||
rredirects[dst] = id
|
||||
end
|
||||
#Create destination directory if does not exists
|
||||
if !File.directory?(site.dest)
|
||||
Dir.mkdir(site.dest)
|
||||
|
@ -31,15 +38,25 @@ module Jekyll
|
|||
#Add translated pages with their alternative in each languages
|
||||
locs['en']['url'].each do |id,value|
|
||||
locs.each do |lang,value|
|
||||
#Don't add a page if their url is not translated or if they are a redirection
|
||||
next if locs[lang]['url'][id].nil? or locs[lang]['url'][id] == ''
|
||||
next if redirects.has_key?(id) and ( !redirects[id].has_key?('except') or !redirects[id]['except'].has_key?(lang) )
|
||||
sitemap.puts '<url>'
|
||||
sitemap.puts ' <loc>http://bitcoin.org/'+lang+'/'+CGI::escape(locs[lang]['url'][id])+'</loc>'
|
||||
locs.each do |altlang,value|
|
||||
next if locs[altlang]['url'][id].nil? or locs[altlang]['url'][id] == '' or altlang == lang
|
||||
#Find appropriate alternative page even with redirections that are not fully deployed in translations
|
||||
altid = id
|
||||
if redirects.has_key?(id) and redirects[id].has_key?('except') and !redirects[id]['except'].has_key?(altlang)
|
||||
altid = redirects[id]['dst']
|
||||
end
|
||||
if rredirects.has_key?(id)
|
||||
altid = rredirects[id]
|
||||
end
|
||||
next if locs[altlang]['url'][altid].nil? or locs[altlang]['url'][altid] == '' or altlang == lang
|
||||
sitemap.puts ' <xhtml:link'
|
||||
sitemap.puts ' rel="alternate"'
|
||||
sitemap.puts ' hreflang="'+altlang+'"'
|
||||
sitemap.puts ' href="http://bitcoin.org/'+altlang+'/'+CGI::escape(locs[altlang]['url'][id])+'" />'
|
||||
sitemap.puts ' href="http://bitcoin.org/'+altlang+'/'+CGI::escape(locs[altlang]['url'][altid])+'" />'
|
||||
end
|
||||
sitemap.puts '</url>'
|
||||
end
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
require 'yaml'
|
||||
require 'cgi'
|
||||
|
||||
#This plugin generates all translated pages using templates in
|
||||
#_templates. The final file name of each page is defined in
|
||||
#the url section of each translations in _translations.
|
||||
|
||||
#If a page is defined in _redirects.yml, this plugin will
|
||||
#generate a redirection instead of using the template.
|
||||
|
||||
module Jekyll
|
||||
|
||||
class TranslatePage < Page
|
||||
|
@ -18,6 +22,12 @@ module Jekyll
|
|||
end
|
||||
end
|
||||
|
||||
class TranslateRedirect < StaticFile
|
||||
def write(dest)
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
class TranslatePageGenerator < Generator
|
||||
def generate(site)
|
||||
#load translations files
|
||||
|
@ -27,11 +37,14 @@ module Jekyll
|
|||
lang = file.split('.')[0]
|
||||
locs[lang] = YAML.load_file("_translations/"+file)[lang]
|
||||
end
|
||||
#generate each translated page based on templates
|
||||
#Load redirections
|
||||
redirects = YAML.load_file('_redirects.yml')['redirects']
|
||||
#Generate each translated page based on templates
|
||||
locs.each do |lang,value|
|
||||
Dir.foreach('_templates') do |file|
|
||||
next if file == '.' or file == '..'
|
||||
id = file.split('.')[0]
|
||||
next if redirects.has_key?(id) and ( !redirects[id].has_key?('except') or !redirects[id]['except'].has_key?(lang) )
|
||||
dst = locs[lang]['url'][id]
|
||||
next if dst.nil?
|
||||
src = file
|
||||
|
@ -39,6 +52,24 @@ module Jekyll
|
|||
site.pages << TranslatePage.new(site, site.source, lang, '_templates', src, lang, dst)
|
||||
end
|
||||
site.pages << TranslatePage.new(site, site.source, lang, '_templates', 'index.html', lang, 'index.html')
|
||||
#Generate each redirection page based on _redirects.yml
|
||||
redirects.each do |id,redirect|
|
||||
next if redirect.has_key?('except') and redirect['except'].has_key?(lang)
|
||||
src = locs[lang]['url'][id]
|
||||
next if src.nil?
|
||||
src = src+'.html'
|
||||
dst = redirect['dst']
|
||||
dst = locs[lang]['url'][dst]
|
||||
next if dst.nil?
|
||||
File.open(site.dest + '/' + lang + '/' + src, 'w+') do |file|
|
||||
file.puts '<!DOCTYPE HTML>'
|
||||
file.puts '<html><head>'
|
||||
file.puts '<meta name="robots" content="noindex">'
|
||||
file.puts '<script>window.location.href=\'/'+lang+'/'+CGI::escape(dst)+'\';</script>'
|
||||
file.puts '</head></html>'
|
||||
end
|
||||
site.static_files << TranslateRedirect.new(site, site.source, '', lang+'/'+src)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue