fix: check options.enable
This commit is contained in:
parent
7c15687c2b
commit
2e906df384
2 changed files with 22 additions and 23 deletions
|
@ -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.
|
||||
|
|
43
index.js
43
index.js
|
@ -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;
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue