Skip to content

Commit 8d28546

Browse files
authored
Merge pull request #273 from joyofrails/feat/topics
Add Topics
2 parents 96142f3 + 5ef0951 commit 8d28546

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1519
-82
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ gem "honeybadger" # Error monitoring and uptime reporting [https://www.honeybadg
5555
gem "litestream" # Standalone streaming replication for SQLite [https://litestream.io]
5656
gem "web-push" # Web Push library for Ruby [https://github.com/pushpad/web-push]
5757
gem "aws-sdk-s3" # Official AWS Ruby gem for Amazon S3 [https://github.com/aws/aws-sdk-ruby]
58+
gem "ruby-openai" # Use OpenAPI in Ruby [https://github.com/alexrudall/ruby-openai]
5859

5960
# Admin
6061
gem "flipper-ui" # UI for the Flipper gem [https://www.flippercloud.io/docs/ui]

Gemfile.lock

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,22 @@ GEM
194194
erubis (2.7.0)
195195
et-orbi (1.2.11)
196196
tzinfo
197+
event_stream_parser (1.0.0)
197198
factory_bot (6.5.0)
198199
activesupport (>= 5.0.0)
199200
factory_bot_rails (6.4.3)
200201
factory_bot (~> 6.4)
201202
railties (>= 5.0.0)
202203
faker (3.5.1)
203204
i18n (>= 1.8.11, < 2)
205+
faraday (2.12.0)
206+
faraday-net_http (>= 2.0, < 3.4)
207+
json
208+
logger
209+
faraday-multipart (1.0.4)
210+
multipart-post (~> 2)
211+
faraday-net_http (3.3.0)
212+
net-http
204213
ferrum (0.15)
205214
addressable (~> 2.5)
206215
concurrent-ruby (~> 1.1)
@@ -317,7 +326,10 @@ GEM
317326
stimulus-rails
318327
turbo-rails
319328
msgpack (1.7.3)
329+
multipart-post (2.4.1)
320330
nested_form (0.3.2)
331+
net-http (0.5.0)
332+
uri
321333
net-imap (0.5.0)
322334
date
323335
net-protocol
@@ -466,6 +478,10 @@ GEM
466478
rubocop-performance (1.22.1)
467479
rubocop (>= 1.48.1, < 2.0)
468480
rubocop-ast (>= 1.31.1, < 2.0)
481+
ruby-openai (7.3.1)
482+
event_stream_parser (>= 0.3.0, < 2.0.0)
483+
faraday (>= 1)
484+
faraday-multipart (>= 1)
469485
ruby-progressbar (1.13.0)
470486
ruby-vips (2.2.2)
471487
ffi (~> 1.12)
@@ -587,8 +603,6 @@ GEM
587603
zeitwerk (2.7.1)
588604

589605
PLATFORMS
590-
arm64-darwin-22
591-
arm64-darwin-23
592606
arm64-darwin-24
593607
x86_64-linux
594608

@@ -637,6 +651,7 @@ DEPENDENCIES
637651
reek
638652
rouge
639653
rspec-rails
654+
ruby-openai
640655
scout_apm
641656
simplecov
642657
simplecov-cobertura

app/content/layouts/article.html.erb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
) %>
1414
<%= render "application/skip_to_content" %>
1515
<%= render_layout "application" do %>
16-
<article itemscope itemtype="http://schema.org/Article">
16+
<article itemscope itemtype="http://schema.org/Article" class="mb-3xl">
1717
<%= render Pages::Header.new(
1818
title: current_page.data.title!,
1919
description: current_page.data.description,
@@ -33,9 +33,14 @@
3333
</nav>
3434
</aside>
3535
<%- end -%>
36-
<div class="article-content container mb-3xl" itemprop="articleBody">
36+
<div class="article-content container" itemprop="articleBody">
3737
<%= yield %>
3838
</div>
39+
<% if @page.topics.any? %>
40+
<section id="article-topics" class="section-content container">
41+
<%= render Pages::Topics.new(topics: @page.topics.pluck(:slug)) %>
42+
</section>
43+
<% end %>
3944
</article>
4045
<section id="newsletter-signup">
4146
<%= render "users/newsletter_subscriptions/banner" %>

app/content/models/sitepress_article.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ class SitepressArticle < Sitepress::Model
55
collection glob: "articles/*.html*"
66
data :title, :published, :updated, :summary, :description, :tags, :image
77

8-
delegate :mime_type, :handler, to: :page
8+
delegate :resource_path, :mime_type, :handler, to: :page
99

1010
def self.published(params = {})
11-
all
11+
take_published(all)
12+
end
13+
14+
def self.take_published(articles, params = {})
15+
articles
1216
.filter { |article| article.published?(preview: params[:preview]) }
13-
.sort { |a, b| b.published_on <=> a.published_on } # DESC order
17+
.sort { |a, b| b.published_on <=> a.published_on }
1418
end
1519

1620
def self.draft

app/content/models/sitepress_page.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
class SitepressPage < Sitepress::Model
22
collection glob: "**/*.html*"
33
data :title
4+
5+
def self.render_html(resource, format: :atom)
6+
type = (format == :atom && resource.handler.to_sym == :mdrb) ? :"mdrb-atom" : resource.handler
7+
content_type = (format == :atom) ? "application/atom+xml" : "text/html"
8+
9+
ApplicationController.render(
10+
inline: resource.body,
11+
type:,
12+
content_type:,
13+
layout: false,
14+
assigns: {format:}
15+
)
16+
end
417
end

app/content/models/sitepress_slash_page.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
# https://slashpages.net/
55
#
66
class SitepressSlashPage < Sitepress::Model
7-
collection glob: "{about,contact,settings}/**/*.html*"
7+
collection glob: "{about,contact,settings,deploy}/**/*.html*"
88
data :title
99
end

app/content/pages/articles/web-push-notifications-from-rails.html.mdrb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ You may have heard news: Rails 8 will extract a new framework for Web Push in Ra
1818

1919
<%= image_tag "articles/web-push-notifications-from-rails/a-web-push-notification.jpg", alt: "A Web Push Notification" %>
2020

21-
In advance of [Rails Action Notifier](https://github.com/rails/rails/issues/50454), it may be helpful to know how things will work under the hood. In this article, we’ll cover the basics of implementing Web Push yourself with Rails.
21+
Web Push is a technology enabled by making your Rails app a Progressive Web Application (PWA). With Rails 8, new apps are PWAs by default.
22+
23+
And with the pending release [Rails Action Notifier](https://github.com/rails/rails/issues/50454), due in Rails 8.1, it may be helpful to know how things will work under the hood. In this article, we’ll cover the basics of implementing Web Push yourself with Rails.
2224

2325
This article has something you won’t find in most posts about Web Push: a working demo! (in supporting browsers and devices) 😅. Try it below.
2426

app/content/pages/index.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ title: Joy of Rails
99
<%= render Pages::Summary.from_page(page, side: side) %>
1010
<% end %>
1111

12-
<%= render Pages::List.new(articles.drop(3).take(6), class: "mt-16") %>
12+
<h3 class="mt-16">More articles</h3>
13+
<%= render Pages::List.new(articles.drop(3).take(6)) %>
1314
</div>
1415
</section>
1516
<section>

app/controllers/site_controller.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ class SiteController < Sitepress::SiteController
55
# render_resource is a helper method provided by Sitepress to render the current resource.
66
# requested_resource is the Sitepress::Resource object that represents the current page.
77
#
8-
# def show
9-
# render_resource requeste_resource
10-
# end
8+
def show
9+
@page = Page.find_or_initialize_by(request_path: request.path)
10+
11+
super
12+
end
1113

1214
protected
1315

@@ -19,7 +21,7 @@ class SiteController < Sitepress::SiteController
1921
#
2022
# For example, the rendition could be modified via `Nokogiri::HTML5::DocumentFragment(rendition)`.
2123
#
22-
# @param rendition [Sitepress::Rendition] Rendered representatio of current_resource
24+
# @param rendition [Sitepress::Rendition] Rendered representation of current_resource
2325
#
2426
def process_rendition(rendition)
2527
end

app/controllers/topics_controller.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class TopicsController < ApplicationController
2+
def index
3+
@topics = Topic.approved.with_pages.order(name: :asc)
4+
end
5+
6+
def show
7+
@topics = Topic.approved.with_pages.order(name: :asc)
8+
@topic = Topic.find_by!(slug: params[:slug])
9+
end
10+
end

0 commit comments

Comments
 (0)