Skip to content

Commit 110a998

Browse files
Fix /page/:page routes for 2025 theme (#4249)
Most notable change is: Before in 2017 theme, routes like `/page/2` were handled by `home#index` They were the homepage with a different collection of articles, and no "latest article" Now in 2025 theme, routes like `/page/2` are handled by `articles#index` They are the same `article_archives#index` So, in the transitional time from 2017 theme to 2025, the `articles#index` controller action receives the `/page/2` request, then does the same setup and render as `home#index` (literally copy/pasted from `home#index`) After the transition is launched and announced, we can delete all of the double dispatch code
1 parent 86ef870 commit 110a998

File tree

8 files changed

+125
-44
lines changed

8 files changed

+125
-44
lines changed

app/controllers/application_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def next_theme = '2025'
8282

8383
def pages_for_2025_theme
8484
%w[
85+
articles#index
8586
article_archives#index
8687
home#index
8788
languages#index

app/controllers/articles_controller.rb

+44-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
11
class ArticlesController < ApplicationController
22
skip_before_action :check_for_redirection, only: :index
33

4+
before_action :set_page_number, only: :index
5+
before_action :redirect_malformed_pagination, only: :index
6+
before_action :force_2025_theme_for_feeds, only: :index
7+
48
def index
9+
# TEMP: copied from home#index because the route /page/:page changed
10+
# from home#index in 2017 theme
11+
# to articles#index in 2025 theme
12+
if Current.theme == '2017'
13+
14+
@body_id = 'home'
15+
@homepage = true
16+
17+
articles_for_current_page = Article.includes(:categories).english.live.published.root
18+
19+
# Homepage featured article
20+
@latest_article = articles_for_current_page.first if params[:page].blank?
21+
22+
# Feed artciles
23+
@articles = articles_for_current_page.page(params[:page]).per(6)
24+
25+
render "#{Current.theme}/home/index"
26+
end
27+
28+
return unless Current.theme == '2025'
29+
530
@articles = Article.includes(:tags, :categories)
631
.for_index(**filters)
732
.root
8-
.page(params[:page])
9-
.per(10)
33+
.page(@page_number)
34+
.per(15)
1035

1136
locale = Locale.find_by(abbreviation: params[:lang])
1237
@lang = locale.abbreviation if locale.present?
@@ -110,4 +135,21 @@ def content_without_embeds
110135
def docx_mimetype
111136
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
112137
end
138+
139+
def set_page_number
140+
return if params[:page].blank?
141+
142+
@page_number = params[:page].gsub(/\D/, '')
143+
end
144+
145+
def redirect_malformed_pagination
146+
return if params[:format].in? %w[json atom]
147+
return if @page_number == params[:page]
148+
149+
redirect_to [:articles, { page: @page_number }]
150+
end
151+
152+
def force_2025_theme_for_feeds
153+
Current.theme = '2025' if params[:format].in? %w[json atom]
154+
end
113155
end

app/controllers/home_controller.rb

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
class HomeController < ApplicationController
2-
def index
3-
@body_id = 'home'
4-
@homepage = true
2+
before_action :redirect_pagination
53

4+
def index
65
articles_for_current_page = Article.includes(:categories).english.live.published.root
76

8-
# Homepage featured article
9-
@latest_article = articles_for_current_page.first if first_page?
7+
if Current.theme == '2017'
8+
@body_id = 'home'
9+
@homepage = true
1010

11-
if Current.theme == '2025'
11+
# Homepage featured article
12+
@latest_article = articles_for_current_page.first if first_page?
13+
14+
# Feed artciles
15+
@articles = articles_for_current_page.page(params[:page]).per(6).padding(1)
16+
else
1217
# Feed artciles, needed for pagination
1318
@articles = articles_for_current_page.page(params[:page]).per(14).padding(1)
1419

20+
# Homepage featured article
21+
@latest_article = articles_for_current_page.first
22+
1523
# Recent article
1624
@just_published_articles = @articles[0..3]
1725

@@ -39,9 +47,6 @@ def index
3947

4048
# Ex-Workers’ Collection
4149
@ex_workers_collection = Article.featured
42-
else
43-
# Feed artciles
44-
@articles = articles_for_current_page.page(params[:page]).per(6).padding(1)
4550
end
4651

4752
render "#{Current.theme}/home/index"
@@ -52,4 +57,10 @@ def index
5257
def first_page?
5358
params[:page].blank?
5459
end
60+
61+
def redirect_pagination
62+
return if params[:page].blank?
63+
64+
redirect_to [:articles, { page: params[:page] }]
65+
end
5566
end
+37-29
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
1-
<%# TODO delete this view %>
2-
<header>
3-
<h1>
4-
<%= link_to "Archives", [:library] %> :
5-
<time>
6-
<%= link_to_dates(year: @articles_year, month: @articles_month, day: @articles_day) %>
7-
</time>
8-
</h1>
9-
</header>
1+
<% content_for(:head) do %>
2+
<%= rel_next_prev_link_tags @articles %>
3+
<% end %>
104

11-
<% if @articles.nil? %>
12-
<h2>No archives for this time period.</h2>
13-
<% else %>
14-
<ol class="h-feed">
15-
<% @articles.each do |article| %>
16-
<li>
17-
<article class="h-entry">
18-
<header>
19-
<%= render_themed "articles/titles", header: article, linked: true %>
20-
</header>
5+
<div class='container'>
6+
<div class='row'>
7+
<div class='col-md-6 col-lg-8'>
8+
<header class='titles pb-3 mb-4 border-bottom'>
9+
<h1><%= tt :articles %></h1>
10+
<h2 class='fw-light'><%= tt :page %> <%= @page_number %></h2>
11+
</header>
2112

22-
<footer>
23-
<%= render_themed "articles/published_on", article: article %>
24-
<%= render_themed "articles/categories", article: article %>
25-
<%= render_themed "articles/tags", article: article %>
26-
</footer>
27-
</article>
28-
</li>
29-
<% end %>
30-
</ol>
31-
<% end %>
13+
<div class='h-feed'>
14+
<% @articles.each do |article| %>
15+
<%= render_themed 'articles/article', article: article %>
16+
<% end %>
17+
</div>
18+
19+
<%= paginate @articles, theme: 'twitter-bootstrap-4' %>
20+
</div>
21+
22+
<div class='col-md-6 col-lg-4'>
23+
<header class='titles pb-3 mb-2 border-bottom fw-normal'>
24+
<h1 class='fw-normal'>See also…</h1>
25+
<h2 class='fw-normal'>Explore The Archives</h2>
26+
</header>
27+
28+
<div id='categories' class='mb-5 pt-3'>
29+
<h2 class='h4 fw-bold'><%= link_to tt(:categories_heading), '#categories' %></h2>
30+
<%= render_themed 'categories/list', categories: @categories %>
31+
</div>
32+
33+
<div id='years' class='mb-5 pt-3'>
34+
<h2 class='h4 fw-bold'><%= link_to tt(:chronological_heading), '#years' %></h2>
35+
<%= render_themed 'years/list', years: @years %>
36+
</div>
37+
</div>
38+
</div><!-- .row -->
39+
</div><!-- .container -->

app/views/2025/home/sections/_articles.html.erb

+11-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
<% end %>
3232
</ol>
3333

34-
<p class='fw-bold'><%= link_to_next_page articles, "#{tt :more_articles} →" %></p>
34+
<p class='fw-bold'>
35+
<%= link_to [:articles, page: 2] do %>
36+
<%= tt :more_articles %>
37+
<% end %>
38+
</p>
3539
</div>
3640

3741
<div class='col-12 col-lg-4'>
@@ -50,7 +54,12 @@
5054
<% end %>
5155
</ol>
5256

53-
<p class='fw-bold text-end'><%= link_to_next_page articles, "#{tt :more_articles} →" %></p>
57+
<p class='fw-bold text-end'>
58+
<%= link_to [:articles, page: 2] do %>
59+
<%= tt :more_articles %>
60+
<% end %>
61+
</p>
62+
5463
</div>
5564
</section>
5665
<!-- /Recent and previous articles -->
+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
Kaminari.configure do |config|
2+
# config.default_per_page = 25
3+
# config.max_per_page = nil
24
config.window = 1
35
config.outer_window = 3
6+
# config.left = 0
7+
# config.right = 0
8+
# config.page_method_name = :page
9+
# config.param_name = :page
10+
# config.max_pages = nil
11+
config.params_on_first_page = true # forces /page/1 instead of /
412
end

config/locales/en/2025.yml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ en:
2828
adventure: Adventure
2929
analysis: Analysis
3030
archives: The Archives
31+
articles: Articles
3132
arts: Arts
3233
books: Books
3334
categories: Categories
@@ -42,6 +43,7 @@ en:
4243
logos: Logos
4344
music: Music
4445
news: News
46+
page: Page
4547
podcasts: Podcasts
4648
posters: Posters
4749
published: Published

config/routes.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
# Homepage
2727
root to: 'home#index'
2828

29-
get 'page(/1)', to: redirect { |_, _| '/' }
30-
get 'page/:page', to: 'home#index'
29+
get 'page', to: redirect('/page/1'), as: :page_one
30+
get 'page/:page', to: 'articles#index', as: :articles
3131

3232
# To Change Everything (TCE)
3333
get 'tce(/:lang)',

0 commit comments

Comments
 (0)