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

写的 <%- is_home() %> 在首页(index) 返回 false ??? #3738

Closed
zhwangart opened this issue Sep 29, 2019 · 12 comments
Closed

写的 <%- is_home() %> 在首页(index) 返回 false ??? #3738

zhwangart opened this issue Sep 29, 2019 · 12 comments
Labels
question Needs help in usage

Comments

@zhwangart
Copy link

<%- is_home() %>http://localhost:4000/ 返回 true ,然后生成($ hexo g)文件中的 index.html 中,则显示 false ???
$ hexo g 之前已经多次执行 $ hexo clean

@zhwangart
Copy link
Author

我找到问题原因了,是因为 <%- partial('_partial/header', null, {cache: !config.relative_link}) %>中的null, {cache: !config.relative_link}导致,如果删除 null就好了,请问这个 null 具体起什么作用???我是从默认主题中复制过来的!

@stevenjoezhang
Copy link
Member

stevenjoezhang commented Sep 30, 2019

其实这并不是null的问题,正确的做法是删除{cache: !config.relative_link}。你可以看下文档,partialcache选项是用于缓存的,遇到is_home这种在每个页面上不同的方法就出问题了。

@stevenjoezhang
Copy link
Member

Duplicate of #3483

@zhwangart
Copy link
Author

Duplicate of #3483

请问下为什么 is_home 会遇上 cache 就出问题呢?

@stevenjoezhang
Copy link
Member

可以这样理解:执行hexo g,Hexo开始渲染第一个页面(可能并不是index),此页面中is_home()false。然后,Hexo开始渲染第二个、第三个页面。由于开启了cache,Hexo不会重新执行is_home()方法,而是直接套用第一个页面的结果(即返回false,并没有重新渲染)。这就导致了问题。
hexo s的机制又与hexo g不同,因此更加令人感到困惑。

@zhwangart
Copy link
Author

zhwangart commented Sep 30, 2019

@stevenjoezhang 非常感谢!
让我这么笨的人都理解了这么难的关系...
那照理说,这算是 hexo 的一个 bug 吗?

@stevenjoezhang
Copy link
Member

这个选项确实还不够智能(可能就是这么设计的?)毕竟如果能够根据页面类型进行缓存,就可以避免你说的这个问题。

@SukkaW
Copy link
Member

SukkaW commented Oct 9, 2019

@ppoffice has implement a smart _partial() helper with fragment cache automatically enabled: https://github.com/ppoffice/hexo-theme-icarus/blob/master/includes/helpers/override.js#L158-L187

The side-effect is huge memory usage since all partials will be cached in memory.

@zhwangart @stevenjoezhang

@stale
Copy link

stale bot commented Dec 18, 2019

This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 18, 2019
@ppoffice
Copy link
Contributor

ppoffice commented Dec 20, 2019

@ppoffice has implement a smart _partial() helper with fragment cache automatically enabled: https://github.com/ppoffice/hexo-theme-icarus/blob/master/includes/helpers/override.js#L158-L187

The side-effect is huge memory usage since all partials will be cached in memory.

@zhwangart @stevenjoezhang

@SukkaW
Actually, the memory size of the cache object is negligible, event with the _partial() helper I wrote. I took a snapshot of the heap when rendering https://github.com/jiangtj-lab/hexo-many-posts with hexo-theme-icarus:

Annotation 2019-12-20 170806

The cache object in lib/plugins/helper/fragment_cache.js#L4 only takes up 3.0MB with 1418 HTML fragments. I also found out that most of the memory is consumed by the unreleased CacheStream in /lib/plugins/console/generate.js#L48. Thus, my suggestions to reduce the memory size of Hexo are

@stale stale bot removed the stale label Dec 20, 2019
@stale
Copy link

stale bot commented Feb 18, 2020

This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stevenjoezhang
Copy link
Member

I'm closing this issue. Please join the discussion in #2451

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Needs help in usage
Projects
None yet
Development

No branches or pull requests

4 participants