module Jekyll class SitemapFile < StaticFile def write(dest) # do nothing end end class SitemapGenerator < Generator def generate(site) #Load translations locs = {} Dir.foreach('_translations') do |file| next if file == '.' or file == '..' lang=file.split('.')[0] locs[lang] = YAML.load_file('_translations/'+file)[lang] end #Create destination directory if does not exists if !File.directory?(site.dest) Dir.mkdir(site.dest) end File.open(File.join(site.dest, 'sitemap.xml'), 'w+') do |sitemap| #Open sitemap sitemap.puts '' sitemap.puts '' #Add translated pages with their alternative in each languages locs['en']['url'].each do |id,value| locs.each do |lang,value| next if locs[lang]['url'][id].nil? or locs[lang]['url'][id] == '' sitemap.puts '' sitemap.puts ' http://bitcoin.org/'+lang+'/'+locs[lang]['url'][id]+'' locs.each do |altlang,value| next if locs[altlang]['url'][id].nil? or locs[altlang]['url'][id] == '' or altlang == lang sitemap.puts ' ' end sitemap.puts '' end end #Add static non-translated pages Dir.foreach('.') do |file1| if /^[a-z]{2}(_[A-Z]{2})?$/.match(file1) and File.directory?(file1) Dir.foreach(file1) do |file2| next if !/\.html$/.match(file2) sitemap.puts '' sitemap.puts ' http://bitcoin.org/'+file1+'/'+file2.gsub('.html','')+'' sitemap.puts '' end end next if !/\.html$/.match(file1) next if file1 == 'index.html' || file1 == '404.html' sitemap.puts '' sitemap.puts ' http://bitcoin.org/'+file1.gsub('.html','')+'' sitemap.puts '' end #Add posts site.posts.each do |post| sitemap.puts '' sitemap.puts ' http://bitcoin.org'+post.url.gsub('.html','')+'' sitemap.puts '' end #Close sitemap sitemap.puts '' end site.static_files << SitemapFile.new(site, site.source, '', 'sitemap.xml') end end end