Life In The Stack Trace...

TODO: <Insert clever marketing phrase here>

Sitemaps With Namespaces

DuckMap provides support for namespaces and could be a big help for logically grouping sitemaps for large sites. Sitemaps behave in the same manner with or without a namespace. The main difference is the actual path pointing to the sitemap.

A few points:

  • Sitemap statements with or without blocks behave in the same manner regardless of namespace.
  • The physical modules/class that make up the namespace must exist
  • There is no limit to the number of sitemaps you can include regardless of namespace.

Given the following config/routes.rb

ComboCom::Application.routes.draw do

  root to: 'home#index'         # /sitemap.xml

  namespace :computers do

    sitemap                     # /computers/sitemap.xml created without using a block

    resources :desktops
    resources :laptops
    resources :printers
    resources :scanners

  end

end

Notice that we were able to insert a sitemap without using a block and the default name is still sitemap.

  • The default sitemap contains the root url and can be found at: http://localhost:3000/sitemap.xml.
  • The computers sitemap contains four routes and can be found at: http://localhost:3000/computers/sitemap.xml.

The demo application shows a few combinations of what is possible.

NamespaceCom::Application.routes.draw do

  root to: 'home#index'
  resources :faqs

  namespace :products do

    sitemap do                            # /products/sitemap.xml

      resources :papers
      resources :pencils

      namespace :audio do

        sitemap do                        # /products/audio/sitemap.xml

          resources :accessories
          resources :head_phones
          resources :speakers

        end

      end

      namespace :video do

        sitemap do                        # /products/video/sitemap.xml

          resources :accessories
          resources :dvd_players

          sitemap :bluray do              # /products/video/bluray.xml
            resources :bluray_players
          end

        end

      end

    end

  end

end