Clean and improve redirects.rb

Use _redirects/ for more consistency with other plugins
Fix an inaccurate redirection association in sitemap.rb
This commit is contained in:
Saivann 2013-06-22 20:43:19 -04:00
parent dbb1823e69
commit d58a1690da
6 changed files with 28 additions and 23 deletions

View file

@ -41,7 +41,7 @@ You can import all translations (complete and incomplete) from transifex using t
tx set --auto-remote https://www.transifex.com/projects/p/bitcoinorg/ tx set --auto-remote https://www.transifex.com/projects/p/bitcoinorg/
tx pull -a -s --skip tx pull -a -s --skip
Then, you can overwrite any specific translation in the _translations folder by one of these files. You might also need to make sure that each .html files (in _layouts, _templates and _redirects.yml) don't serve outdated content for those languages. You should also make sure that no urls or anchor has been changed by translators. Then, you can overwrite any specific translation in the _translations folder by one of these files. You might also need to make sure that each .html files (in _layouts, _templates and _redirects) don't serve outdated content for those languages. You should also make sure that no urls or anchor has been changed by translators.
### Update source english strings ### Update source english strings

View file

@ -20,11 +20,13 @@ module Jekyll
locs[lang] = YAML.load_file('_translations/'+file)[lang] locs[lang] = YAML.load_file('_translations/'+file)[lang]
end end
#Load redirections #Load redirections
redirects = YAML.load_file('_redirects.yml')['redirects'] redirects = {}
rredirects = {} rredirects = {}
redirects.each do |id,value| Dir.foreach('_redirects') do |file|
dst = value['dst'] next if file == '.' or file == '..'
rredirects[dst] = id id = file.split('.')[0]
redirects[id] = YAML.load_file("_redirects/" + file)
rredirects[redirects[id]['dst']] = id
end end
#Create destination directory if does not exists #Create destination directory if does not exists
if !File.directory?(site.dest) if !File.directory?(site.dest)
@ -44,12 +46,13 @@ module Jekyll
sitemap.puts '<url>' sitemap.puts '<url>'
sitemap.puts ' <loc>http://bitcoin.org/'+lang+'/'+CGI::escape(locs[lang]['url'][id])+'</loc>' sitemap.puts ' <loc>http://bitcoin.org/'+lang+'/'+CGI::escape(locs[lang]['url'][id])+'</loc>'
locs.each do |altlang,value| locs.each do |altlang,value|
#Find appropriate alternative page even with redirections that are not fully deployed in translations
altid = id altid = id
if redirects.has_key?(id) and redirects[id].has_key?('except') and !redirects[id]['except'].has_key?(altlang) #If there is a redirection from this page, use the destination as alternate url
if redirects.has_key?(id) and ( !redirects[id].has_key?('except') or !redirects[id]['except'].has_key?(altlang) )
altid = redirects[id]['dst'] altid = redirects[id]['dst']
end end
if rredirects.has_key?(id) #If there is a disabled redirection to this page, point to the source as alternate url
if rredirects.has_key?(id) and redirects[rredirects[id]].has_key?('except') and redirects[rredirects[id]]['except'].has_key?(altlang)
altid = rredirects[id] altid = rredirects[id]
end end
next if locs[altlang]['url'][altid].nil? or locs[altlang]['url'][altid] == '' or altlang == lang next if locs[altlang]['url'][altid].nil? or locs[altlang]['url'][altid] == '' or altlang == lang

View file

@ -37,8 +37,13 @@ module Jekyll
lang = file.split('.')[0] lang = file.split('.')[0]
locs[lang] = YAML.load_file("_translations/"+file)[lang] locs[lang] = YAML.load_file("_translations/"+file)[lang]
end end
#Load redirections #Load redirections files
redirects = YAML.load_file('_redirects.yml')['redirects'] redirects = {}
Dir.foreach('_redirects') do |file|
next if file == '.' or file == '..'
id = file.split('.')[0]
redirects[id] = YAML.load_file("_redirects/" + file)
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 |file| Dir.foreach('_templates') do |file|

View file

@ -1,13 +0,0 @@
redirects:
bitcoin-for-enthusiasts:
dst: innovation
except:
ar: true
de: true
es: true
fa: true
it: true
nl: true
ru: true
bitcoin-for-press:
dst: press

View file

@ -0,0 +1,9 @@
dst: innovation
except:
ar: true
de: true
es: true
fa: true
it: true
nl: true
ru: true

View file

@ -0,0 +1 @@
dst: press