Class: AegisNet::Sitemapper::Urlset
- Defined in:
- lib/sitemapper/urlset.rb
Overview
:doc:
Instance Attribute Summary
Attributes inherited from Sitemap
Class Method Summary collapse
-
.build_all! ⇒ Object
Generate Urlset sitemaps listed in sitemaps.yml.
-
.create!(options = {}) ⇒ Object
Short-hand for Urlset#new and Urlset#create!.
Instance Method Summary collapse
Methods inherited from Sitemap
#changefreq, #initialize, #priority
Constructor Details
This class inherits a constructor from AegisNet::Sitemapper::Sitemap
Class Method Details
.build_all! ⇒ Object
Generate Urlset sitemaps listed in sitemaps.yml
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# 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 = {}) ⇒ Object
Short-hand for Urlset#new and Urlset#create!
28 29 30 31 |
# File 'lib/sitemapper/urlset.rb', line 28 def self.create!( = {}) sitemap = self.new() sitemap.create! end |
Instance Method Details
#create! ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |