Skip to content

Instantly share code, notes, and snippets.

@cermakcz

cermakcz/_config.yml

Created Apr 10, 2016
Embed
What would you like to do?
Simple Jekyll plugin for creating a CDN url Liquid tag
#cdn
cdnurl: 'https://s3-eu-west-1.amazonaws.com/outoftime/'
module Jekyll
class CdnUrlTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@path = text
end
def render(context)
resolvedPath = ''
# Check if @path is actually a name of a variable or just a textual path.
if !context[@path].nil?
resolvedPath = context[@path]
else
resolvedPath = @path
end
# Strip the leading slash if there's any.
if resolvedPath.start_with?('/')
resolvedPath = resolvedPath[1..-1]
end
"#{context.registers[:site].config['cdnurl']}#{resolvedPath}"
end
end
end
Liquid::Template.register_tag('cdn_url', Jekyll::CdnUrlTag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment