<commit_before>= BigSitemap

BigSitemap is a Sitemap (http://sitemaps.org) generator suitable for applications with greater than 50,000 URLs.  It splits large Sitemaps into multiple files, gzips the files to minimize bandwidth usage, batches database queries to minimize memory usage, can be set up with just a few lines of code and is compatible with just about any framework.

BigSitemap is best run periodically through a Rake/Thor task.

  require 'big_sitemap'

  sitemap = BigSitemap.new(:url_options => {:host => 'example.com'})

  # Add a model
  sitemap.add Product

  # Add another model with some options
  sitemap.add(Post, {
    :conditions       => {:published => true},
    :path             => 'articles',
    :change_frequency => 'daily',
    :priority         => 0.5
  })

  # Generate the files
  sitemap.generate

The code above will create a minimum of three files:

1. public/sitemaps/sitemap_index.xml.gz
2. public/sitemaps/sitemap_products.xml.gz
3. public/sitemaps/sitemap_posts.xml.gz

If your sitemaps grow beyond 50,000 URLs (this limit can be overridden with the <code>:max_per_sitemap</code> option), the sitemap files will be partitioned into multiple files (<code>sitemap_products_1.xml.gz</code>, <code>sitemap_products_2.xml.gz</code>, ...).

If you're using Rails then the URLs for each database record are generated with the <code>polymorphic_url</code> helper.  That means that the URL for a record will be exactly what you would expect: generated with respect to the routing setup of your app.  In other contexts where this helper isn't available, the URLs are generated in the form:

  :base_url/:path/:to_param

If the <code>to_param</code> method does not exist, then <code>id</code> will be used.

== Install

Via gem:

  sudo gem install alexrabarts-big_sitemap -s http://gems.github.com

== Advanced

=== Options

* <code>:url_options</code> -- hash with <code>:host</code>, optionally <code>:port</code> and <code>:protocol</code>
* <code>:base_url</code> -- string alternative to <code>:url_options</code>, e.g. "https://example.com:8080/"
* <code>:document_root</code> -- string defaults to <code>Rails.root</code> or <code>Merb.root</code> if available
* <code>:path</code> -- string defaults to 'sitemaps', which places sitemap files under the <code>/sitemaps</code> directory
* <code>:max_per_sitemap</code> -- <code>50000</code>, which is the limit dictated by Google but can be less
* <code>:batch_size</code> -- <code>1001</code> (not <code>1000</code> due to a bug in DataMapper)
* <code>:gzip</code> -- <code>true</code>
* <code>:ping_google</code> -- <code>true</code>
* <code>:ping_yahoo</code> -- <code>false</code>, needs <code>:yahoo_app_id</code>
* <code>:ping_msn</code> -- <code>false</code>
* <code>:ping_ask</code> -- <code>false</code>

=== Chaining

You can chain methods together.  You could even get away with as little code as:

  BigSitemap.new(:url_options => {:host => 'example.com'}).add(Post).generate

=== Pinging Search Engines

To ping search engines, call <code>ping_search_engines</code> after you generate the sitemap:

  sitemap.generate
  sitemap.ping_search_engines

=== Change Frequency and Priority

You can control "changefreq" and "priority" values for each record individually by passing lambdas instead of fixed values:

  sitemap.add(Posts,
    :change_frequency => lambda {|post| ... },
    :priority         => lambda {|post| ... }
  )

=== Find Methods

Your models must provide either a <code>find_for_sitemap</code> or <code>all</code> class method that returns the instances that are to be included in the sitemap.

Additionally, you models must provide a <code>count_for_sitemap</code> or <code>count</code> class method that returns a count of the instances to be included.

If you're using ActiveRecord (Rails) or DataMapper then <code>all</code> and <code>count</code> are already provided and you don't need to do anything unless you want to include a subset of records.  If you provide your own <code>find_for_sitemap</code> or <code>all</code> method then it should be able to handle the <code>:offset</code> and <code>:limit</code> options, in the same way that ActiveRecord and DataMapper handle them.  This is especially important if you have more than 50,000 URLs.

=== Cleaning the Sitemaps Directory

Calling the <code>clean</code> method will remove all files from the Sitemaps directory.

== Limitations

If your database is likely to shrink during the time it takes to create the sitemap then you might run into problems (the final, batched SQL select will overrun by setting a limit that is too large since it is calculated from the count, which is queried at the very beginning).  Patches welcome!

== TODO

Tests for Rails components.

== Credits

Thanks to <NAME> and <NAME>, who's work provided a starting point for this library.
http://scoop.cheerfactory.co.uk/2008/02/26/google-sitemap-generator/

Thanks to those who can contributed patches:

  * <NAME>
  * <NAME>

== Copyright

Copyright (c) 2009 Stateless Systems (http://statelesssystems.com). See LICENSE for details.<commit_msg>Fix RDoc formatting and typo<commit_after>= BigSitemap

BigSitemap is a Sitemap (http://sitemaps.org) generator suitable for applications with greater than 50,000 URLs.  It splits large Sitemaps into multiple files, gzips the files to minimize bandwidth usage, batches database queries to minimize memory usage, can be set up with just a few lines of code and is compatible with just about any framework.

BigSitemap is best run periodically through a Rake/Thor task.

  require 'big_sitemap'

  sitemap = BigSitemap.new(:url_options => {:host => 'example.com'})

  # Add a model
  sitemap.add Product

  # Add another model with some options
  sitemap.add(Post, {
    :conditions       => {:published => true},
    :path             => 'articles',
    :change_frequency => 'daily',
    :priority         => 0.5
  })

  # Generate the files
  sitemap.generate

The code above will create a minimum of three files:

1. public/sitemaps/sitemap_index.xml.gz
2. public/sitemaps/sitemap_products.xml.gz
3. public/sitemaps/sitemap_posts.xml.gz

If your sitemaps grow beyond 50,000 URLs (this limit can be overridden with the <code>:max_per_sitemap</code> option), the sitemap files will be partitioned into multiple files (<code>sitemap_products_1.xml.gz</code>, <code>sitemap_products_2.xml.gz</code>, ...).

If you're using Rails then the URLs for each database record are generated with the <code>polymorphic_url</code> helper.  That means that the URL for a record will be exactly what you would expect: generated with respect to the routing setup of your app.  In other contexts where this helper isn't available, the URLs are generated in the form:

  :base_url/:path/:to_param

If the <code>to_param</code> method does not exist, then <code>id</code> will be used.

== Install

Via gem:

  sudo gem install alexrabarts-big_sitemap -s http://gems.github.com

== Advanced

=== Options

* <code>:url_options</code> -- hash with <code>:host</code>, optionally <code>:port</code> and <code>:protocol</code>
* <code>:base_url</code> -- string alternative to <code>:url_options</code>, e.g. "https://example.com:8080/"
* <code>:document_root</code> -- string defaults to <code>Rails.root</code> or <code>Merb.root</code> if available
* <code>:path</code> -- string defaults to 'sitemaps', which places sitemap files under the <code>/sitemaps</code> directory
* <code>:max_per_sitemap</code> -- <code>50000</code>, which is the limit dictated by Google but can be less
* <code>:batch_size</code> -- <code>1001</code> (not <code>1000</code> due to a bug in DataMapper)
* <code>:gzip</code> -- <code>true</code>
* <code>:ping_google</code> -- <code>true</code>
* <code>:ping_yahoo</code> -- <code>false</code>, needs <code>:yahoo_app_id</code>
* <code>:ping_msn</code> -- <code>false</code>
* <code>:ping_ask</code> -- <code>false</code>

=== Chaining

You can chain methods together.  You could even get away with as little code as:

  BigSitemap.new(:url_options => {:host => 'example.com'}).add(Post).generate

=== Pinging Search Engines

To ping search engines, call <code>ping_search_engines</code> after you generate the sitemap:

  sitemap.generate
  sitemap.ping_search_engines

=== Change Frequency and Priority

You can control "changefreq" and "priority" values for each record individually by passing lambdas instead of fixed values:

  sitemap.add(Posts,
    :change_frequency => lambda {|post| ... },
    :priority         => lambda {|post| ... }
  )

=== Find Methods

Your models must provide either a <code>find_for_sitemap</code> or <code>all</code> class method that returns the instances that are to be included in the sitemap.

Additionally, you models must provide a <code>count_for_sitemap</code> or <code>count</code> class method that returns a count of the instances to be included.

If you're using ActiveRecord (Rails) or DataMapper then <code>all</code> and <code>count</code> are already provided and you don't need to do anything unless you want to include a subset of records.  If you provide your own <code>find_for_sitemap</code> or <code>all</code> method then it should be able to handle the <code>:offset</code> and <code>:limit</code> options, in the same way that ActiveRecord and DataMapper handle them.  This is especially important if you have more than 50,000 URLs.

=== Cleaning the Sitemaps Directory

Calling the <code>clean</code> method will remove all files from the Sitemaps directory.

== Limitations

If your database is likely to shrink during the time it takes to create the sitemap then you might run into problems (the final, batched SQL select will overrun by setting a limit that is too large since it is calculated from the count, which is queried at the very beginning).  Patches welcome!

== TODO

Tests for Rails components.

== Credits

Thanks to <NAME> and <NAME>, who's work provided a starting point for this library.
http://scoop.cheerfactory.co.uk/2008/02/26/google-sitemap-generator/

Thanks to those who have contributed patches:

* <NAME>
* <NAME>

== Copyright

Copyright (c) 2009 Stateless Systems (http://statelesssystems.com). See LICENSE for details.
{'fraction_non_alphanumeric': 0.11054588143220505, 'fraction_numerical': 0.0099784777929955, 'mean_word_length': 4.372044140830268, 'pattern_counts': {'":': 0, '<': 191, '<?xml version=': 0, '>': 213, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '702644', 'n_tokens_mistral': 3201, 'n_tokens_neox': 3026, 'n_words': 1173}