安装
Gemfile
gem 'sitemap_generator'
生成config/sitemap.rb
bundle exec rake sitemap:install
修改SitemapGenerator::Sitemap.default_host
config/sidemap.rb
SitemapGenerator::Sitemap.default_host = 'http://example.com'
在public/下生成sitemap文件
# Development/Test环境
bundle exec rake sitemap:refresh:no_ping
# Production环境
bundle exec rake sitemap:refresh
结果如下:
rake sitemap:refresh:no_ping
> In /app_path/to/public/
> + sitemap1.xml.gz 1 links > / 340 Bytes
> + sitemap_index.xml.gz 1 sitemaps > / 241 Bytes
> Sitemap stats: 1 links / 1 sitemaps / 0m00s
修改Robots.txt
Robots.txt
Sitemap: http://www.example.com/sitemap.xml.gz
Deployments & Capistrano
require 'capistrano/sitemap_generator'
可使用的命令:
deploy:sitemap:create #Create sitemaps without pinging search engines
deploy:sitemap:refresh #Create sitemaps and ping search engines
deploy:sitemap:clean #Clean up sitemaps in the sitemap path
参考网站