class AegisNet::Sitemapper::Urlset
Public Class Methods
build_all!()
click to toggle source
Generate Urlset
sitemaps listed in sitemaps.yml
# File lib/sitemapper/urlset.rb, line 34 def self.build_all! config = AegisNet::Sitemapper::Loader.load_config # Generate sitemaps for AR Models dynamically by yml instructions if config[:models] config[:models].each do |ar_map| opts = ar_map.last klass = ar_map.first.camelize.constantize build_opts = { :file => File.join("#{config[:local_path]}", opts["sitemapfile"]) } build_opts.merge!( :conditions => opts["conditions"]) if opts["conditions"] scope = opts["scope"].present? ? "#{opts["scope"]}" : :all klass.build_sitemap scope, build_opts do |object, xml| if opts["loc"].starts_with?("Proc") xml.loc AegisNet::Sitemapper::Loader.proc_loader(opts["loc"], object) else xml.loc opts["loc"] end xml.lastmod object.updated_at.to_date xml.changefreq opts["changefreq"] || "weekly" xml.priority opts["priority"] || 0.5 end end end # Find misc. sitemap data and generate a single static one if config[:static] entries = config[:static]["urlset"] file = File.join("#{config[:local_path]}", config[:static]["sitemapfile"]) AegisNet::Sitemapper::Generator.create(entries, :file => file) do |entry, xml| xml.loc entry["loc"] xml.lastmod entry["lastmod"] if entry["lastmod"] xml.changefreq entry["changefreq"] if entry["changefreq"] xml.priority entry["priority"] || 0.5 end end end
create!(options = {})
click to toggle source
Short-hand for Urlset#new and Urlset#create!
# File lib/sitemapper/urlset.rb, line 28 def self.create!(options = {}) sitemap = self.new(options) sitemap.create! end
Public Instance Methods
create!()
click to toggle source
# File lib/sitemapper/urlset.rb, line 7 def create! xml = Builder::XmlMarkup.new(:indent => 2) xml.instruct! xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do @sitemaps.each do |sitemap| location = sitemap.loc.gsub(/^\//, '') xml.url do xml.loc "http://#{@host}/#{location}" xml.lastmod sitemap.lastmod if sitemap.lastmod xml.changefreq sitemap.changefreq xml.priority sitemap.priority end end end File.open(@file, "w") { |file| file.puts xml.target! } end