Skip to content

Commit 98d428b

Browse files
authored
Merge pull request #1773 from coderdojo-japan/add-podcast-rss-to-news
✨ DojoCast ポッドキャストを「最近の CoderDojo」セクションに追加
2 parents 0d164ef + ae2cb01 commit 98d428b

File tree

5 files changed

+366
-162
lines changed

5 files changed

+366
-162
lines changed

app/helpers/application_helper.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,27 @@ def translate_dojo_tag(tag_name)
213213
end
214214

215215
def format_news_title(news)
216-
has_emoji = news.title[0]&.match?(/[\p{Emoji}&&[^0-9#*]]/)
217-
has_emoji ? news.title : "📰 #{news.title}"
216+
has_custom_emoji = news.title[0]&.match?(/[\p{Emoji}&&[^0-9#*]]/)
217+
return news.title if has_custom_emoji
218+
219+
# Add preset Emoji to its prefix if news.title does not have Emoji.
220+
emoji = case news.url
221+
when %r{/podcasts/\d+}
222+
'📻'
223+
when %r{prtimes\.jp}
224+
'📢'
225+
else
226+
'📰'
227+
end
228+
"#{emoji} #{news.title}"
229+
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
218238
end
219239
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>

0 commit comments

Comments
 (0)