Skip to content

Commit

Permalink
Merge pull request #7899 from fjordllc/feature/add-atom-feed
Browse files Browse the repository at this point in the history
外部公開ブログに atom フィードを追加
  • Loading branch information
komagata authored Jul 15, 2024
2 parents 1a854a1 + 31e85fc commit 9ca0a8a
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 6 deletions.
13 changes: 9 additions & 4 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ class ArticlesController < ApplicationController
def index
@articles = list_articles
@articles = @articles.tagged_with(params[:tag]) if params[:tag]
render layout: 'welcome'
number_per_page = @articles.page(1).limit_value
@atom_articles = list_recent_articles(number_per_page)
respond_to do |format|
format.html { render layout: 'welcome' }
format.atom
end
end

def show
@mentor = @article.user
@recent_articles = list_recent_articles
@recent_articles = list_recent_articles(10)
if @article.published? || admin_or_mentor_login?
render layout: 'welcome'
else
Expand Down Expand Up @@ -66,9 +71,9 @@ def list_articles
admin_or_mentor_login? ? articles : articles.where(wip: false)
end

def list_recent_articles
def list_recent_articles(number)
Article.with_attached_thumbnail.includes(user: { avatar_attachment: :blob })
.where(wip: false).order(published_at: :desc).limit(10)
.where(wip: false).order(published_at: :desc).limit(number)
end

def article_params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
display: flex
line-height: 1.4
flex-wrap: wrap
align-items: center
+media-breakpoint-up(md)
font-size: .8125rem
justify-content: center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
+media-breakpoint-up(lg)
gap: 1rem
justify-content: center
align-items: center
+media-breakpoint-up(md)
display: flex
flex-wrap: wrap
Expand Down Expand Up @@ -44,6 +45,12 @@
align-items: center
padding-inline: 1rem
+size(100% 2.75rem)
i
font-size: .75em
position: relative
top: -.0625em
i:first-child
margin-right: .375em
body.is-welcome &
color: var(--default-text)

Expand Down
4 changes: 3 additions & 1 deletion app/views/application/footer/_footer.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ footer.footer
li.footer-nav__item
= link_to 'https://fbc-stack.vercel.app/', class: 'footer-nav__item-link', target: '_blank', rel: 'noopener' do
| FBC Stack

li.footer-nav__item
= link_to '/articles.atom', class: 'a-button is-sm is-secondary is-icon', target: '_blank', rel: 'noopener', title: 'フィヨルドブートキャンプブログフィード' do
i.fa-solid.fa-rss
small.footer__copyright
i.fa-regular.fa-copyright
= link_to 'Lokka Inc.', 'https://lokka.jp', class: 'footer__copyright-link'
Expand Down
17 changes: 17 additions & 0 deletions app/views/articles/index.atom.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
atom_feed do |feed|
feed.title("ブログ | FJORD BOOT CAMP(フィヨルドブートキャンプ)")
feed.updated(@atom_articles.first.created_at)
@atom_articles.each do |article|
feed.entry(article) do |entry|
entry.title(article.title)
summary_html = md2html(article.summary)
entry.summary(summary_html, type: 'html')
body_html = md2html(article.body)
entry.content(body_html, type: 'html')

entry.author do |author|
author.name(article.user.login_name)
end
end
end
end
1 change: 1 addition & 0 deletions app/views/articles/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- title 'ブログ'
- set_meta_tags(site: 'FJORD BOOT CAMP(フィヨルドブートキャンプ)',
description: 'オンラインプログラミングフィヨルドブートキャンプのブログ記事一覧ページです。')
= auto_discovery_link_tag(:atom, 'https://bootcamp.fjord.jp/articles.atom', { title: 'Atom Feed' })
= render '/head/fontawsome'

.welcome-page-header
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ html.is-application lang='ja'
= stylesheet_link_tag 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/yakuhanjp_s-narrow.min.css', media: 'all'
= stylesheet_link_tag 'https://fonts.googleapis.com/css2?family=Roboto:wght@400;700;900&display=swap', media: 'all'
= render '/head/fontawsome'
link(rel='alternate' type='application/atom+xml' title='フィヨルドブートキャンプブログ' href='/articles.atom')
= content_for(:head_last) if content_for?(:head_last)
body.is-application#body(class="#{body_class}")
= render 'google_analytics' if Rails.env.production? && !staging?
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/welcome.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ html.is-application lang='ja'
= stylesheet_link_tag 'https://fonts.googleapis.com/css?family=Source+Code+Pro', media: 'all'
= stylesheet_link_tag 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/yakuhanjp_s-narrow.min.css', media: 'all'
= render '/head/fontawsome'
link(rel='alternate' type='application/atom+xml' title='フィヨルドブートキャンプブログ' href='/articles.atom')
= content_for(:head_last) if content_for?(:head_last)
- if defined?(@article) && @article.wip?
meta name="robots" content="none"
meta(name="robots" content="none")
body.is-welcome#body class="#{body_class}"
= render 'google_analytics' if Rails.env.production? && !staging?
.wrapper
Expand Down
3 changes: 3 additions & 0 deletions app/views/shared/_not_logged_in_footer.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ footer.not-logged-in-footer
li.not-logged-in-footer__nav-item
= link_to new_comeback_path, class: 'not-logged-in-footer__nav-item-link' do
| 休会からの復帰
li.not-logged-in-footer__nav-item
= link_to '/articles.atom', class: 'a-button is-sm is-secondary is-icon', target: '_blank', rel: 'noopener', title: 'フィヨルドブートキャンプブログフィード' do
i.fa-solid.fa-rss
small.not-logged-in-footer-copyright
i.fa-regular.fa-copyright
span.not-logged-in-footer-copyright__author
Expand Down
31 changes: 31 additions & 0 deletions test/system/articles_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,35 @@ class ArticlesTest < ApplicationSystemTestCase
assert_selector "a[href='https://b.hatena.ne.jp/entry/s/bootcamp.fjord.jp/articles/#{@article.id}#bbutton']"
end
end

test 'items of article shown in atom feed' do
visit_with_auth new_article_url, 'komagata'

fill_in 'article[title]', with: 'エントリーのタイトル(text)'
fill_in 'article[summary]', with: 'サマリー(HTML)'
fill_in 'article[body]', with: '本文(HTML)'
within '.select-users' do
find('.choices__inner').click
find('#choices--js-choices-single-select-item-choice-6', text: 'mentormentaro').click
end
click_on '公開する'

visit '/articles.atom'
assert_text 'エントリーのタイトル(text)'
assert_text '&lt;p&gt;サマリー(HTML)&lt;/p&gt;'
assert_text '&lt;p&gt;本文(HTML)&lt;/p&gt;'
assert_text 'mentormentaro'
end

test 'WIP article is not shown in atom feed' do
visit_with_auth new_article_url, 'komagata'

fill_in 'article[title]', with: 'WIPの記事は atom feed に表示されない'
fill_in 'article[body]', with: 'WIPの記事は atom feed に表示されない'
click_on 'WIP'
assert_text '記事をWIPとして保存しました'

visit '/articles.atom'
assert_no_text 'WIPの記事は atom feed に表示されない'
end
end

0 comments on commit 9ca0a8a

Please sign in to comment.