Skip to content

Commit

Permalink
fix: videos were auto played wrongly (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreytse committed Apr 15, 2021
1 parent 8ca9f65 commit a5e345b
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/jekyll-spaceship/processors/media-processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def handle_normal_audio(element)
handle_media(element, {
media_type: 'audio',
host: '(https?:\\/\\/)?.*\\/',
id: '(.+?\\.(mp3|wav|ogg|mid|midi|aac|wma))',
id: '(.+?\\.(mp3|wav|ogg|mid|midi|aac|wma))'
})
end

Expand All @@ -53,7 +53,7 @@ def handle_normal_audio(element)
# ![video](//techslides.com/demos/sample-videos/small.mp4?width=400)
def handle_normal_video(element)
handle_media(element, {
media_type: 'iframe',
media_type: 'video',
host: '(https?:\\/\\/)?.*\\/',
id: '(.+?\\.(avi|mp4|webm|ogg|ogv|flv|mkv|mov|wmv|3gp|rmvb|asf))'
})
Expand Down Expand Up @@ -158,6 +158,10 @@ def handle_media(element, data)
cfg['loop'] = qs['loop'] || data[:loop] || cfg['loop']
cfg['style'] += ';display: none;' if qs['hidden']
handle_audio(element, { cfg: cfg })
when 'video'
cfg['autoplay'] = qs['autoplay'] || data[:autoplay] || cfg['autoplay']
cfg['loop'] = qs['loop'] || data[:loop] || cfg['loop']
handle_video(element, { cfg: cfg })
when 'iframe'
cfg['title'] = title
cfg['width'] = qs['width'] || data[:width] || cfg['width']
Expand Down Expand Up @@ -188,6 +192,25 @@ def handle_audio(element, data)
element.replace(doc.at('body').children.first)
end

def handle_video(element, data)
cfg = data[:cfg]
html = "<video"\
" id=\"#{cfg['id']}\""\
" class=\"#{cfg['class']}\""\
" style=\"#{cfg['style']}\""\
" #{cfg['autoplay'] ? 'autoplay' : ''}"\
" #{cfg['loop'] ? 'loop' : ''}"\
" controls>" \
" <source src=\"#{cfg['src']}\">" \
" Your browser doesn't support HTML5 video."\
" Here is a <a href=\"#{cfg['src']}\">link to download the video</a>"\
" instead."\
"</video>"
doc = Nokogiri::HTML(html)
return if element.parent.nil?
element.replace(doc.at('body').children.first)
end

def handle_iframe(element, data)
cfg = data[:cfg]
html = "<iframe"\
Expand Down

0 comments on commit a5e345b

Please sign in to comment.