├── README.md └── emoji.rb /README.md: -------------------------------------------------------------------------------- 1 | # Jekyll Emoji 2 | A jekyll plug-in that provides a Liquid filter for emojifying text with [Gemoji](https://github.com/github/gemoji). See [Emoji Cheat Sheet](http://www.emoji-cheat-sheet.com) for a full listing of emoji codes. 3 | 4 | ## Installation 5 | - Run `gem install gemoji` or add `gem 'gemoji'` to your gemfile and run `bundle install` 6 | - Copy this file to your `_plugins` directory 7 | - Add a line like `emoji_dir: ./images/emoji` to your `_config.yml` 8 | 9 | ## Usage: 10 | - Apply the filter wherever needed e.g. `{{ content | emojify }}` 11 | - Add some emoji to your article! e.g. `Hello :wink:` 12 | -------------------------------------------------------------------------------- /emoji.rb: -------------------------------------------------------------------------------- 1 | # Jekyll Emoji 2 | # 3 | # Chris Kempson (http://chriskempson.com) 4 | # https://github.com/chriskempson/jekyll-emoji 5 | # 6 | # A jekyll plug-in that provides a Liquid filter for emojifying text with 7 | # https://github.com/github/gemoji. See http://www.emoji-cheat-sheet.com for 8 | # a full listing of emoji codes. 9 | # 10 | # Installation: 11 | # - Run `gem install gemoji` or add `gem 'gemoji'` to your gemfile and run `bundle install` 12 | # - Copy this file to your `_plugins` directory 13 | # - Add a line like `emoji_dir: images/emoji` to your `_config.yml` 14 | # - If you want to use external source for emoji, set `emoji_dir: http://...` to your `_config.yml`. 15 | # 16 | # Usage: 17 | # - Apply the filter wherever needed e.g. {{ content | emojify }} 18 | # - Add some emoji to your article! e.g. "Hello :wink:" 19 | 20 | require 'gemoji' 21 | 22 | module Jekyll 23 | 24 | module EmojiFilter 25 | 26 | def emojify(content) 27 | return false if !content 28 | 29 | config = @context.registers[:site].config 30 | if config['emoji_dir'] 31 | emoji_dir = config['emoji_dir'] 32 | end 33 | 34 | content.to_str.gsub(/:([a-z0-9\+\-_]+):/) do |match| 35 | if Emoji.find_by_alias($1) and emoji_dir 36 | '' + $1 + '' 37 | else 38 | match 39 | end 40 | end 41 | end 42 | 43 | end 44 | 45 | class EmojiGenerator < Generator 46 | def generate(site) 47 | config = site.config 48 | return false if not config['emoji_dir'] 49 | return false if config['emoji_dir'].start_with?('http') 50 | emoji_dir = File.join(config['source'], config['emoji_dir']) 51 | return false if File.exist?(File.join(emoji_dir, 'smiley.png')) 52 | 53 | puts " Copying: Emoji from Gemoji to " + config['emoji_dir'] 54 | 55 | # Make Emoji directory 56 | FileUtils.mkdir_p(emoji_dir) 57 | 58 | # Copy Gemoji files 59 | unicode_emoji_dir = File.join(Emoji.images_path, 'emoji') 60 | Emoji.all.each do |em| 61 | # Use the name rather than the unicode character 62 | FileUtils.cp File.join(unicode_emoji_dir, em.image_filename), File.join(emoji_dir, em.name + '.png') 63 | end 64 | end 65 | end 66 | 67 | end 68 | 69 | Liquid::Template.register_filter(Jekyll::EmojiFilter) 70 | --------------------------------------------------------------------------------