Skip to content

Instantly share code, notes, and snippets.

@upvalue
Last active December 23, 2016 06:01
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save upvalue/5589077 to your computer and use it in GitHub Desktop.
Save upvalue/5589077 to your computer and use it in GitHub Desktop.
Amazon affiliate filters for jekyll.
# amazon.rb - amazon affiliate links for jekyll
# assumes that you have a configuration variable called 'amazon_associate_id' with your associate id
# usage: {{ asin | amazon_product_href }}
# returns url of a product
# usage: {{ asin | amazon_image_href: 'M' }}
# returns image of the product, size argument can be S, M, or L, default M
# usage: {{ asin | amazon_product: 'A Product' }}
# returns an html link to a product
# usage: {{ asin | amazon_image: 'M' }}
# returns an html IMG of the product
module Jekyll
module Filters
def amazon_product_href(asin)
"http://amazon.com/exec/obidos/ASIN/#{asin}/#{@context.registers[:site].config['amazon_associate_id']}"
end
def amazon_image_href(asin, size)
"http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&ASIN=#{asin}&Format=_#{size ? size : 'M'}L110_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=#{@context.registers[:site].config['amazon_associate_id']}"
end
def amazon_product(asin, text)
asin ? "<a href=\"#{amazon_product_href(asin)}\">#{text}</a>" : text
end
def amazon_image(asin, size)
"<img src=\"#{amazon_image_href(asin, size)}\" />"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment