Giter VIP home page Giter VIP logo

big_sitemap's Introduction

BigSitemap

BigSitemap is a Sitemap generator suitable for Rails 2.3.2 applications with more than 50000 URLs. It splits large sitemaps into multiple files, optionally gzipping them to minimize bandwidth usage and using batched queries (find_each) on your models to avoid running out of memory.

BigSitemap is best run periodically through a Rake/Thor task. Your application environment should be loaded prior to generating sitemaps; BigSitemap uses your application database models and routing setup.

sitemap = BigSitemap.new(
  :url_options => { :host => 'example.com' },
  :batch_size => 1001, :gzip => false
)

# add a model with find options
sitemap.add(Community, :conditions => ['members_count > ?', 5])

# named scopes also work
sitemap.add(Posts.published, :change_frequency => 'weekly')

# generate it!
sitemap.generate

The code above will create 3 files at minimum:

  1. public/sitemap_index.xml
  2. public/sitemap_communities.xml
  3. public/sitemap_posts.xml

If any of your sitemaps grow beyond 50000 URLs (this limit can be changed to less with the ":max_per_sitemap" option), the sitemap files will be partitioned into multiple files ("sitemap_communities_1.xml", "sitemap_communities_2.xml", ...).

The URLs for each database record are generated with polymorphic_url helper from Rails. 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.

Advanced

BigSitemap options:

  • :url_options -- hash with :host, optionally :port and :protocol;
  • :base_url -- string alternative to :url_options, e.g. "https://example.com:8080/";
  • :document_root -- value of Rails.public_path by default (recommended not to change);
  • :max_per_sitemap -- 50000, limit dictated by Google but can be less;
  • :batch_size -- 1001;
  • :gzip -- true;
  • :ping_google -- true;
  • :ping_yahoo -- false, needs :yahoo_app_id;
  • :ping_msn -- false.

To ping search engines, call ping_search_engines after you generated the sitemap:

sitemap.generate
sitemap.ping_search_engines

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| ... }
)

Credits

Thanks to Alex Rabarts who open-sourced big_sitemap on GitHub.

Thanks to Alastair Brunton and Harry Love whose work was a starting point for big_sitemap.

Copyright (c) 2009 Stateless Systems (http://statelesssystems.com). See LICENSE for details.

big_sitemap's People

Contributors

alexrabarts avatar mislav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

moski

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.