Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 hexo-blog-encrypt 加密文章时,如果之前输入过密码,文章会失去样式。 #895

Closed
2 of 3 tasks
llingy opened this issue Jan 8, 2023 · 2 comments
Closed
2 of 3 tasks
Labels
🐛 bug Unexpected problem or unintended behavior

Comments

@llingy
Copy link

llingy commented Jan 8, 2023

请确认

  • 是当前最新的 Release 版本
  • 本地 hexo clean && hexo s,并且清除浏览器缓存,仍可复现
  • 已经排除是其他 Hexo 插件影响

Bug 描述

文章丢失样式。

复现步骤

使用 hexo-blog-encrypt 加密文章时,如果之前输入过密码,文章会失去样式。
原因是这段:

  if (document.getElementById('hbePass')) {
    Fluid.utils.waitElementLoaded('hbe-prefix', function() {
      var hbePrefix = document.querySelector('hbe-prefix');
      hbePrefix.parentElement.classList.add('markdown-body');
      Fluid.utils.retry(function() {
        if (Fluid.boot && Fluid.boot.refresh) {
          Fluid.boot.refresh();
          return true;
        }
      }, 100, 10);
    })
  }

hexo-blog-encrypt 会保存密码,如果之前有正确的密码则会自动解密,这段脚本有属性 defer,会在页面加载完后才执行,所以如果之前输入过密码则会导致 id 为 hbePass 的密码输入框已经被删除,则不会重新进行所需的操作。并且由于解密操作是异步的,很可能没法在正常执行这些操作之前解密完成。最终导致如果输过密码则丢失样式。

if (document.getElementById('hbePass') || document.querySelector('hbe-prefix')) {
    Fluid.utils.waitElementLoaded('hbe-prefix', function() {
        var hbePrefix = document.querySelector('hbe-prefix');
        hbePrefix.parentElement.classList.add('markdown-body');
        hbePrefix.parentElement.removeChild(hbePrefix);
        Fluid.utils.retry(function() {
            if (Fluid.boot && Fluid.boot.refresh) {
                Fluid.boot.refresh();
                return true;
            }
        }, 100, 10);
    })
}

如果改成这样能正确加载样式。

截图

image
这是二级标题,但并没有相应的样式。

@llingy llingy added the 🐛 bug Unexpected problem or unintended behavior label Jan 8, 2023
@llingy
Copy link
Author

llingy commented Jan 8, 2023

经查找,应修改 /layout/_partials/plugins/encrypt.ejs 中的代码。

@zkqiang
Copy link
Member

zkqiang commented Jul 2, 2023

Fixed in v1.9.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants