File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -7,17 +7,20 @@ class ArticlePage < Sitepress::Model
7
7
8
8
delegate :mime_type , :handler , to : :page
9
9
10
- def self . published
11
- all . filter ( &:published? )
10
+ def self . published ( params = { } )
11
+ all
12
+ . filter { |article | article . published? ( preview : params [ :preview ] ) }
12
13
. sort { |a , b | b . published_on <=> a . published_on } # DESC order
13
14
end
14
15
15
16
def self . draft
16
17
all . filter ( &:draft? )
17
18
end
18
19
19
- def published?
20
- published_on . presence && published_on <= Date . today
20
+ # Consider an article published if it has a published date prior to today.
21
+ # If preview is true, consider the article published regardless of the date.
22
+ def published? ( preview : false )
23
+ published_on . presence && ( preview || published_on <= Date . today )
21
24
end
22
25
23
26
def draft? = !published?
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ title: Joy of Rails
4
4
5
5
< section style ="min-height: 51vh ">
6
6
< div class ="main-content container py-gap lg:py-3xl ">
7
- <% ArticlePage . published . take ( 4 ) . zip ( %w[ left right ] . cycle ) . each do |( page , side ) | %>
7
+ <% ArticlePage . published ( params ) . take ( 4 ) . zip ( %w[ left right ] . cycle ) . each do |( page , side ) | %>
8
8
<%= render Pages ::Summary . from_page ( page , side : side ) %>
9
9
<% end %>
10
10
</ div >
Original file line number Diff line number Diff line change 6
6
# Filter out index.html.erb from article pages before selecting first draft
7
7
let ( :first_draft ) { ArticlePage . draft . lazy . filter { |article | article . page . request_path != "/articles" } . first }
8
8
9
+ describe "GET /" do
10
+ it "lists recent published articles" do
11
+ get "/"
12
+
13
+ expect ( response ) . to have_http_status ( :ok )
14
+ end
15
+
16
+ it "supports preview flag" do
17
+ get "/" , params : { preview : true }
18
+
19
+ expect ( response ) . to have_http_status ( :ok )
20
+ end
21
+ end
22
+
9
23
describe "GET /articles" do
10
24
it "lists published articles" do
11
25
get "/articles"
You can’t perform that action at this time.
0 commit comments