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

Having a path in config.new_post_name breaks tag plugin post_link #5361

Closed kristofzerbe closed 7 months ago

kristofzerbe commented 7 months ago

Check List

Expected behavior

My post folder structure relies on subfolders per year, like _posts/2023/my-fancy-post.md, with asset folders of the same name, and I use the Tag Plugin post_link in many posts.

Since hexo new post XXX always creates the new post in the root post folder, I recently changed the config entry new_post_name from :title.md to :year/:title to create the new posts directly in the correct folder.

I expected that the new post is created in the appropriate subfolder (works) and Hexo generates my files (works not)

Actual behavior

After the change my build, which executes hexo clean && hexo generate, aborts with the following message:

Template render error: (unknown path)
  Error: Post not found: post_link 2023/My-fancy-post.
    at Object._prettifyError (C:\Projects\kiko.io\node_modules\nunjucks\src\lib.js:36:11)
    at C:\Projects\kiko.io\node_modules\nunjucks\src\environment.js:563:19
    at Template.root [as rootRenderFunc] (eval at _compile (C:\Projects\kiko.io\node_modules\nunjucks\src\environment.js:633:18), <anonymous>:92:3)
    at Template.render (C:\Projects\kiko.io\node_modules\nunjucks\src\environment.js:552:10)
    at Environment.renderString (C:\Projects\kiko.io\node_modules\nunjucks\src\environment.js:380:17)
    at C:\Projects\kiko.io\node_modules\hexo\dist\extend\tag.js:206:22
    at tryCatcher (C:\Projects\kiko.io\node_modules\hexo\node_modules\bluebird\js\release\util.js:16:23)
    at Function.Promise.fromNode.Promise.fromCallback (C:\Projects\kiko.io\node_modules\hexo\node_modules\bluebird\js\release\promise.js:209:30)
    at Tag.render (C:\Projects\kiko.io\node_modules\hexo\dist\extend\tag.js:205:35)
    at Object.onRenderEnd (C:\Projects\kiko.io\node_modules\hexo\dist\hexo\post.js:399:32)
    at C:\Projects\kiko.io\node_modules\hexo\dist\hexo\render.js:77:29
    at tryCatcher (C:\Projects\kiko.io\node_modules\hexo\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\Projects\kiko.io\node_modules\hexo\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (C:\Projects\kiko.io\node_modules\hexo\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromise0 (C:\Projects\kiko.io\node_modules\hexo\node_modules\bluebird\js\release\promise.js:649:10)
    at Promise._settlePromises (C:\Projects\kiko.io\node_modules\hexo\node_modules\bluebird\js\release\promise.js:729:18)
    at _drainQueueStep (C:\Projects\kiko.io\node_modules\hexo\node_modules\bluebird\js\release\async.js:93:12)
    at _drainQueue (C:\Projects\kiko.io\node_modules\hexo\node_modules\bluebird\js\release\async.js:86:9)
    at Async._drainQueues (C:\Projects\kiko.io\node_modules\hexo\node_modules\bluebird\js\release\async.js:102:5)
    at Immediate.Async.drainQueues (C:\Projects\kiko.io\node_modules\hexo\node_modules\bluebird\js\release\async.js:15:14)
    at processImmediate (internal/timers.js:464:21)

The error occurs comprehensible in Hexo 6.3.0 as well as in 7.0.0. :title = generation works, :year/:title generation stops with error.

How to reproduce?

  1. Clone https://github.com/kristofzerbe/kiko.io
  2. Edit /_config.yml with new_post_name: :year/:title.md
  3. Run hexo generate

Is the problem still there under Safe mode?

Yes

Your Node.js & npm version

Node: v14.17.2
NPM: 6.14.13

Your Hexo and Plugin version

+-- hexo@7.0.0
+-- hexo-asset-link@2.2.2
+-- hexo-browsersync@0.3.0
+-- hexo-cli@4.3.1
+-- hexo-front-matter@4.2.1
+-- hexo-fs@4.1.1
+-- hexo-generator-alias@1.0.0
+-- hexo-generator-anything@1.0.12
+-- hexo-generator-archive@2.0.0
+-- hexo-generator-category@2.0.0
+-- hexo-generator-copy@0.1.0
+-- hexo-generator-index@3.0.0
+-- hexo-generator-json-content@4.2.3
+-- hexo-generator-sitemap@3.0.1
+-- hexo-generator-tag@2.0.0
+-- hexo-hide-posts@0.4.0
+-- hexo-renderer-ejs@2.0.0
+-- hexo-renderer-marked@6.1.1
+-- hexo-renderer-stylus@3.0.0
+-- hexo-server@3.0.0
+-- hexo-tag-video@0.0.2

Your package.json

see https://github.com/kristofzerbe/kiko.io/blob/master/package.json

Your site's _config.yml (Optional)

see https://github.com/kristofzerbe/kiko.io/blob/master/_config.yml

Others

I was hoping issues like https://github.com/hexojs/hexo/issues/5042 would help me, but that wasn't the case

kristofzerbe commented 7 months ago

same with https://github.com/hexojs/hexo/issues/4778

kristofzerbe commented 7 months ago

One more thing, I didn't mentioned: The post_link's in my MD's are looking always like this:

{% post_link 2023/My-fancy-post %}

... as Steven pointed out in https://github.com/hexojs/hexo/issues/5042#issuecomment-1322432714

D-Sketon commented 7 months ago

It seems that if you change the config entry new_post_name from :title.md to :year/:title.md, you need to remove the subfolder prefix in post_link like {% post_link My-fancy-post %}

kristofzerbe commented 7 months ago

Oh yes, you're right. Works, even if I couldn't directly establish a connection between the config entry and the tag in my head and in the code.