Skip to content

Instantly share code, notes, and snippets.

@HKLF4
Created August 27, 2012 09:54
Show Gist options
  • Save HKLF4/3487038 to your computer and use it in GitHub Desktop.
Save HKLF4/3487038 to your computer and use it in GitHub Desktop.
Octopress HTML5 Audio Tag
# Title:
# Octopress HTML5 Audio Tag
# http://antoncherkasov.me/projects/octopress-plugins
# Author:
# Anton Cherkasov
# http://antoncherkasov.me
# [email protected]
# Syntax:
# {% audio url/to/mp3 %}
# {% audio url/to/mp3 url/to/ogg %}
# Example:
# {% audio http://example.org/music.mp3 http://example.org/music.ogg %}
# Output:
# <audio controls><source src="http://example.org/music.mp3"><source src="http://example.org/music.org"></audio>
module Jekyll
class AudioTag < Liquid::Tag
@audio = nil
def initialize(tag_name, markup, tokens)
@files = markup
super
end
def render(context)
output = super
audio = "<audio controls>"
@files.each_line(' ') do |file|
audio += "<source src='#{file[0...-1]}'>"
end
audio += "</audio>"
end
end
end
Liquid::Template.register_tag('audio', Jekyll::AudioTag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment