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

How to encrypt TOC under NexT theme #58

Closed
yuyuforest opened this issue Oct 17, 2018 · 3 comments
Closed

How to encrypt TOC under NexT theme #58

yuyuforest opened this issue Oct 17, 2018 · 3 comments

Comments

@yuyuforest
Copy link

It is said that TOC can be encrypted in themes/next/layout/_macro/sidebar.swig.
However, after I used another one's code hexo博文加密 , there is some bug in the TOC of encrypted article.
I want the presentation like this Hexo Blog Encrypt . How can I make it?

@yuyuforest
Copy link
Author

yuyuforest commented Oct 18, 2018

10/18/2018
I just found the way to solve the problem. I will write a blog about it and put it here later.

10/19/2018
Now I finish the blog !
Hexo | 在NexT主题下加密文章和目录

@D0n9X1n
Copy link
Owner

D0n9X1n commented Oct 18, 2018

Cool~

@yuhldr
Copy link

yuhldr commented Apr 4, 2022

更新一下 NexT version 8.10.1

这个文件:node_modules/hexo-theme-next/layout/_macro/sidebar.njk

这一行

{%- set toc = toc(page.content, {class: 'nav', list_number: page.toc.number, max_depth: page.toc.max_depth}) %}

修改为

{%- if page.encrypt == true %}
    {%- set toc = toc(page.origin, {class: 'nav', list_number: page.toc.number, max_depth: page.toc.max_depth}) %}
{% else %}
    {%- set toc = toc(page.content, {class: 'nav', list_number: page.toc.number, max_depth: page.toc.max_depth}) %}
{%- endif %}

其实原理就是:

如果加密了,生成目录 toc 变量就不能用 page.content 了,需要改为 page.origin

@D0n9X1n D0n9X1n mentioned this issue Sep 5, 2022
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants