hexo-filter-github-emojis/README.md

115 lines
3.4 KiB
Markdown
Raw Normal View History

2016-12-22 19:11:28 +08:00
# hexo-filter-github-emojis
[![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.
## 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
2016-12-23 01:02:51 +08:00
unicode: false
2017-06-26 15:52:34 +08:00
styles:
2016-12-23 18:46:01 +08:00
localEmojis:
2016-12-22 19:11:28 +08:00
```
The filter will try to download the latest version of [Github Emojis][ghemojis] list. If the network is unavailable or too slow it will use the backup version.
2017-06-26 15:52:34 +08:00
- **className** - Image class name. For :sparkles: `:sparkles:` the filter will generate something like this:
2016-12-22 19:11:28 +08:00
```html
<img class="github-emoji" title=":sparkles:" alt=":sparkles:" src="https://assets-cdn.github.com/images/icons/emoji/unicode/2728.png" height="20" width="20">
```
2016-12-23 01:02:51 +08:00
- **unicode** - If you set this option to true, the filter will generate something like this:
```html
<span class="github-emoji" title=":sparkles:" data-src="https://assets-cdn.github.com/images/icons/emoji/unicode/2728.png">&#x2728;</span>
```
Then you can fallback to image with JavaScript. For example, with jQuery:
```javascript
$('span.github-emoji').each(function (i, emoji) {
var $emoji = $(emoji)
var codepoint = $emoji.html()
$('<img height="20" width="20">')
.on('error', function () {
// image loading failed
$emoji.html(codepoint)
})
2016-12-23 18:46:01 +08:00
.prop('alt', $emoji.attr('title'))
.prop('src', $emoji.data('src'))
2016-12-23 01:02:51 +08:00
.appendTo($emoji.empty())
})
```
2017-09-30 12:28:59 +08:00
- **styles** - inline styles for the images. For example:
2017-06-26 15:52:34 +08:00
```yaml
githubEmojis:
styles:
display: inline
vertical-align: bottom
```
outputs:
```html
<img class="github-emoji" style="display:inline;vertical-align:bottom" ...>
```
2016-12-23 18:46:01 +08:00
- **localEmojis** - You can specify your own list. An object or JSON string is valid. The filter will first check the `localEmojis` then fallback to the [Github Emojis][ghemojis] list.
For example:
2016-12-23 18:50:32 +08:00
```yaml
2016-12-23 18:46:01 +08:00
githubEmojis:
localEmojis:
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:
localEmojis:
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 %}
```
## 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