Skip to content

Commit 2f47579

Browse files
Use static sitemaps, generated locally (#4323)
Adds - `/public/sitemap.txt` - `/public/sitemap.xml.gz` Because generating each of them is time expensive, but doesn't change very often We can re-generate them often in local dev environments and re-push them For now, to re-generate them locally, the manual steps are: From repo root, with a clean git status… ```sh git pull main git checkout -b update_static_sitemap rm public/sitemap.* bundle exec rails server curl -o public/sitemap.txt https://crimethinc.com/sitemap_txt curl -o public/sitemap.xml https://crimethinc.com/sitemap_xml gzip --force --best public/sitemap.xml git add . git commit -am "Update static sitemaps $(date)" git push ```
1 parent 7907b7d commit 2f47579

File tree

8 files changed

+11242
-7
lines changed

8 files changed

+11242
-7
lines changed

app/controllers/sitemap_controller.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ class SitemapController < ApplicationController
2222
%w[czech deutsch polski slovenscina slovensko]
2323
].flatten.freeze
2424

25-
def show
25+
before_action :set_all_data
26+
27+
def sitemap_xml; end
28+
def sitemap_text; end
29+
30+
private
31+
32+
def set_all_data
2633
set_latest_article
2734
set_last_modified
2835

@@ -87,8 +94,6 @@ def show
8794
set_episodes_last_modified
8895
end
8996

90-
private
91-
9297
def set_latest_article
9398
@latest_article = Article.published.english.first
9499
end

app/middlewares/rack/redirect.rb

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def call env
1212

1313
# special case: non-ASCII paths
1414
redirects = {
15+
'/sitemap.xml' => '/sitemap.xml.gz',
1516
'/search?utf8=✓&' => '/search',
1617
'/tce/%uFEFF' => '/tce'
1718
}
File renamed without changes.
File renamed without changes.

config/routes.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# sitemaps
55
# xml: for robots/search engines
66
# txt: for humans/archivers
7-
get 'sitemap.xml', to: 'sitemap#show', defaults: { format: 'xml' }, as: :sitemap
8-
get 'sitemap.txt', to: 'sitemap#show', defaults: { format: 'txt' }, as: :sitemap_txt
7+
get 'sitemap_xml', to: 'sitemap#sitemap_xml', defaults: { format: 'xml' }, as: :sitemap_xml
8+
get 'sitemap_txt', to: 'sitemap#sitemap_txt', defaults: { format: 'txt' }, as: :sitemap_txt
99

1010
# TODO: After switching the site auth to Devise, enable this auth protected route
1111
# # Sidekiq admin interface to monitor background jobs

0 commit comments

Comments
 (0)