hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
38.83k stars 4.75k forks source link

hexo.locals.get('posts') doesn't show all posts #5287

Open D-Sketon opened 10 months ago

D-Sketon commented 10 months ago

Check List

Please check followings before submitting a new issue.

Expected behavior

Actual behavior

5286 #5194 #5230

How to reproduce?

register new tag function

hexo.extend.tag.register("series",() => {
  console.log(hexo.locals.get('posts').length)
},{ends: false});

create three posts like this:

---
title: test1
date: 2023-09-03 16:59:42
tags: tag1
---
{% series %}
---
title: test2
date: 2023-09-03 16:59:46
tags: tag1
---
---
title: test3
date: 2023-09-03 16:59:49
tags: tag1
---

hexo g and the output result is 2

However, if all tags in the post are removed, the result is 3

Is the problem still there under "Safe mode"?

Environment & Settings

Node.js & npm version(node -v && npm -v)

v18.12.1
8.19.2

Your site _config.yml (Optional)

Hexo and Plugin version(npm ls --depth 0)

Your package.json package.json

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "build": "hexo generate",
    "clean": "hexo clean",
    "deploy": "hexo deploy",
    "server": "hexo server"
  },
  "hexo": {
    "version": "6.3.0"
  },
  "dependencies": {
    "hexo": "^6.3.0",
    "hexo-generator-archive": "^2.0.0",
    "hexo-generator-category": "^2.0.0",
    "hexo-generator-index": "^3.0.0",
    "hexo-generator-tag": "^2.0.0",
    "hexo-renderer-ejs": "^2.0.0",
    "hexo-renderer-marked": "^6.0.0",
    "hexo-renderer-stylus": "^3.0.0",
    "hexo-server": "^3.0.0",
    "hexo-theme-landscape": "^1.0.0"
  }
}

Others

uiolee commented 10 months ago

~i make a test and it works well~

hexojs#5194(comment)

I also had this problem and it was weird

D-Sketon commented 4 months ago

I try to remove cache here and it works. https://github.com/hexojs/hexo/blob/bc53720dd9fa7e11cc3b34c67fe95692aa085e28/lib/hexo/locals.ts#L15-L20 But I don't think that's where the problem lies.