Skip to content

Commit ae2cb01

Browse files
committed
✨ ポッドキャストURLを相対パスで表示(ローカル開発対応)
- news_link_url ヘルパーメソッドを追加 - https://coderdojo.jp/podcasts/* を /podcasts/* に変換 - ローカル開発環境でも内部ページが表示可能に - ホームページのニュース表示部分でヘルパーを使用 - format_news_title の絵文字判定を簡素化(Spotify URL削除) - テストケースも追加
1 parent 4331e80 commit ae2cb01

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

app/helpers/application_helper.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def format_news_title(news)
218218

219219
# Add preset Emoji to its prefix if news.title does not have Emoji.
220220
emoji = case news.url
221-
when %r{coderdojo\.jp/podcasts}, %r{spotify\.com/pod/show/coderdojo-japan}
221+
when %r{/podcasts/\d+}
222222
'📻'
223223
when %r{prtimes\.jp}
224224
'📢'
@@ -227,4 +227,13 @@ def format_news_title(news)
227227
end
228228
"#{emoji} #{news.title}"
229229
end
230+
231+
def news_link_url(news)
232+
# Convert absolute podcast URLs to relative paths for local development
233+
if news.url.match?(%r{^https://coderdojo\.jp/podcasts/\d+$})
234+
news.url.sub('https://coderdojo.jp', '')
235+
else
236+
news.url
237+
end
238+
end
230239
end

app/views/home/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
<ul class="list" style="list-style: none;">
195195
<% @news_items.each do |news| %>
196196
<li>
197-
<%= link_to format_news_title(news), news.url, target: '_blank' %>
197+
<%= link_to format_news_title(news), news_link_url(news), target: '_blank' %>
198198
</li>
199199
<% end %>
200200
</ul>

spec/helpers/application_helper_spec.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99

1010
context '先頭文字が絵文字でない場合' do
1111
it 'ポッドキャストのURLには📻を付与する' do
12-
news = double('news', title: 'DojoCast Episode 33', url: 'https://podcasters.spotify.com/pod/show/coderdojo-japan/episodes/033')
13-
expect(helper.format_news_title(news)).to eq '📻 DojoCast Episode 33'
14-
15-
news2 = double('news', title: 'エピソード33', url: 'https://coderdojo.jp/podcasts/33')
16-
expect(helper.format_news_title(news2)).to eq '📻 エピソード33'
12+
news = double('news', title: 'エピソード33', url: 'https://coderdojo.jp/podcasts/33')
13+
expect(helper.format_news_title(news)).to eq '📻 エピソード33'
1714
end
1815

1916
it 'PR TIMESのURLには📢を付与する' do
@@ -27,4 +24,19 @@
2724
end
2825
end
2926
end
27+
28+
describe '#news_link_url' do
29+
it 'ポッドキャストの絶対URLを相対パスに変換する' do
30+
news = double('news', url: 'https://coderdojo.jp/podcasts/33')
31+
expect(helper.news_link_url(news)).to eq '/podcasts/33'
32+
end
33+
34+
it 'その他のURLはそのまま返す' do
35+
news = double('news', url: 'https://news.coderdojo.jp/2025/12/06/dojoletter')
36+
expect(helper.news_link_url(news)).to eq 'https://news.coderdojo.jp/2025/12/06/dojoletter'
37+
38+
news2 = double('news', url: 'https://prtimes.jp/main/html/rd/p/000000001.000038935.html')
39+
expect(helper.news_link_url(news2)).to eq 'https://prtimes.jp/main/html/rd/p/000000001.000038935.html'
40+
end
41+
end
3042
end

0 commit comments

Comments
 (0)