Skip to content

Instantly share code, notes, and snippets.

@upvalue upvalue/amazon.rb
Last active Dec 23, 2016

What would you like to do?
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)
def amazon_image_href(asin, size)
"{asin}&Format=_#{size ? size : 'M'}L110_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=#{@context.registers[:site].config['amazon_associate_id']}"
def amazon_product(asin, text)
asin ? "<a href=\"#{amazon_product_href(asin)}\">#{text}</a>" : text
def amazon_image(asin, size)
"<img src=\"#{amazon_image_href(asin, size)}\" />"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.