Last active
December 11, 2015 05:48
-
-
Save jalcine/4554192 to your computer and use it in GitHub Desktop.
An Octopress / Jekyll plugin to provide a tag that automatically generates a bit.ly short-link for the current page in reference.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
## @author Jacky Alcine <[email protected]> | |
## @see [TODO: Add URL to post about bit.ly URLs.] | |
## | |
## Add in Bit.ly URL support to pages. | |
require "bitly" | |
# Ensure use of new API. | |
Bitly.use_api_version_3 | |
module Jekyll | |
module Bitly | |
module Methods | |
private | |
def _config (option) | |
Jekyll.configuration({})["bitly_#{option}"] | |
end | |
public | |
def api_obj | |
login = _config("login") | |
api_key = _config("api_key") | |
::Bitly.new login, api_key | |
end | |
end | |
class ShortenTag < Liquid::Tag | |
include Jekyll::Bitly::Methods | |
def initialize (tag_name, text, tokens) | |
@bitly = api_obj | |
@link = text | |
super | |
end | |
def render (context) | |
@bitly.shorten(@link).short_url | |
end | |
end | |
end | |
end | |
Liquid::Template.register_tag('bitly_shorten', Jekyll::Bitly::ShortenTag) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bitly_api_key: FOOO | |
bitly_login: BARRR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="{% bitly_shorten page.url %}">short link</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment