fix: check options.enable

This commit is contained in:
crimx 2020-10-03 11:34:27 +08:00
parent 7c15687c2b
commit 2e906df384
2 changed files with 22 additions and 23 deletions

View file

@ -38,7 +38,7 @@ githubEmojis:
```
- **inject** `boolean=true` - Inject emoji styles and fallback script.
If `true`, the filter will inject a `<style>` to document `<head>`.
If `true`, the filter will inject a `<style>` to the html.
If `false`, the filter will not inject any style. If you can modify source style files you may turn this off and add them yourself.
Below is the injected `<style>`. The class name changes according to option.

View file

@ -30,30 +30,29 @@ hexo.extend.tag.register("github_emoji", (args) =>
);
hexo.extend.filter.register("after_post_render", (data) => {
if (data["no-emoji"]) {
if (options.inject !== false) {
data.content = `<style>${getEmojiStyles()}</style>` + data.content;
}
} else {
const $content = new JSDOM(data.content);
const $excerpt = new JSDOM(data.excerpt);
replaceColons($content.window.document.body, emojis);
replaceColons($excerpt.window.document.body, emojis);
if (options.inject !== false) {
const style = $content.window.document.createElement("style");
style.innerHTML = getEmojiStyles();
$content.window.document.body.insertBefore(
style,
$content.window.document.body.firstElementChild
);
}
data.content = $content.window.document.body.innerHTML;
data.excerpt = $excerpt.window.document.body.innerHTML;
if (options.inject !== false && (!options.enable || data["no-emoji"])) {
data.content = `<style>${getEmojiStyles()}</style>` + data.content;
return data
}
const $content = new JSDOM(data.content);
const $excerpt = new JSDOM(data.excerpt);
replaceColons($content.window.document.body, emojis);
replaceColons($excerpt.window.document.body, emojis);
if (options.inject !== false) {
const style = $content.window.document.createElement("style");
style.innerHTML = getEmojiStyles();
$content.window.document.body.insertBefore(
style,
$content.window.document.body.firstElementChild
);
}
data.content = $content.window.document.body.innerHTML;
data.excerpt = $excerpt.window.document.body.innerHTML;
return data;
});