Closed DNACore closed 1 year ago
I have this issue too... Seems this only works for posts that are in the /_post/
folder. If you place the post in any subdirectory, it will fail.
Obviously, need to see why this is failing at: https://github.com/hexojs/hexo/blob/740a0d6a94a8f3a096a5315ec3e8c45328994e93/lib/plugins/tag/post_link.js#L27-L30
It seems that if you want to link to articles in _post/subfolder
, you need to write like this {% post_link subfolder-test %}
Yes, you need to specify the full path, for example
{% post_link '2017/10/Hello World' %}
Posts with the same name may exist under different folders. If only the filename is provided without the full directory, then hexo cannot deduce which post to link to.
Posts with the same name may exist under different folders. If only the filename is provided without the full directory, then hexo cannot deduce which post to link to.
The Hexo db has the slug defined for every post. It should be a unique identifier in the front-matter. Requiring the full path makes this function completely pointless. Far easier to use the [Link text](url)
markdown.
Furthermore, it adds overhead to the blog management when you move posts across folders. If you only need to provide the slug (without path) - as defined in documentation - then it’s trivial to reorganize your posts.
As for post names being duplicated in different folders, you can specify a slightly different slug in the front matter. This function doesn’t need to deduce which folder’s post to display, just use the first matching slug.
You can't define the slug in front-matter. It will always be overwritten here: https://github.com/hexojs/hexo/blob/860f1bfb77ef8306b7d3a39a4ff8481544a15360/lib/plugins/processor/post.js#L99
(Maybe you can try modifying the relevant code)
This function calls url_for
and is therefore able to handle cases where the blog root directory is changed.
Furthermore, slug contains the directory name by default: https://github.com/hexojs/hexo/issues/4837
相对地址、相对链接、内部链接、站内链接 {% post_link 'VsCode/使用vsCode配置Go开发环境' '使用vsCode配置Go开发环境' %}
I have two articles.
_post/a/poo.md:
---
permalink: post/poo.html
---
_post/b/foo.md
---
permalink: post/foo.html
---
How can I link poo.md in foo.md ?
I have both tried {% post_link a/poo %}
{% post_link post/poo %}
@stevenjoezhang @lorezyra
{% post_link a/poo %}
is working. Note that you will get an empty link if you don't set the title in front-matter.
@stevenjoezhang
sorry for the late reply, I've tried that, but it wasnt ok.
here is my sample hexo project. It can reproduce this problem.
@DNACore First, you need to update to Hexo 7.0.0-rc1:
npm i hexo@7.0.0-rc1
Second, your post path is not a/poo
, but a/poo_2023-05-31_19-12-35
.
So, using {% post_link a/poo %}
won't work. You can use title instead:
{% post_link poo %}
@stevenjoezhang
After updating to hexo@7.0.0-rc1 and using title instead it worked.
While usding post path
isn't work even I use the correct path.
Thank you!
Check List
Please check followings before submitting a new issue.
hexo version
to check)Expected behavior
{% post_link somemarkdownfile %}
should generate a corrent link to the exsit markdown file.Actual behavior
it genrated a
post not found xxx
link.How to reproduce?
just write the post_link such as
{% post_link somemarkdownfile %}
what's more:
I created a new hexo folder, and created a new post named
test.md
, and wrote{% post_link test %}
in hello-world.md. runhexo g
, it can genrate the correnct link. and I move test.md to subfolder/test.md, then runhexo clean && hexo g
. it can't genrate the correct link, just said:post not found
. I moved thetest.md
just below the _post folder, then it can genrate the correct link again. BUT for my original hexo folder, wherever i put thesomemarkdownfile.md
, it always saidpost not found
.Is the problem still there under "Safe mode"?
YES
Environment & Settings
Node.js & npm version(
node -v && npm -v
)Your site
_config.yml
(Optional)Hexo and Plugin version(
npm ls --depth 0
)Your package.json
package.json
Others
I replace the post_link.js in the node_moduls/hexo/lib bla bla with the current post_link.js on the master.
it throws the error below, hope it helps