Skip to content

Commit

Permalink
Render Pages sitemap at root level
Browse files Browse the repository at this point in the history
  • Loading branch information
elektronaut committed Sep 23, 2024
1 parent 7734be1 commit 1edcc51
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 44 deletions.
43 changes: 43 additions & 0 deletions app/controllers/pages_core/sitemaps_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

module PagesCore
class SitemapsController < ApplicationController
include PagesCore::PagePathHelper
static_cache :index, :pages

def index
@sitemaps = PagesCore::Sitemap.sitemaps.flat_map do |entry|
if entry.is_a?(Proc)
locales.map { |l| instance_exec(l, &entry) }
else
entry
end
end.compact_blank.uniq
end

def pages
respond_to do |format|
format.xml { render xml: pages_sitemap.to_xml }
end
end

private

def pages_sitemap
pages = Page.published.where.not(skip_index: true)
.localized(content_locale)

PagesCore::Sitemap.new do |map|
pages.each { |p| map.add(page_url(p.locale, p), lastmod: p.updated_at) }
end
end

def locales
if PagesCore.config.locales
PagesCore.config.locales.keys
else
[I18n.default_locale]
end
end
end
end
40 changes: 0 additions & 40 deletions app/controllers/sitemaps_controller.rb

This file was deleted.

File renamed without changes.
8 changes: 4 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
get "pages/:locale/*glob" => redirect("/%{locale}/pages/%{glob}"),
locale: /\w\w\w/

# Sitemap
resource :sitemap, only: [:show] do
get :pages, path: ":locale/pages"
end
# Sitemaps
get("sitemap" => "pages_core/sitemaps#index", as: :sitemap_index)
get("/sitemap-pages-:locale" => "pages_core/sitemaps#pages",
as: :pages_sitemap)

namespace :admin do
get "users/login" => redirect("/admin/login")
Expand Down

0 comments on commit 1edcc51

Please sign in to comment.