Jake.codes

Affiliate Ads, a Jekyll Plugin

Friday, March 14, 2014

Insert a random affiliate referral like ads on your static Jekyll blog. Edit the @affiliate array to your liking, you probably don’t want to use my referral codes on your site. Or maybe you do.

module Jekyll
  class AffiliateAd < Liquid::Tag

    def initialize(tag_name, text, tokens)
      super

      @affiliate = [
          # Example Usage:
          # You can support this site by  <a href="http://payjake.com">using Pay Jake.com</a>.
          ["signing up for Lyft","http://www.lyft.com/invited/jake91"],
          ["purchasing a Karma Wi-Fi Hotspot","https://yourkarma.com/invite/tedzdt"],
          ["signing up for Uber","http://www.uber.com/invite/88wlx"],
          ["purchasing a gift card on iTunes","https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/buyLandingPage?at=1l3v3KV"],
          ["tweeting a Starbucks Coffee to me","https://twitter.com/intent/tweet?text=@tweetacoffee%20to%20@jakebilbrey"],
          ["signing up for Instacart","http://inst.cr/t/heYKvt"],
          ["buying something on Amazon","http://www.amazon.com/?_encoding=UTF8&camp=1789&creative=390957&linkCode=ur2&tag=jakebilbrcom-20"],
          ["signing up for Evernote","https://www.evernote.com/referral/Registration.action?uid=131467&sig=aff978965dacc8ae1f0963292eb65043"],
          ["signing up for Hulu Plus","http://hulu.com/r/MMieSg"],
          ["buying a domain at Namecheap","http://www.namecheap.com/?aff=58901"],
          ["signing up for Fastmail","http://www.fastmail.fm/?STKI=7829801"],
          ["pre-ordering Coin, simplify your wallet","https://onlycoin.com/?referral=y1tdaqPz"]
      ].shuffle[0]

      @text = text
    end

    def render(context)
      "#{@text} <a href=\"#{@affiliate[1]}\">#{@affiliate[0]}</a>."
    end
  end
end

Liquid::Template.register_tag('affiliate', Jekyll::AffiliateAd)