Skip to content

Commit 86ef870

Browse files
Add some missing URLs to sitemaps (#4244)
- `articles#show` as `.markdown` - months of the years `/2025/01`, `/2024/12`, ... - contradictionary definitions - SSfWD -
1 parent 1a736cf commit 86ef870

File tree

6 files changed

+264
-70
lines changed

6 files changed

+264
-70
lines changed

.rubocop.yml

+16-16
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ require:
1111
AllCops:
1212
NewCops: enable
1313
Exclude:
14-
- 'db/schema.rb'
15-
- 'db/migrate/20230628052836_init_schema.rb'
16-
- 'vendor/**/*'
14+
- "db/schema.rb"
15+
- "db/migrate/20230628052836_init_schema.rb"
16+
- "vendor/**/*"
1717

1818
Layout/HashAlignment:
1919
EnforcedHashRocketStyle: table
2020
EnforcedColonStyle: table
2121

2222
Layout/LineLength:
2323
Exclude:
24-
- 'db/**/*'
24+
- "db/**/*"
2525

2626
# This is too aggressive with our use of Seattle.rb style lack of parens on method calls
2727
# E.g., return redirect_to [:articles]
@@ -30,23 +30,23 @@ Layout/SpaceBeforeBrackets:
3030
Enabled: false
3131

3232
Metrics/AbcSize:
33-
Max: 74
33+
Max: 80
3434

3535
Metrics/BlockLength:
3636
Max: 99
3737
Exclude:
38-
- 'config/routes.rb'
38+
- "config/routes.rb"
3939

4040
Metrics/ClassLength:
41-
Max: 145
41+
Max: 180
4242

4343
Metrics/CyclomaticComplexity:
4444
Max: 13
4545

4646
Metrics/MethodLength:
47-
Max: 31
47+
Max: 40
4848
Exclude:
49-
- 'db/migrate/*'
49+
- "db/migrate/*"
5050

5151
Metrics/ModuleLength:
5252
Max: 116
@@ -68,29 +68,29 @@ Rails/EnvironmentVariableAccess:
6868
# Using `puts` is allowed in these files
6969
Rails/Output:
7070
Exclude:
71-
- 'app/lib/code_archiver.rb'
72-
- 'db/seeds.rb'
71+
- "app/lib/code_archiver.rb"
72+
- "db/seeds.rb"
7373

7474
Rails/TimeZone:
7575
Exclude:
76-
- 'script/*'
76+
- "script/*"
7777

7878
RSpec/DescribeClass:
7979
Exclude:
80-
- 'spec/system/*'
80+
- "spec/system/*"
8181

8282
RSpec/ExampleLength:
8383
Max: 14
8484
Exclude:
85-
- 'spec/system/*'
85+
- "spec/system/*"
8686

8787
RSpec/MessageSpies:
8888
Enabled: false
8989

9090
RSpec/MultipleExpectations:
9191
Max: 5
9292
Exclude:
93-
- 'spec/system/*'
93+
- "spec/system/*"
9494

9595
Style/AsciiComments:
9696
Enabled: false
@@ -106,7 +106,7 @@ Style/MethodDefParentheses:
106106

107107
Style/MixinUsage:
108108
Exclude:
109-
- 'script/*'
109+
- "script/*"
110110

111111
Style/RedundantFetchBlock:
112112
Enabled: false

app/controllers/sitemap_controller.rb

+175-41
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class SitemapController < ApplicationController
1010
kickstarter/2017
1111
library
1212
start
13-
steal-something-from-work-day
1413
store
1514
tce
1615
tools
@@ -24,84 +23,219 @@ class SitemapController < ApplicationController
2423
].flatten.freeze
2524

2625
def show
27-
@latest_article = Article.published.english.first
28-
@last_modified = @latest_article&.updated_at || Time.current
29-
@urls = []
26+
set_latest_article
27+
set_last_modified
3028

3129
# articles feed, for all languages with articles
32-
@localized_feeds = Locale.unscoped.order(name_in_english: :asc)
30+
set_localized_feeds
3331

3432
# categories
35-
@categories = Category.all
33+
set_categories
34+
35+
# tags
36+
set_tags
3637

3738
# articles
38-
@articles = live_published_articles
39+
set_articles
3940

4041
# articles by year
41-
@article_years = (1996..Time.zone.today.year).to_a
42+
set_article_years
4243

4344
# static-ish pages
44-
@static_paths = STATIC_PATHS
45+
set_static_paths
4546

4647
# To Change Everything (TCE)
47-
@to_change_everything_languages = TO_CHANGE_EVERYTHING_LANGUAGES
48+
set_to_change_everything_languages
49+
50+
# Steal Something from Work Day (SSfWD)
51+
set_steal_something_from_work_day_urls
4852

4953
# languages
50-
@locales = languages
54+
set_locales
5155

5256
# tools
5357
# books
58+
set_books
59+
set_books_last_modified
60+
# contradictionary definitions
61+
set_definitions
62+
set_definitions_last_modified
63+
# logos
64+
set_logos
65+
set_logos_last_modified
66+
# posters
67+
set_posters
68+
set_posters_last_modified
69+
# stickers
70+
set_stickers
71+
set_stickers_last_modified
72+
# videos
73+
set_videos
74+
set_videos_last_modified
75+
# zines
76+
set_zines
77+
set_zines_last_modified
78+
# journals / issues
79+
set_journals
80+
set_journals_last_modified
81+
set_issues
82+
set_issues_last_modified
83+
# podcasts / episodes
84+
set_podcasts
85+
set_podcasts_last_modified
86+
set_episodes
87+
set_episodes_last_modified
88+
end
89+
90+
private
91+
92+
def set_latest_article
93+
@latest_article = Article.published.english.first
94+
end
95+
96+
def set_last_modified
97+
@last_modified = @latest_article&.updated_at || Time.current
98+
end
99+
100+
# articles feed, for all languages with articles
101+
def set_localized_feeds
102+
@localized_feeds = Locale.unscoped.order(name_in_english: :asc)
103+
end
104+
105+
def set_categories
106+
@categories = Category.all
107+
end
108+
109+
def set_tags
110+
@tags = Tag.all
111+
end
112+
113+
def set_articles
114+
@articles =
115+
Rails.cache.fetch([:sitemap, @latest_article, :live_published_articles], expires_in: 12.hours) do
116+
Article.live.published.select(:id, :updated_at, :draft_code, :published_at, :publication_status, :slug)
117+
end
118+
end
119+
120+
def set_article_years
121+
@article_years = (1996..Time.zone.today.year).to_a
122+
end
123+
124+
def set_static_paths
125+
@static_paths = STATIC_PATHS
126+
end
127+
128+
def set_to_change_everything_languages
129+
@to_change_everything_languages = TO_CHANGE_EVERYTHING_LANGUAGES
130+
end
131+
132+
def set_steal_something_from_work_day_urls
133+
@steal_something_from_work_day_urls = [steal_something_from_work_day_url]
134+
135+
ssfwd_locales = StealSomethingFromWorkDayController::STEAL_SOMETHING_FROM_WORK_DAY_LOCALES.keys - [:en]
136+
137+
ssfwd_locales.each do |ssfwd_locale|
138+
@steal_something_from_work_day_urls << steal_something_from_work_day_url
139+
.sub('http://', "http://#{ssfwd_locale}.")
140+
.sub('https://', "https://#{ssfwd_locale}.")
141+
end
142+
end
143+
144+
def set_locales
145+
@locales = Locale.live.each do |locale|
146+
unicode_url = language_url locale: locale.name.downcase.tr(' ', '-')
147+
slug_url = language_url locale: locale.slug.to_sym
148+
english_url = language_url locale: locale.name_in_english.downcase.tr(' ', '-')
149+
150+
[unicode_url, slug_url, english_url].uniq
151+
end
152+
end
153+
154+
def set_books
54155
@books = Book.published.live
156+
end
55157

56-
# logos
158+
def set_books_last_modified
159+
@books_last_modified = @books.unscoped.order(updated_at: :asc).first&.updated_at || Time.current
160+
end
161+
162+
def set_logos
57163
@logos = Logo.published.live
164+
end
58165

59-
# posters
166+
def set_logos_last_modified
167+
@logos_last_modified = @logos.unscoped.order(updated_at: :asc).first&.updated_at || Time.current
168+
end
169+
170+
def set_posters
60171
@posters = Poster.published.live
172+
end
61173

62-
# stickers
174+
def set_posters_last_modified
175+
@posters_last_modified = @posters.unscoped.order(updated_at: :asc).first&.updated_at || Time.current
176+
end
177+
178+
def set_stickers
63179
@stickers = Sticker.published.live
180+
end
64181

65-
# videos
182+
def set_stickers_last_modified
183+
@stickers_last_modified = @stickers.unscoped.order(updated_at: :asc).first&.updated_at || Time.current
184+
end
185+
186+
def set_videos
66187
@videos = Video.published.live
188+
end
67189

68-
# zines
190+
def set_videos_last_modified
191+
@videos_last_modified = @videos.unscoped.order(updated_at: :asc).first&.updated_at || Time.current
192+
end
193+
194+
def set_zines
69195
@zines = Zine.published.live
196+
end
70197

71-
# journals / issues
198+
def set_zines_last_modified
199+
@zines_last_modified = @zines.unscoped.order(updated_at: :asc).first&.updated_at || Time.current
200+
end
201+
202+
def set_journals
72203
@journals = Journal.published.live
73-
@issues = Issue.published.live
204+
end
74205

75-
# podcasts / episodes
76-
@podcasts = Podcast.published.live
77-
@episodes = Episode.published.live
206+
def set_journals_last_modified
207+
@journals_last_modified = @journals.unscoped.order(updated_at: :asc).first&.updated_at || Time.current
208+
end
78209

79-
# TODO: add @TOOL_latest_modified to each tool, used in view for lastmod: in url tag partial
80-
# TODO: add contradictionary definitions pages to sitemap
81-
# TODO: add tags index and show pages to sitemap
82-
# TODO: add steal-something-from-work-day localized pages
210+
def set_issues
211+
@issues = Issue.published.live
83212
end
84213

85-
private
214+
def set_issues_last_modified
215+
@issues_last_modified = @issues.unscoped.order(updated_at: :asc).first&.updated_at || Time.current
216+
end
86217

87-
def sitemap_url = Data.define(:loc, :lastmod)
218+
def set_podcasts
219+
@podcasts = Podcast.published.live
220+
end
88221

89-
# languages
90-
def languages
91-
Locale.live.each do |locale|
92-
unicode_url = language_url locale: locale.name.downcase.tr(' ', '-')
93-
slug_url = language_url locale: locale.slug.to_sym
94-
english_url = language_url locale: locale.name_in_english.downcase.tr(' ', '-')
222+
def set_podcasts_last_modified
223+
@podcasts_last_modified = @podcasts.unscoped.order(updated_at: :asc).first&.updated_at || Time.current
224+
end
95225

96-
[unicode_url, slug_url, english_url].uniq
97-
end
226+
def set_episodes
227+
@episodes = Episode.published.live
98228
end
99229

100-
def live_published_articles
101-
Rails.cache.fetch([:sitemap, @latest_article, :live_published_articles], expires_in: 12.hours) do
102-
Article.live
103-
.published
104-
.select(:id, :updated_at, :draft_code, :published_at, :publication_status, :slug)
105-
end
230+
def set_episodes_last_modified
231+
@episodes_last_modified = @episodes.unscoped.order(updated_at: :asc).first&.updated_at || Time.current
232+
end
233+
234+
def set_definitions
235+
@definitions = Definition.live.published.group_by(&:filed_under)
236+
end
237+
238+
def set_definitions_last_modified
239+
@definitions_last_modified = Definition.unscoped.order(updated_at: :asc).first&.updated_at || Time.current
106240
end
107241
end

app/lib/code_archiver.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class CodeArchiver
2-
def run # rubocop:disable Metrics/MethodLength
2+
def run
33
# make all the directories
44
system 'mkdir', '-p', articles_prefix
55
system 'mkdir', '-p', pages_prefix

0 commit comments

Comments
 (0)