Skip to content

Commit e00d06a

Browse files
committed
ポッドキャスト一覧ページを YouTube embed + ボタンに刷新
- Spotify プレイヤーを YouTube embed に置換 - YouTube / Podcast ボタンを追加 - #DojoCast ツイートボタンを削除 - 📻 これまでの収録 セクションに margin-top を追加 - Podcast#youtube_id メソッドを追加(REGEX_YOUTUBE_ID を改善) - YOUTUBE_PLAYLIST_ID 定数を追加
1 parent 4a28d43 commit e00d06a

4 files changed

Lines changed: 25 additions & 14 deletions

File tree

app/controllers/podcasts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def show
2727
@url = request.url
2828
@title = @episode.title.split('-').last.strip
2929
@date = @episode.published_date.strftime("%Y年%-m月%-d日(#{Podcast::WDAY2JAPANESE[@episode.published_date.wday]})")
30-
@youtube_id = @episode.content.match(Podcast::REGEX_YOUTUBE_ID)[1]
30+
@youtube_id = @episode.youtube_id
3131
@content = Kramdown::Document.new(
3232
self.convert_shownote(@episode.content),
3333
input: 'GFM').to_html

app/models/podcast.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Podcast < ApplicationRecord
55
YOUTUBE_PLAYLIST_ID = 'PL94GDfaSQTmJxxnapafkApHYgQUJ6ABUU'
66
# Match timestamps at the beginning of lines (YouTube format)
77
REGEX_TIMESTAMP = /^((\d{1,2}:)?\d{1,2}:\d{2})/
8-
REGEX_YOUTUBE_ID = /watch\?v=((\w)*)/
8+
REGEX_YOUTUBE_ID = /watch\?v=([\w-]+)/
99

1010
validates :title, presence: true
1111
validates :content_size, presence: true
@@ -34,4 +34,8 @@ def cover
3434
def content
3535
exist? ? File.read(path) : ''
3636
end
37+
38+
def youtube_id
39+
content.match(REGEX_YOUTUBE_ID)[1]
40+
end
3741
end

app/views/podcasts/index.html.erb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
<h3 id="live" style="text-align: center; padding-top: 70px;">🎙
2020
最新エピソードを聴く</h3>
2121

22-
<div class="container" style="line-height: 1.9em; margin-bottom: -100px;">
22+
<div class="container" style="line-height: 1.9em; margin-bottom: 100px;">
2323
<section class="doc" style="padding: 30px 0px 0px 0px;">
24-
<% if @episodes.first %>
25-
<iframe class="lazyload" src="https://creators.spotify.com/pod/profile/coderdojo-japan/embed/episodes/<%= @episodes.first.permalink %>" width="100%px" scrolling="no" frameborder="yes"></iframe>
26-
<% end %>
27-
<br>
24+
<%= render 'podcasts/youtube_embed', youtube_id: @episodes.first.youtube_id %>
25+
<div class='btn-cover'>
26+
<a class='btn-blue' href='https://www.youtube.com/watch?v=<%= @episodes.first.youtube_id %>&list=<%= Podcast::YOUTUBE_PLAYLIST_ID %>' target='_blank'>
27+
<i class='fa fa-youtube'></i> YouTube で聴く
28+
</a>
29+
<a class='btn-blue' href='<%= @episodes.first.permalink_url %>' target='_blank'>
30+
<i class='fas fa-podcast'></i> Podcast で聴く
31+
</a>
32+
</div>
2833
</section>
2934
</div>
3035

31-
<p style="text-align: center; padding-top: 120px; padding-bottom: 30px;">
32-
<a href="https://twitter.com/intent/tweet?button_hashtag=DojoCast&hashtags=CoderDojo"
33-
class="twitter-hashtag-button" data-size="large" data-lang="ja"
34-
data-text="" data-show-count="false">#DojoCast でツイートする</a>
35-
</p>
3636

37-
<h3 id="episodes" style="text-align: center; padding-top: 70px;padding-bottom: 10px;">📻 これまでの収録</h3>
37+
<h3 id="episodes" style="text-align: center; padding-top: 70px; padding-bottom: 10px; margin-top: 50px;">📻 これまでの収録</h3>
3838
<ul style="font-size: 120%">
3939
<% @episodes.each do |episode| %>
4040
<li><%= link_to episode.title, podcast_path(episode) %></li>
@@ -43,7 +43,7 @@
4343
</section>
4444

4545
<br>
46-
46+
4747
<section class="introduction text-center list" style="margin-bottom: 30px;">
4848
<%= render 'shared/social_buttons' %>
4949
</section>

spec/features/podcasts_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
RSpec.feature 'Podcasts', type: :feature do
44
describe 'GET documents' do
55
scenario 'Podcast index should be exist' do
6+
@podcast = create(:podcast)
7+
allow(@podcast).to receive(:exist?) { true }
8+
allow(@podcast).to receive(:content) { "title\nhttps://www.youtube.com/watch?v=test123\n" }
9+
allow(Podcast).to receive(:order).and_return([@podcast].reverse)
10+
611
visit '/podcasts'
712
expect(page).to have_http_status(:success)
813
end
@@ -13,6 +18,7 @@
1318
allow(@podcast).to receive(:exist?).with(offset: -1) { false }
1419
allow(@podcast).to receive(:content) { "title\n収録日: 2019/05/10\nhttps://www.youtube.com/watch?v=test123\n..." }
1520
allow(Podcast).to receive(:find_by).with(id: @podcast.id.to_s) { @podcast }
21+
allow(Podcast).to receive(:order).and_return([@podcast].reverse)
1622

1723
visit "/podcasts/#{@podcast.id}"
1824
expect(page).to have_http_status(:success)
@@ -28,6 +34,7 @@
2834
allow(@podcast).to receive(:exist?) { true }
2935
allow(@podcast).to receive(:content) { "title\n収録日: 2019/05/10\nhttps://www.youtube.com/watch?v=test123\n..." }
3036
allow(Podcast).to receive(:find_by).with(id: @podcast.id.to_s) { @podcast }
37+
allow(Podcast).to receive(:order).and_return([@podcast].reverse)
3138

3239
visit "/podcasts/#{@podcast.id}"
3340
target = 'DojoCast'

0 commit comments

Comments
 (0)