fix(plugin/heti): make autoSpacing work (#77)
We modified heti.autoSpacing() to remove DOMContentLoaded (DOM has been loaded in deferred block.)
This commit is contained in:
parent
6b385f3224
commit
8ab2eb9f94
|
@ -62,15 +62,6 @@ function og_args() {
|
|||
<meta name="theme-color" content="#f8f8f8">
|
||||
<title><%- generate_title() %></title>
|
||||
|
||||
<% if (theme.heti) { %>
|
||||
<link rel="stylesheet" href="//unpkg.com/heti/umd/heti.min.css">
|
||||
<script src="//unpkg.com/heti/umd/heti-addon.min.js"></script>
|
||||
<script defer>
|
||||
const heti = new Heti('.heti');
|
||||
heti.autoSpacing(); // 自动进行中西文混排美化和标点挤压
|
||||
</script>
|
||||
<% } %>
|
||||
|
||||
<% if (theme.open_graph && theme.open_graph.enable) { %>
|
||||
<%- open_graph(og_args()) %>
|
||||
<% } %>
|
||||
|
|
|
@ -301,8 +301,22 @@ if (stellar.plugins.fancybox) {
|
|||
if (stellar.plugins.heti) {
|
||||
stellar.loadCSS(stellar.plugins.heti.css);
|
||||
stellar.loadScript(stellar.plugins.heti.js, { defer: true }).then(function () {
|
||||
const heti = new Heti('.heti p');
|
||||
heti.autoSpacing();
|
||||
const heti = new Heti('.heti');
|
||||
|
||||
// Copied from heti.autoSpacing() without DOMContentLoaded.
|
||||
// https://github.com/sivan/heti/blob/eadee6a3b748b3b7924a9e7d5b395d4bce479c9a/js/heti-addon.js
|
||||
//
|
||||
// We managed to minimize the code modification to ensure .autoSpacing()
|
||||
// is synced with upstream; therefore, we use `.bind()` to emulate the
|
||||
// behavior of .autoSpacing() so we can even modify almost no code.
|
||||
void (function () {
|
||||
const $$rootList = document.querySelectorAll(this.rootSelector)
|
||||
|
||||
for (let $$root of $$rootList) {
|
||||
this.spacingElement($$root)
|
||||
}
|
||||
}).bind(heti)();
|
||||
|
||||
stellar.plugins.heti.enable = false;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue