app/models/crawler/site_map_indexer.rb
# NOTE: Only works if the file is in /public.
Only works if the file is in /public.
Only works if the file is in / public .
def add_sitemap(file)
      filename = File.basename(file)
      mtime = File.mtime(file)
      doc = File.open(@filename) do |f|
        Nokogiri::XML(f) do |cfg|
          cfg.strict
          cfg.noblanks
        end
      end
      doc.css("//sitemap/loc").each do |loc|
        loc.parent.remove if loc.content =~ /\/#{filename}$/
      end
      Nokogiri::XML::Builder.with(doc.at('sitemapindex')) do |xml|
        xml.sitemap do
          xml.loc "http://#{Rails.configuration.site_domain}/#{filename}"
          xml.lastmod mtime.strftime("%FT%T%z")
        end
      end
      File.open(@filename, "w") { |f| f.puts doc.to_xml }
    end
def add_sitemap ( file ) filename = File . basename ( file ) mtime = File . mtime ( file ) doc = File . open ( @filename ) do | f | Nokogiri :: XML ( f ) do | cfg | cfg . strict cfg . noblanks end end doc . css ( "//sitemap/loc" ) . each do | loc | loc . parent . remove if loc . content =~ / \/ #{ filename } $ / end Nokogiri :: XML :: Builder . with ( doc . at ( 'sitemapindex' ) ) do | xml | xml . sitemap do xml . loc "http://#{Rails.configuration.site_domain}/#{filename}" xml . lastmod mtime . strftime ( "%FT%T%z" ) end end File . open ( @filename , "w" ) { | f | f . puts doc . to_xml } end
NOTE: Only works if the file is in /public.
NOTE : Only works if the file is in / public .
# puts("Content: /#{loc.content}/") # puts("We should remove this") if loc.content =~ /\/#{filename}$/
file
<not_specific>