Class: Sitemapper::Map
- Inherits:
-
SitemapXML
- Object
- SitemapXML
- Sitemapper::Map
- Defined in:
- lib/sitemapper/map.rb
Constant Summary collapse
- @@root_tag =
'urlset'
Constants inherited from SitemapXML
SitemapXML::INDENT, SitemapXML::SCHEMA
Instance Method Summary collapse
-
#map_url(loc, opts = {}) ⇒ Object
(also: #map_path)
Map the given localization.
-
#map_urls {|_self| ... } ⇒ Object
Map multiple URLs and write once (at the end).
-
#unmap_url(loc) ⇒ Object
Unmap the given localization (
loc
).
Methods inherited from SitemapXML
Constructor Details
This class inherits a constructor from Sitemapper::SitemapXML
Instance Method Details
#map_url(loc, opts = {}) ⇒ Object Also known as: map_path
Map the given localization
loc
is the URL to me mapped opts
is a hash with the following parameters:
-
url
orpath
is the complete URL or path (ex.: /articles/rails-doesnt-scale) [required] -
lastmod
a date object to the last modification [optional] -
changefreq
the frequency of change (:daily, :monthly, :yearly) [optional] -
priority
the priority of the URL (0..1) [optional]
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sitemapper/map.rb', line 21 def map_url(loc, opts={}) self.locker.synchronize do loc = Sitemapper.urlfy(loc) lastmod, changefreq, priority = (opts) url = get_url(loc) || self.builder.root.add_element('url') (url.elements['loc'] || url.add_element('loc')).text = loc (url.elements['lastmod'] || url.add_element('lastmod')).text = lastmod.strftime('%Y-%m-%d') if lastmod (url.elements['changefreq'] || url.add_element('change_freq')).text = changefreq.to_s if changefreq (url.elements['priority'] || url.add_element('priority')).text = '%.2f' % priority if priority write_file end end |
#map_urls {|_self| ... } ⇒ Object
Map multiple URLs and write once (at the end)
Usage:
map.map_urls do |map|
map.map_url('http://www.example.com/about')
map.unmap_url('http://www.example.com/contact')
end
45 46 47 48 49 50 51 |
# File 'lib/sitemapper/map.rb', line 45 def map_urls @write = false yield(self) @write = true self.locker.synchronize { write_file } end |
#unmap_url(loc) ⇒ Object
Unmap the given localization (loc
)
-
loc
is the URL to be unmaped
56 57 58 59 60 61 62 63 |
# File 'lib/sitemapper/map.rb', line 56 def unmap_url(loc) self.locker.synchronize do if url = get_url(Sitemapper.urlfy(loc)) url.remove write_file end end end |