Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hexo-filter-emoji

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hexo-filter-emoji - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

update.js

119

index.js

@@ -1,90 +0,42 @@

'use strict'
/* global hexo */
const _ = require('lodash')
const path = require('path')
const fs = require('fs')
const cheerio = require('cheerio')
'use strict'
var options = _.assign({
enable: true,
inject: true,
version: 'latest',
className: 'github-emoji',
}, hexo.config.githubEmojis)
const _ = require('lodash');
const path = require('path');
const fs = require('fs');
var options = Object.assign({
enable : true,
className: 'emoji',
}, hexo.config.emoji);
if (options.enable !== false) {
const emojis = _.assign(
{},
const emojis = Object.assign(
require('./emojis.json'),
loadCustomEmojis(options.customEmojis || options.localEmojis),
)
);
fs.writeFile(
path.join(__dirname, 'emojis.json'),
JSON.stringify(emojis, null, ' '),
JSON.stringify(emojis),
function (err) { err && console.warn(err) },
)
);
hexo.extend.filter.register('after_post_render', data => {
if (!options.inject && data['no-emoji']) { return data }
hexo.extend.filter.register('before_post_render', data => {
if (data['no-emoji']) return data;
const $ = cheerio.load(data.content, {decodeEntities: false})
const excerpt = cheerio.load(data.excerpt, {decodeEntities: false})
data.content = data.content.replace(
/:(\w+):/ig,
(match, p1) => emojis[p1] ? renderEmoji(emojis, p1) : match,
);
if (options.inject) {
$('body').append(`<script>
document.querySelectorAll('.${options.className}')
.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>`)
}
return data;
});
if (!data['no-emoji']) {
replaceColons($('body')[0], $, emojis)
replaceColons(excerpt('body')[0], excerpt, emojis)
}
data.content = $('body').html()
data.excerpt = excerpt('body').html()
return data
})
hexo.extend.helper.register('github_emoji', name => renderEmoji(emojis, name))
hexo.extend.tag.register('github_emoji', args => renderEmoji(emojis, args[0]))
hexo.extend.helper.register('emoji', name => renderEmoji(emojis, name))
hexo.extend.tag.register('emoji', args => renderEmoji(emojis, args[0]))
}
function replaceColons (node, $, emojis) {
node.children.forEach(child => {
if (child.type === 'text') {
const content = child.data.replace(
/:(\w+):/ig,
(match, p1) => emojis[p1] ? renderEmoji(emojis, p1) : match,
)
if (content !== child.data) {
$(child).replaceWith($.parseHTML(content))
}
} else if (child.type === 'tag') {
if (child.name !== 'pre' && child.name !== 'code') {
replaceColons(child, $, emojis)
}
}
})
}
function loadCustomEmojis (customEmojis) {
function loadCustomEmojis(customEmojis) {
// JSON string

@@ -103,3 +55,3 @@ if (_.isString(customEmojis)) {

customEmojis = {}
console.warn('hexo-filter-github-emojis: Custom emojis not valid. Skipped.')
console.warn('hexo-filter-emoji: Custom emojis not valid. Skipped.')
}

@@ -119,4 +71,4 @@ }

function renderEmoji (emojis, name) {
if (!emojis[name]) { return name }
function renderEmoji(emojis, name) {
if (!emojis[name]) return name;

@@ -126,19 +78,12 @@ const styles = _.isObject(options.styles)

.filter(k => _.isString(options.styles[k]))
.map(k => k + ':' + options.styles[k])
: []
.map(k => k + ': ' + options.styles[k])
: [];
if (options.inject) {
styles.push(
'color: transparent',
`background:no-repeat url(${emojis[name].src}) center/contain`,
)
} else {
styles.push(`background-image:url(${emojis[name].src})`)
}
styles.push(`background-image: url(${emojis[name].src})`);
const codepoints = emojis[name].codepoints
? emojis[name].codepoints.map(c => `&#x${c};`).join('')
: ' '
: ' ';
return `<span class="${options.className}" style="${styles.join(';')}" data-src="${emojis[name].src}">${codepoints}</span>`
return `<span class="${options.className}" style="${styles.join('; ')}" data-src="${emojis[name].src}">${codepoints}</span>`;
}
{
"name": "hexo-filter-emoji",
"version": "2.0.2",
"description": "A Hexo plugin that adds emojis support, using Github Emojis API",
"main": "index",
"version": "2.1.0",
"description": "A Hexo plugin that adds emojis support, using Github Emojis API.",
"main": "index.js",
"repository": "https://github.com/theme-next/hexo-filter-emoji",
"engines": {
"node": ">=8.0.0"
"node": ">=8.6.0"
},

@@ -15,17 +15,12 @@ "keywords": [

"github emojis",
"github",
"emoji",
"emojis"
],
"author": "Mimi <zsq@zsq.im> (https://zhangshuqiao.org)",
"maintainers": [
"CRIMX <straybugs@gmail.com> (http://blog.crimx.com)"
],
"author": "Mimi <stevenjoezhang@gmail.com> (https://zhangshuqiao.org)",
"license": "MIT",
"dependencies": {
"cheerio": "^1.0.0-rc.2",
"lodash": "^4.17.15",
"lodash": "4.17.15",
"random-ua": "0.0.6",
"request": "^2.88.0"
"request": "2.88.0"
}
}
# hexo-filter-emoji
[![Npm Version](https://img.shields.io/npm/v/hexo-filter-emoji.svg)](https://npmjs.org/package/hexo-filter-emoji)
[![Npm Downloads Month](https://img.shields.io/npm/dm/hexo-filter-emoji.svg)](https://npmjs.org/package/hexo-filter-emoji)
[![Npm Downloads Total](https://img.shields.io/npm/dt/hexo-filter-emoji.svg)](https://npmjs.org/package/hexo-filter-emoji)
[![License](https://img.shields.io/npm/l/hexo-filter-emoji.svg)](https://npmjs.org/package/hexo-filter-emoji)
[![Npm Version](https://img.shields.io/npm/v/hexo-filter-emoji?style=flat-square)](https://npmjs.org/package/hexo-filter-emoji)
[![Npm Downloads Month](https://img.shields.io/npm/dm/hexo-filter-emoji?style=flat-square)](https://npmjs.org/package/hexo-filter-emoji)
[![Npm Downloads Total](https://img.shields.io/npm/dt/hexo-filter-emoji?style=flat-square)](https://npmjs.org/package/hexo-filter-emoji)
[![License](https://img.shields.io/npm/l/hexo-filter-emoji?style=flat-square)](https://npmjs.org/package/hexo-filter-emoji)

@@ -15,3 +15,3 @@ A Hexo plugin that adds emoji support, using [Github Emojis API](https://api.github.com/emojis).

``` bash
$ npm install hexo-filter-emoji --save
$ npm install hexo-filter-emoji
```

@@ -24,6 +24,5 @@

``` yaml
githubEmojis:
emoji:
enable: true
className: github-emoji
inject: true
styles:

@@ -36,39 +35,9 @@ customEmojis:

```html
<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">&#x2728;</span>
<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">&#x2728;</span>
```
- **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.
```html
<span class="github-emoji" style="color:transparent;background:no-repeat url(...) center/contain" ...>
```
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>
```
- **styles** - inline styles. For example:
```yaml
githubEmojis:
emoji:
styles:

@@ -82,3 +51,3 @@ font-size: 2em

```html
<span class="github-emoji" style="font-size:2em;font-weight:bold;background-image:url(...)" ...>
<span class="github-emoji" style="font-size: 2em; font-weight: bold; background-image: url(...)" ...>
```

@@ -91,3 +60,3 @@

```yaml
githubEmojis:
emoji:
customEmojis:

@@ -101,3 +70,3 @@ arrow_left: https://path/to/arrow_left.png

```yaml
githubEmojis:
emoji:
customEmojis:

@@ -115,3 +84,3 @@ man_juggling:

```html
{% github_emoji sparkles %}
{% emoji sparkles %}
```

@@ -129,3 +98,3 @@

{% github_emoji tada %} still works.
{% emoji tada %} still works.
```

@@ -135,10 +104,6 @@

You can also render a GitHub emoji from a template using the `github_emoji` helper:
You can also render a GitHub emoji from a template using the `emoji` helper:
```html
<h1><% github_emoji('octocat') %></h1>
<h1>{% emoji('octocat') %}</h1>
```
## Credits
[hexo-filter-github-emojis](https://github.com/crimx/hexo-filter-github-emojis), Author: [crimx](https://github.com/crimx).

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc