Sha256: a8fdb93573596e62abf91d59c2026c32b2997aba1adf4c33cf2a944c7b17d669
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
require "builder" require "open-uri" module SiteMapper class SiteMapper attr_accessor :url, :loc, :lastmod, :changefreq, :priority, :sitemap def initialize @url = nil @loc = :loc @lastmod = :lastmod @changefreq = "daily" @priority = 1.00 @sitemap = nil end def write_sitemap(collection,extra_collection=nil) return false if @sitemap.nil? xml = Builder::XmlMarkup.new(:indent=>2) collection = extra_collection + collection if extra_collection xml.urlset(:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9") do collection.each do |value| loc = value.respond_to?(@loc.to_s.to_sym) ? value.send(@loc) : value[@loc] lastmod = value.respond_to?(@lastmod.to_s.to_sym) ? value.send(@lastmod) : value[@lastmod] change = value.respond_to?(@changefreq.to_s.to_sym) ? value.send(@changefreq) : value[@changefreq] priority = value.respond_to?(@priority.to_s.to_sym) ? value.send(@priority) : value[@priority] change = @changefreq if !change priority = @priority if !priority xml.url do xml.loc loc xml.lastmod lastmod xml.changefreq change xml.priority priority end end end content = xml.target! File.open(sitemap,"w") do |file| file << content end content end def ping return if @url.nil? open("http://www.google.com/webmasters/tools/ping?sitemap=#{@url}").read end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
taq-sitemapper-0.0.3 | lib/sitemapper.rb |