Sha256: 2b0d6a39513d61d25929119a0e67182a99e780113248f44026ea822058b13256

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

namespace :sitemap do
  task generate: :environment do
    SitemapGenerator::Sitemap.default_host = '<%= Rails.configuration.sitemap_config_variable[:production_url] %>'
    SitemapGenerator::Sitemap.create_index = false
    SitemapGenerator::Sitemap.create do
      routes = Rails.application.routes.routes.map do |route|
        {
          alias: route.name,
          path: route.path.spec.to_s,
          controller: route.defaults[:controller],
          action: route.defaults[:action],
        }
      end

      # Set a list of controllers you don't want to generate routes for.
      # /rails/info in particular maps to something inaccessible.
      # redirects have a nil controller. This prevents duplicate content penalties.
      banned_controllers = ["rails/info", nil]
      routes.reject! { |route| banned_controllers.include?(route[:controller]) }

      # sitemap_generator includes root by default; prevent duplication
      routes.reject! { |route| route[:path] == '/' }

      routes.each { |route| add route[:path][0..-11] } # Strips off '(.:format)

      # Notice the below if you're hosting Jekyll/Octopress in a subdirectory
      # or otherwise want to index content outside of Rails' routes.
      # add_to_index '/sitemaps/show.xml'

      # example for user resources
      # User.select(:seo_slug, :updated_at).each do |slug|
      #   add user_path(slug), lastmod: slug.updated_at
      # end
    end
  end

  task ping_search_engines: :environment do
    SitemapGenerator::Sitemap.ping_search_engines('<%= Rails.configuration.sitemap_config_variable[:production_url] %>/sitemap.xml')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seo_optimizer-0.1.2 lib/generators/seo_optimizer/robots_files/templates/sitemaps_task_template.erb