2016-12-22 19:11:28 +08:00
# hexo-filter-github-emojis
2017-06-26 07:25:18 +08:00
[![Npm Version ](https://img.shields.io/npm/v/hexo-filter-github-emojis.svg )](https://npmjs.org/package/hexo-filter-github-emojis)
2016-12-22 19:11:28 +08:00
[![Npm Downloads Month ](https://img.shields.io/npm/dm/hexo-filter-github-emojis.svg )](https://npmjs.org/package/hexo-filter-github-emojis)
[![Npm Downloads Total ](https://img.shields.io/npm/dt/hexo-filter-github-emojis.svg )](https://npmjs.org/package/hexo-filter-github-emojis)
[![License ](https://img.shields.io/npm/l/hexo-filter-github-emojis.svg )](https://npmjs.org/package/hexo-filter-github-emojis)
A Hexo plugin that adds emoji support, using [Github Emojis API][ghemojis].
Check out the [Emoji Cheat Sheet ](http://www.webpagefx.com/tools/emoji-cheat-sheet/ ) for all the emojis it supports.
2018-10-04 19:07:24 +08:00
V2 is not compatible with [V1 ](https://github.com/crimx/hexo-filter-github-emojis/tree/e52ceb8b18a7b06916b6cb0a887b218d49a7ab92 ). V1 replaces codepoints with `<img>` tags. While V2 makes the font transparent and displays emojis with `background-image` .
2016-12-22 19:11:28 +08:00
## Installation
``` bash
$ npm install hexo-filter-github-emojis --save
```
## Options
You can configure this plugin in `_config.yml` . Default options:
``` yaml
githubEmojis:
enable: true
className: github-emoji
2018-10-04 19:07:24 +08:00
inject: true
2017-06-26 15:52:34 +08:00
styles:
2018-10-04 19:07:24 +08:00
customEmojis:
2016-12-22 19:11:28 +08:00
```
2018-10-04 19:07:24 +08:00
- **className** - Image class name. For example :sparkles: `:sparkles:` the filter will generate something like this:
2016-12-22 19:11:28 +08:00
```html
2018-10-04 19:07:24 +08:00
< span class = "github-emoji" style = "background-image:url(https://assets-cdn.github.com/images/icons/emoji/unicode/2728.png?v8)" data-src = "https://assets-cdn.github.com/images/icons/emoji/unicode/2728.png?v8" > ✨ < / span >
2016-12-22 19:11:28 +08:00
```
2018-10-04 19:07:24 +08:00
- **inject** - If true, the filter will inject proper inline styles and a script to fallback when image loading fails. If you can modify script files and style files, you may turn this off and add them yourself.
2016-12-23 01:02:51 +08:00
```html
2018-10-04 19:07:24 +08:00
< span class = "github-emoji" style = "color:transparent;background:no-repeat url(...) center/contain" . . . >
2016-12-23 01:02:51 +08:00
```
2018-10-04 19:07:24 +08:00
A script tag will be appended, the className changes according to the options:
```html
< script >
document.querySelectorAll('.github-emojis')
.forEach(el => {
if (!el.dataset.src) { return; }
const img = document.createElement('img');
img.style = 'display:none !important;';
img.src = el.dataset.src;
img.addEventListener('error', () => {
img.remove();
el.style.color = 'inherit';
el.style.backgroundImage = 'none';
el.style.background = 'none';
});
img.addEventListener('load', () => {
img.remove();
});
document.body.appendChild(img);
});
< / script >
2016-12-23 01:02:51 +08:00
```
2018-10-04 19:07:24 +08:00
- **styles** - inline styles. For example:
2017-06-26 15:52:34 +08:00
```yaml
githubEmojis:
styles:
2018-10-04 19:07:24 +08:00
font-size: 2em
font-weight: bold
2017-06-26 15:52:34 +08:00
```
outputs:
```html
2018-10-04 19:07:24 +08:00
< span class = "github-emoji" style = "font-size:2em;font-weight:bold;background-image:url(...)" . . . >
2017-06-26 15:52:34 +08:00
```
2018-10-04 19:07:24 +08:00
- **customEmojis** - You can specify your own list. An object or JSON string is valid. The filter will first check the `customEmojis` then fallback to the [Github Emojis][ghemojis] list.
2016-12-23 18:46:01 +08:00
For example:
2017-06-26 07:25:18 +08:00
2016-12-23 18:50:32 +08:00
```yaml
2016-12-23 18:46:01 +08:00
githubEmojis:
2018-10-04 19:07:24 +08:00
customEmojis:
2016-12-23 18:46:01 +08:00
arrow_left: https://path/to/arrow_left.png
arrow_right: https://path/to/arrow_right.png
```
If you need to add code points that are not in the Github list, you can do this:
2016-12-23 18:50:32 +08:00
```yaml
2016-12-23 18:46:01 +08:00
githubEmojis:
2018-10-04 19:07:24 +08:00
customEmojis:
2016-12-23 18:46:01 +08:00
man_juggling:
2016-12-23 18:50:32 +08:00
src: https://path/to/man_juggling.png
2016-12-23 18:46:01 +08:00
codepoints: ["1f939", "2642"]
arrow_right: https://path/to/arrow_right.png
```
2017-06-26 15:52:34 +08:00
## Tag
If you do not like the `::` -style keywords, you can always use tags:
```html
{% github_emoji sparkles %}
```
2018-01-05 14:30:59 +08:00
Add `no-emoji: true` to front-matter to stop replacing `::` :
```md
---
title: Hello World
no-emoji: true
---
:tada: as it is.
{% github_emoji tada %} still works.
```
2017-06-26 07:25:18 +08:00
## Helper
You can also render a GitHub emoji from a template using the `github_emoji` helper:
```html
< h1 > < % github_emoji('octocat') %>< / h1 >
```
2016-12-22 19:11:28 +08:00
[ghemojis]: https://api.github.com/emojis