D0n9X1n / hexo-blog-encrypt

Yet, just another hexo plugin for security.
https://www.npmjs.com/package/hexo-blog-encrypt
MIT License
971 stars 101 forks source link

Shoka主题下toc解密后无法自动展开 #182

Closed c01dkit closed 2 years ago

c01dkit commented 2 years ago

Issue

Shoka主题下toc解密后无法自动展开

Expected Behavior

正常情况下随页面滚动,侧边栏toc可以自动展开定位,如图: d20211214143524

Actual Behavior

修改前,加密解密无法显示toc,修改sidebar.njk后可以显示出toc,但是无法根据浏览位置定位 a20211214144211

Steps to Reproduce the Problem

  1. 修改sidebar.njk(添加的部分用注释说明了)

    
    {% macro render(display_toc) %}
    <div class="inner">
    {%- if display_toc %}
    {%- if page.encrypt %} <!--add this line-->
    {%- set toc = toc(page.origin) %} <!--add this line-->
    {%- else %} <!--add this line-->
    {%- set toc = toc(page.content) %}
    {%- endif %} <!--add this line-->
    {%- set display_toc = toc.length > 1 and display_toc %}
    {%- set related = _category_posts(page) %}
    {%- endif %}
    
    <div class="panels">
    <div class="inner">
      <div class="contents panel pjax" data-title="{{ __('sidebar.toc') }}">
        {%- if display_toc %}
        <div id="toc-div"> <!--add this line-->
          {{ toc }}
        </div> <!--add this line-->
        {%- endif %}
      </div>
      <div class="related panel pjax" data-title="{{ __('sidebar.related') }}">
        {%- if related %}
        <ul>
          {{ related }}
        </ul>
        {%- endif %}
      </div>
      <div class="overview panel" data-title="{{ __('sidebar.overview') }}">
        {{ partial('_partials/sidebar/overview.njk', {}, {cache: true}) }}
      </div>
    </div>
    </div>
    
    <ul id="quick">
    <li class="prev pjax">
      {%- if page and page.prev %}
        {%- set prevlink = page.prev_link %}
        {%- if is_page() or is_post() %}
          {%- set prevlink = page.next.path %}
        {%- endif %}
        {%- if prevlink %}
        {{ _url(prevlink, '<i class="ic i-chevron-left"></i>', {rel: 'prev', title: __('post.prev')}) }}
        {%- endif %}
      {%- endif %}
    </li>
    <li class="up"><i class="ic i-arrow-up"></i></li>
    <li class="down"><i class="ic i-arrow-down"></i></li>
    <li class="next pjax">
      {%- if page and page.next %}
        {%- set nextlink = page.next_link %}
        {%- if is_page() or is_post() %}
          {%- set nextlink = page.prev.path %}
        {%- endif %}
        {%- if nextlink %}
        {{ _url(nextlink, '<i class="ic i-chevron-right"></i>', {rel: 'next', title: __('post.next')}) }}
        {%- endif %}
      {%- endif %}
    </li>
    <li class="percent"></li>
    </ul>
    </div>
    {% endmacro %}

2. 正常配置加密选项

## Specifications
encrypt版本3.1.6

最理想的是能不能不对toc加密?尽管不希望公开内容,但是想公开目录
D0n9X1n commented 2 years ago

试试看解密之后执行, 在 console 里面执行 sidebarTOC().

如果可以得话,就在 callback 那加上这句。

如果不行的话,在调试下,找到绑定博客内容元素和侧边栏 toc 得函数,加入 callback