@@ -10,7 +10,6 @@ class SitemapController < ApplicationController
10
10
kickstarter/2017
11
11
library
12
12
start
13
- steal-something-from-work-day
14
13
store
15
14
tce
16
15
tools
@@ -24,84 +23,219 @@ class SitemapController < ApplicationController
24
23
] . flatten . freeze
25
24
26
25
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
30
28
31
29
# articles feed, for all languages with articles
32
- @localized_feeds = Locale . unscoped . order ( name_in_english : :asc )
30
+ set_localized_feeds
33
31
34
32
# categories
35
- @categories = Category . all
33
+ set_categories
34
+
35
+ # tags
36
+ set_tags
36
37
37
38
# articles
38
- @articles = live_published_articles
39
+ set_articles
39
40
40
41
# articles by year
41
- @article_years = ( 1996 .. Time . zone . today . year ) . to_a
42
+ set_article_years
42
43
43
44
# static-ish pages
44
- @static_paths = STATIC_PATHS
45
+ set_static_paths
45
46
46
47
# 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
48
52
49
53
# languages
50
- @locales = languages
54
+ set_locales
51
55
52
56
# tools
53
57
# 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
54
155
@books = Book . published . live
156
+ end
55
157
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
57
163
@logos = Logo . published . live
164
+ end
58
165
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
60
171
@posters = Poster . published . live
172
+ end
61
173
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
63
179
@stickers = Sticker . published . live
180
+ end
64
181
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
66
187
@videos = Video . published . live
188
+ end
67
189
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
69
195
@zines = Zine . published . live
196
+ end
70
197
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
72
203
@journals = Journal . published . live
73
- @issues = Issue . published . live
204
+ end
74
205
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
78
209
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
83
212
end
84
213
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
86
217
87
- def sitemap_url = Data . define ( :loc , :lastmod )
218
+ def set_podcasts
219
+ @podcasts = Podcast . published . live
220
+ end
88
221
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
95
225
96
- [ unicode_url , slug_url , english_url ] . uniq
97
- end
226
+ def set_episodes
227
+ @episodes = Episode . published . live
98
228
end
99
229
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
106
240
end
107
241
end
0 commit comments