Skip to content

Instantly share code, notes, and snippets.

@nukos
Forked from upvalue/amazon.rb
Last active August 29, 2015 14:06
Show Gist options
  • Save nukos/be2cf4c8e024f841908e to your computer and use it in GitHub Desktop.
Save nukos/be2cf4c8e024f841908e to your computer and use it in GitHub Desktop.
JP Amazon Associate
# 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 link and IMG of the product
module Jekyll
module Filters
def amazon_product_href(asin)
"http://www.amazon.co.jp/gp/product/#{asin}/ref=as_li_ss_il?ie=UTF8&creativeASIN=#{asin}&tag=#{@context.registers[:site].config['amazon_associate_id']}"
end
def amazon_image_href(asin, size)
"http://ws-fe.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=#{asin}&Format=_#{size ? size : 'M'}L110_&ID=AsinImage&MarketPlace=JP&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)
"<a href=\"#{amazon_product_href(asin)}\" target=\"_blank\"><img src=\"#{amazon_image_href(asin, size)}\" /></a>"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment