Skip to content

Instantly share code, notes, and snippets.

@tabletick
Created September 6, 2012 10:08
Show Gist options
  • Save tabletick/3654288 to your computer and use it in GitHub Desktop.
Save tabletick/3654288 to your computer and use it in GitHub Desktop.
Audio/MP3 Plugin for Octopress
# Title: MP3 tag for Jekyll
# Authors: Devin Weaver, Daniel Roos (youtube changes)
# Description: Allows mp3 tag to include mp3 files embedded into the post.
# It uses the player 'audio.js' from http://kolber.github.com/audiojs/
#
# Install the plugin according to the manuel of the author by adding the necessary lines to the head-template
# and adding the files into the right directories.
#
# Please read my [blog post about it][2].
#
# [2]: http://blog.micronarrativ.org/2012/09/06/Wordpress_til_Octopress_-_Audio
#
# Syntax {% audio fileurl %}
#
# Examples:
# {% audio http://www.example.com/audio.mp3 %}
#
# Output:
# <p/>
# <center>
# <audio src="http://www.example.com/audio.mp3" preload="none" />
# </center>
# <p/>
require 'digest/md5'
module Jekyll
class AudioTag < Liquid::Tag
def initialize(tag_name, markup, tokens)
if /(?<fileurl>\S+)?/i =~ markup
@audiotagurl = fileurl
end
super
end
def render(context)
if @audiotagurl
"<p/>
<center>
<audio src=\"#{@audiotagurl}\" preload=\"none\" />
</center>
<p/>"
else
"Error processing input, expected syntax: {% audio fileurl %}"
end
end
end
end
Liquid::Template.register_tag('audio', Jekyll::AudioTag)
@jimsynz
Copy link

jimsynz commented Oct 7, 2013

Thanks for this!

Copy link

ghost commented Mar 15, 2017

I no longer can find the link to your instructions on your website. do you have an updated address for the post?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment