lib/nexmo_developer/app/models/blog/blogpost.rb in station-0.1.7 vs lib/nexmo_developer/app/models/blog/blogpost.rb in station-0.1.8
- old
+ new
@@ -34,14 +34,21 @@
path = "#{Rails.configuration.blog_path}/blogposts/#{locale}/#{path}.md"
default_not_found_page(path) unless File.exist?(path)
- document = File.read(path).gsub('/content/blog/') do |match| # gsub Netlify img urls
+ # gsub Netlify - img urls to S3 Bucket
+ document = File.read(path).gsub('/content/blog/') do |match|
"#{Blog::Blogpost::CLOUDFRONT_BLOG_URL}blogposts/#{match.gsub('/content/blog/', '')}"
end
+ # gsub Netlify - embedded YOUTUBE Video
+ document = document.gsub(%r{<youtube id="(\w+)"></youtube>}) do |match|
+ youtube_id = match[/(?<=").*(?=")/]
+ "<center class='video'><br><iframe width='448' height='252' src='https://www.youtube-nocookie.com/embed/#{youtube_id}' frameborder='0' allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe><br><br></center>"
+ end
+
blogpost = new(BlogpostParser.build_show_with_locale(path, locale))
blogpost.content = Nexmo::Markdown::Renderer.new({}).call(document)
blogpost
end
@@ -55,10 +62,9 @@
@thumbnail = @thumbnail.gsub('/content/blog/') do |match| # gsub Netlify img urls
"#{Blog::Blogpost::CLOUDFRONT_BLOG_URL}blogposts/#{match.gsub('/content/blog/', '')}"
end
url = Addressable::URI.parse(@thumbnail)
-
Net::HTTP.start(url.host, url.port, use_ssl: true) do |http|
if http.head(url.request_uri)['Content-Type'].start_with? 'image'
@thumbnail
else
DEFAULT_VONAGE_LOGO_URL