Normalize page redirections

Use a fallback HTML page with a manual and javascript redirect
Keep canonical pages only for alerts
This commit is contained in:
Saivann 2013-10-14 14:59:10 -04:00
parent b988ce349c
commit 3da682b36b
11 changed files with 69 additions and 54 deletions

View file

@ -14,7 +14,7 @@ module Jekyll
self.data['date'] = date
self.data['layout'] = 'alert'
if dstdir == ''
self.data['redirect'] = src.split('.')[0]
self.data['canonical'] = '/en/alert/' + src.split('.')[0]
else
self.data['category'] = 'alert'
if self.data.has_key?('banner') and !self.data['banner'].nil? and self.data['banner'].length>0

View file

@ -14,7 +14,8 @@ module Jekyll
self.data['date'] = year + '-' + month + '-' + day
self.data['layout'] = 'release'
if dstdir.index('/releases/') === 0
self.data['redirect'] = dst.gsub('.md','')
self.data['redirect'] = '/en/release/' + dst.gsub('.md','')
self.data['layout'] = 'redirect'
else
self.data['category'] = 'release'
if !site.config.has_key?('DOWNLOAD_DATE') or site.config['DOWNLOAD_DATE'] < year + '-' + month + '-' + day

View file

@ -71,7 +71,7 @@ module Jekyll
next if !/\.html$/.match(file2)
#Ignore static redirect pages
data = File.read(file1+'/'+file2)
next if !data.index('window.location.href=').nil?
next if !data.index('window.location.href=').nil? or !data.index('redirect:').nil?
sitemap.puts '<url>'
sitemap.puts ' <loc>http://bitcoin.org/'+file1+'/'+file2.gsub('.html','')+'</loc>'
sitemap.puts '</url>'
@ -81,7 +81,7 @@ module Jekyll
next if file1 == 'index.html'
#Ignore static redirect pages and google webmaster tools
data = File.read(file1)
next if !data.index('window.location.href=').nil? or !data.index('google-site-verification:').nil?
next if !data.index('window.location.href=').nil? or !data.index('redirect:').nil? or !data.index('google-site-verification:').nil?
sitemap.puts '<url>'
sitemap.puts ' <loc>http://bitcoin.org/'+file1.gsub('.html','')+'</loc>'
sitemap.puts '</url>'

View file

@ -22,9 +22,17 @@ module Jekyll
end
end
class TranslateRedirect < StaticFile
def write(dest)
# do nothing
class PageRedirect < Page
def initialize(site, base, lang, srcdir, src, dstdir, dst, red)
@site = site
@base = base
@dir = '/'+dstdir
@name = dst
self.process(dst)
self.read_yaml(File.join(base, srcdir), src)
self.data['lang'] = lang
self.data['redirect'] = red
self.data['layout'] = 'redirect'
end
end
@ -63,23 +71,16 @@ module Jekyll
end
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? or src == ''
src = src+'.html'
dst = redirect['dst']
dst = locs[lang]['url'][dst]
src = redirect['dst']
src = src + '.html'
dst = locs[lang]['url'][id]
next if dst.nil? or dst == ''
if !File.directory?(site.dest + '/' + lang)
Dir.mkdir(site.dest + '/' + lang)
end
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)
dst = dst + '.html'
red = redirect['dst']
red = locs[lang]['url'][red]
next if red.nil? or red == ''
red = '/' + lang + '/' + CGI::escape(red)
site.pages << PageRedirect.new(site, site.source, lang, '_templates', src, lang, dst, red)
end
end
end