Module: SitemapGenerator::LinkSet::LocationHelpers
- Included in:
- SitemapGenerator::LinkSet
- Defined in:
- lib/sitemap_generator/link_set.rb
Instance Method Summary collapse
-
#compress ⇒ Object
Return the current compression setting.
-
#compress=(value) ⇒ Object
Set the value of the compress setting.
-
#create_index=(value, force = false) ⇒ Object
Set the value of
create_indexon the SitemapIndexLocation object of the SitemapIndexFile. -
#default_host=(value) ⇒ Object
Set the host name, including protocol, that will be used by default on each of your sitemap links.
-
#filename=(value) ⇒ Object
Set the filename base to use when generating sitemaps (and the sitemap index).
-
#namer ⇒ Object
Return the namer object.
-
#namer=(value) ⇒ Object
Set the namer to use to generate the sitemap (and index) file names.
-
#public_path ⇒ Object
Return a Pathname with the full path to the public directory.
-
#public_path=(value) ⇒ Object
Set the public_path.
-
#search_engines ⇒ Object
Return the hash of search engines.
-
#search_engines=(value) ⇒ Object
Set the search engines hash to a new hash of search engine names mapped to ping URLs (see ping_search_engines).
-
#sitemap_index_location ⇒ Object
Return a new
SitemapIndexLocationinstance with the current options included. -
#sitemap_location ⇒ Object
Return a new
SitemapLocationinstance with the current options included. -
#sitemaps_host=(value) ⇒ Object
Set the host name, including protocol, that will be used on all links to your sitemap files.
-
#sitemaps_path=(value) ⇒ Object
Set the sitemaps_path.
Instance Method Details
#compress ⇒ Object
Return the current compression setting. Its value determines which files will be gzip’ed. See the setter for documentation of its values.
656 657 658 |
# File 'lib/sitemap_generator/link_set.rb', line 656 def compress @compress end |
#compress=(value) ⇒ Object
Set the value of the compress setting.
Values:
* `true` - Boolean; compress all files
* `false` - Boolean; write out only uncompressed files
* `:all_but_first` - Symbol; leave the first file uncompressed but compress any remaining files.
The compression setting applies to groups too. So :all_but_first will have the same effect (the first file in the group will not be compressed, the rest will). So if you require different behaviour for your groups, pass in a ‘:compress` option e.g. group(:compress => false) { add('/link') }
648 649 650 651 652 |
# File 'lib/sitemap_generator/link_set.rb', line 648 def compress=(value) @compress = value @sitemap_index.location[:compress] = @compress if @sitemap_index @sitemap.location[:compress] = @compress if @sitemap end |
#create_index=(value, force = false) ⇒ Object
Set the value of create_index on the SitemapIndexLocation object of the SitemapIndexFile.
Whether to create a sitemap index file. Supported values: ‘true`, `false`, `:auto`. If `true` an index file is always created, regardless of how many links are in your sitemap. If `false` an index file is never created. If `:auto` an index file is created only if your sitemap has more than one sitemap file.
615 616 617 618 619 620 621 |
# File 'lib/sitemap_generator/link_set.rb', line 615 def create_index=(value, force = false) @create_index = value # Allow overriding the protected status of the index when we are creating a group. # Because sometimes we need to force an index in that case. But generally we don't # want to allow people to mess with this value if the index is protected. @sitemap_index.location[:create_index] = value if @sitemap_index && ((!@sitemap_index.finalized? && !@protect_index) || force) end |
#default_host=(value) ⇒ Object
Set the host name, including protocol, that will be used by default on each of your sitemap links. You can pass a different host in your options to ‘add` if you need to change it on a per-link basis.
508 509 510 511 |
# File 'lib/sitemap_generator/link_set.rb', line 508 def default_host=(value) @default_host = value update_location_info(:host, value) end |
#filename=(value) ⇒ Object
Set the filename base to use when generating sitemaps (and the sitemap index).
Example
filename = :sitemap
Generates
sitemap.xml.gz, sitemap1.xml.gz, sitemap2.xml.gz, ...
560 561 562 563 |
# File 'lib/sitemap_generator/link_set.rb', line 560 def filename=(value) @filename = value self.namer = SitemapGenerator::SimpleNamer.new(@filename) end |
#namer ⇒ Object
Return the namer object. If it is not set, looks for it on the current sitemap and if there is no sitemap, creates a new one using the current filename.
634 635 636 |
# File 'lib/sitemap_generator/link_set.rb', line 634 def namer @namer ||= @sitemap && @sitemap.location.namer || SitemapGenerator::SimpleNamer.new(@filename) end |
#namer=(value) ⇒ Object
Set the namer to use to generate the sitemap (and index) file names. This should be an instance of SitemapGenerator::SimpleNamer
625 626 627 628 629 |
# File 'lib/sitemap_generator/link_set.rb', line 625 def namer=(value) @namer = value @sitemap.location[:namer] = value if @sitemap && !@sitemap.finalized? @sitemap_index.location[:namer] = value if @sitemap_index && !@sitemap_index.finalized? && !@protect_index end |
#public_path ⇒ Object
Return a Pathname with the full path to the public directory
530 531 532 |
# File 'lib/sitemap_generator/link_set.rb', line 530 def public_path @public_path ||= self.send(:public_path=, 'public/') end |
#public_path=(value) ⇒ Object
Set the public_path. This path gives the location of your public directory. The default is the public/ directory in your Rails root. Or if Rails is not found, it defaults to public/ in the current directory (of the process).
Example: ‘tmp/’ if you don’t want to generate in public for some reason.
Set to nil to use the current directory.
520 521 522 523 524 525 526 527 |
# File 'lib/sitemap_generator/link_set.rb', line 520 def public_path=(value) @public_path = Pathname.new(SitemapGenerator::Utilities.append_slash(value)) if @public_path.relative? @public_path = SitemapGenerator.app.root + @public_path end update_location_info(:public_path, @public_path) @public_path end |
#search_engines ⇒ Object
Return the hash of search engines.
575 576 577 |
# File 'lib/sitemap_generator/link_set.rb', line 575 def search_engines @search_engines || {} end |
#search_engines=(value) ⇒ Object
Set the search engines hash to a new hash of search engine names mapped to ping URLs (see ping_search_engines). If the value is nil it is converted to an empty hash.
Example
search_engines = { :google => "http://www.google.com/webmasters/sitemaps/ping?sitemap=%s" }
570 571 572 |
# File 'lib/sitemap_generator/link_set.rb', line 570 def search_engines=(value) @search_engines = value || {} end |
#sitemap_index_location ⇒ Object
Return a new SitemapIndexLocation instance with the current options included
594 595 596 597 598 599 600 601 602 603 604 605 |
# File 'lib/sitemap_generator/link_set.rb', line 594 def sitemap_index_location SitemapGenerator::SitemapLocation.new( host: sitemaps_host, namer: namer, public_path: public_path, sitemaps_path: @sitemaps_path, adapter: @adapter, verbose: verbose, create_index: @create_index, compress: @compress ) end |
#sitemap_location ⇒ Object
Return a new SitemapLocation instance with the current options included
580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/sitemap_generator/link_set.rb', line 580 def sitemap_location SitemapGenerator::SitemapLocation.new( host: sitemaps_host, namer: namer, public_path: public_path, sitemaps_path: @sitemaps_path, adapter: @adapter, verbose: verbose, compress: @compress, max_sitemap_links: max_sitemap_links ) end |
#sitemaps_host=(value) ⇒ Object
Set the host name, including protocol, that will be used on all links to your sitemap files. Useful when the server that hosts the sitemaps is not on the same host as the links in the sitemap.
Note that ‘include_index` will be turned off to avoid adding a link to a sitemap with a different host than the other links.
548 549 550 551 |
# File 'lib/sitemap_generator/link_set.rb', line 548 def sitemaps_host=(value) @sitemaps_host = value update_location_info(:host, value) end |
#sitemaps_path=(value) ⇒ Object
Set the sitemaps_path. This path gives the location to write sitemaps to relative to your public_path. Example: ‘sitemaps/’ to generate your sitemaps in ‘public/sitemaps/’.
537 538 539 540 |
# File 'lib/sitemap_generator/link_set.rb', line 537 def sitemaps_path=(value) @sitemaps_path = value update_location_info(:sitemaps_path, value) end |