Skip to content

Commit 7c981bb

Browse files
committed
Enable to automatically convert 'time' in Shownote into links to corresponding YouTube with the time in Podcasts
1 parent 120c101 commit 7c981bb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app/controllers/podcasts_controller.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ def show
2424
return redirect_to podcasts_path
2525
end
2626

27+
@youtube = @episode.content.match(/watch\?v=((\w)*)/)[1]
28+
@url = request.url
2729
@title = @episode.title.split('-').last.strip
2830
@date = @episode.published_date.strftime("%Y年%-m月%-d日(#{Podcast::WDAY2JAPANESE[@episode.published_date.wday]})")
2931
@content = Kramdown::Document.new(
3032
self.convert_shownote(@episode.content),
3133
input: 'GFM').to_html
32-
@url = request.url
3334
end
3435

3536
private
@@ -43,6 +44,13 @@ def convert_shownote(content)
4344
</h2>
4445
HTML
4546

46-
content.gsub(/(#+) Shownote/i, shownote)
47+
content.gsub!(/(#+) Shownote/) { shownote }
48+
content.gsub!(/-\s((\d:)?\d{1,}:\d{2})/) do
49+
t = $1
50+
t = (t.size == '0:00'.size) ? '0' + t : t
51+
t = (t.size == '00:00'.size) ? '00:' + t : t
52+
t = Time.parse(t).seconds_since_midnight.to_i
53+
"- [#{$1}](https://youtu.be/#{@youtube}?t=#{t}) &nbsp; "
54+
end
4755
end
4856
end

app/views/podcasts/show.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
}
2121
}
2222
.episode-cover img { margin-bottom: 20px;}
23+
.episode ul {
24+
padding-left: 0px;
25+
list-style: none;
26+
}
2327
</style>
2428

2529
<%= render 'podcasts/navigation' %>

0 commit comments

Comments
 (0)