Last active
August 29, 2015 14:11
-
-
Save yukichi/5e55320c57731464f07f to your computer and use it in GitHub Desktop.
Wikipedia link for Jykell
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
=begin | |
Put this file _plugins directory in Jekyll(create if it doesn't exist) | |
You need to set the below configuration in _config.yml | |
wikipedia:en (or de, ja, zh) | |
You can use this tag in markdown file like: | |
{% wikiepdia term %} | |
or | |
{% wikipedia term,lang %} (if you want to specify another language wikipedia than configuration) | |
Expample (in the case you specify wikipedia:en in _config.yml): | |
{% wikipedia test %} | |
-> <a href="http://en.wikipedia.org/wiki/test">test</a> | |
{% wikipedia test,fr %} | |
-> <a href="http://fr.wikipedia.org/wiki/test">test</a> | |
=end | |
module Jekyll | |
class WikipediaTag < Liquid::Tag | |
def initialize(tag_name, term, tokens) | |
super | |
@term = term | |
end | |
def render(context) | |
ar = @term.strip.split(",") | |
if ar[1] | |
term = ar[0] | |
lang = ar[1] | |
else | |
site = context.registers[:site] | |
lang = site.config["wikipedia"] | |
term = @term | |
end | |
"<a href=\"http://#{lang}.wikipedia.org/wiki/#{term}\">#{term}</a>" | |
end | |
end | |
end | |
Liquid::Template.register_tag("wikipedia", Jekyll::WikipediaTag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment