Switch Gollum's emojis to match github's

Posted on Monday, April 10, 2017




I have recently installed Gollum and started using it for documenting a few things.  See http://www.whiteboardcoder.com/2017/04/install-and-configure-gollum-on-ubuntu.html [1]

I have gotten use to using github's wiki for documenting devopy things over the last few years at work.   Github's wiki is Gollum, but with some tweaks.   I want to tweak my install of Gollum to match, as best I can, github's look and feel.

With that in mind the next thing on my plate to change is the emojis.






Current Emojis


If I run gollum with the --emoji option it will display emojis


  > gollum --emoji


If you are unfamiliar with what emojis you can use in gollum go check out https://www.webpagefx.com/tools/emoji-cheat-sheet/  [2]





As an example

If I add this to a wiki page


:smile:
:small_airplane:
:small_blue_diamond:
:heart:
:ghost:
:us:
:one:
:two:
:arrow_right_hook:
:white_check_mark:
:x:
:bangbang:
:interrobang:






I get these emoji's displayed correctly in Gollum….. But…  If I do the same thing in github's wiki





You can see that the icon images are not exactly the same.
I am glad that emojis work in Gollum out of the box, but I want the images to match exactly.

How can I accomplish this?







Where are the emojis?


Where are the emojis in Gollum in the first place?

Gollum uses gemoji as its emoji engine https://github.com/github/gemoji [3]

Go to your gems directory.
To find your directory run this command


  > gem environment






In my case it as /var/lib/gems/2.3.0

Go into that directory


  > cd /var/lib/gems/2.3.0


In that directory should be a gems directory in that directory there should be a gemojion-2.6.1


  > cd gems/gemojione-2.6.1/





In that directory the is an assets directory looking in there I see an images directory that seems to contain the emoji images.


  > ls assets/images









I pulled the images into my machine and they are all 64x64 px

Now why the funny names why 2705.png rather than white_check_mark?




 








From github


Looking around I found https://developer.github.com/v3/emojis/ [5] .  They have a nice API you can use to snag the location of all their emojis

First install jq if you do not have it then run this command


  > sudo apt-get install jq
  > curl https://api.github.com/emojis | jq .




Hey look Unicode friendly addresses for icons.





I get a nice 64x64 image

Let me download the emoji json to a file  (but first to be safe let me do this all in a new folder in my home directory)


  > cd
  > mkdir emojis
  > cd emojis
  > curl https://api.github.com/emojis > emojis.json





Create an images directory here.


  > mkdir images


Now write a simple python script to download all the images.


  > vi download_emojis.py


Place the following in it.
WARNING THIS CODE NEEDS TO BE TWEAKED KEEP READING


#!/usr/bin/python3
import json
import os

with open('emojis.json') as data_file:
   data = json.load(data_file)


for emoji in data:
  url = data[emoji]
  filename = url.split('/')[-1].split('?')[0]

  #Use a simple curl command to download the file
  os.system("curl " + url + " > images/" + filename)




Then make it executable and run it.


  > chmod u+x download_emojis.py
  > ./download_emojis.py


Not the most efficient method, but it works and you really only need to do it once.

There is ~ 1500 images so it take a few min.


OK can I safely use these to replace the ones being used by gemoji?


  > cd /var/lib/gems/2.3.0/gems/gemojione-2.6.1/assets/images/
  > mkdir ~/gemoji.BACK
  > sudo mv * ~/gemoji.BACK
  > sudo cp ~/emojis/images/* .




If I reload my page…





Ok… Partial victory…

Looking at the files compared to the originals I think I found the issue.



The new ones are lower case and it should be upper case.


As a quick proof let me rename one.


  > sudo mv 203c.png 203C.png


 


Yep that did it.

Let me go back and tweak the python script to name things correctly.






Here is the new python code


#!/usr/bin/python3
import json
import os

with open('emojis.json') as data_file:
   data = json.load(data_file)


for emoji in data:
  url = data[emoji]
  filename = url.split('/')[-1].split('?')[0].split('.')
  filename = filename[0].upper() + "." + filename[1]

  #Use a simple curl command to download the file
  os.system("curl " + url + " > images/" + filename)



Run the script again


  > ./download_emojis.py


This time I timed it … total time  10min 22 sec





Delete the old files and copy the new ones over



  > cd /var/lib/gems/2.3.0/gems/gemojione-2.6.1/assets/images/
  > sudo rm *
  > sudo cp ~/emojis/images/* .


Now let me try again



Hey that looks nice now J





One last tweak


Github does have a few extra emoji images.



Most of these I do not use but I do want to add them anyway.


If I update my wiki page


:octocat:
:godmode:
:trollface:





I get nothing.



There is a file in config/index.jon in gemoji


  > cd /var/lib/gems/2.3.0/gems/gemojione-2.6.1/
  > sudo vi config/index.json


You need to add additional section to this json file like this.



Here is the portion I added to the bottom of the document.



  "atom": {
    "unicode": "ATOM",
    "unicode_alternates": [],
    "name": "atom",
    "shortname": ":atom:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "atom"
    ],
    "moji": "💤"
  },
  "basecamp": {
    "unicode": "BASECAMP",
    "unicode_alternates": [],
    "name": "basecamp",
    "shortname": ":basecamp:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "basecamp"
    ],
    "moji": "💤"
  },
  "basecampy": {
    "unicode": "BASECAMPY",
    "unicode_alternates": [],
    "name": "basecampy",
    "shortname": ":basecampy:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "basecampy"
    ],
    "moji": "💤"
  },
  "bowtie": {
    "unicode": "BOWTIE",
    "unicode_alternates": [],
    "name": "bowtie",
    "shortname": ":bowtie:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "bowtie"
    ],
    "moji": "💤"
  },
  "electron": {
    "unicode": "ELECTRON",
    "unicode_alternates": [],
    "name": "electron",
    "shortname": ":electron:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "electron"
    ],
    "moji": "💤"
  },
  "feelsgood": {
    "unicode": "FEELSGOOD",
    "unicode_alternates": [],
    "name": "feelsgood",
    "shortname": ":feelsgood:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "feelsgood"
    ],
    "moji": "💤"
  },
  "finnadie": {
    "unicode": "FINNADIE",
    "unicode_alternates": [],
    "name": "finnadie",
    "shortname": ":bowtie:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "finnadie"
    ],
    "moji": "💤"
  },
  "goberserk": {
    "unicode": "GOBERSERK",
    "unicode_alternates": [],
    "name": "goberserk",
    "shortname": ":goberserk:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "goberserk"
    ],
    "moji": "💤"
  },
  "godmode": {
    "unicode": "GODMODE",
    "unicode_alternates": [],
    "name": "godmode",
    "shortname": ":godmode:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "godmode"
    ],
    "moji": "💤"
  },
  "hurtrealbad": {
    "unicode": "HURTREALBAD",
    "unicode_alternates": [],
    "name": "hurtrealbad",
    "shortname": ":hurtrealbad:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "hurtrealbad"
    ],
    "moji": "💤"
  },
  "neckbeard": {
    "unicode": "NECKBEARD",
    "unicode_alternates": [],
    "name": "neckbeard",
    "shortname": ":neckbeard:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "neckbeard"
    ],
    "moji": "💤"
  },
  "octocat": {
    "unicode": "OCTOCAT",
    "unicode_alternates": [],
    "name": "octocat",
    "shortname": ":octocat:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "octocat"
    ],
    "moji": "💤"
  },
  "rage1": {
    "unicode": "RAGE1",
    "unicode_alternates": [],
    "name": "rage1",
    "shortname": ":rage1:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "rage1"
    ],
    "moji": "💤"
  },
  "rage2": {
    "unicode": "RAGE2",
    "unicode_alternates": [],
    "name": "rage2",
    "shortname": ":rage2:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "rage2"
    ],
    "moji": "💤"
  },
  "rage3": {
    "unicode": "RAGE3",
    "unicode_alternates": [],
    "name": "rage3",
    "shortname": ":rage3:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "rage3"
    ],
    "moji": "💤"
  },
  "rage4": {
    "unicode": "RAGE4",
    "unicode_alternates": [],
    "name": "rage4",
    "shortname": ":rage4:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "rage4"
    ],
    "moji": "💤"
  },
  "shipit": {
    "unicode": "SHIPIT",
    "unicode_alternates": [],
    "name": "shipit",
    "shortname": ":shipit:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "shipit"
    ],
    "moji": "💤"
  },
  "suspect": {
    "unicode": "SUSPECT",
    "unicode_alternates": [],
    "name": "suspect",
    "shortname": ":suspect:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "suspect"
    ],
    "moji": "💤"
  },
  "trollface": {
    "unicode": "TROLLFACE",
    "unicode_alternates": [],
    "name": "trollface",
    "shortname": ":bowtie:",
    "category": "emoticons",
    "aliases": [],
    "aliases_ascii": [],
    "keywords": [
      "trollface"
    ],
    "moji": "💤"
  }




Save the file then restart Gollum!




Hey Look I have them all now, even an octocat.



References


[1]        Install and Configure Gollum on Ubuntu 16.04
[2]        Emoji Cheat Sheet
[3]        gemoji github page
[4]        Enoji Unicode







No comments:

Post a Comment