Hexo: url_for(page.path) gives wrong path for prev&next page

Created on 25 Dec 2018  ·  4Comments  ·  Source: hexojs/hexo

When I used ejs to get the url of prev&next page, I found the path given was wrong. I think it's because I set my blog in a subdirectory. (In fact it's www.example.com/blog/)
For example, my prev post lies in www.example.com/blog/post1.html. When Hexo renders post 2, url_for(page.prev.path) gives www.example.com/blog//blog/post1.html, which lead the link to 404.
Though it does work, do I have to use page.prev.path directly?

feature-request

Most helpful comment

The url_for return from root path. How about relative_url ?

If you want to get absolute path, how about config.root + page.prev.path ? It will be return www.example.com/blog/post1.html

All 4 comments

The url_for return from root path. How about relative_url ?

If you want to get absolute path, how about config.root + page.prev.path ? It will be return www.example.com/blog/post1.html

The url_for return from root path. How about relative_url ?

If you want to get absolute path, how about config.root + page.prev.path ? It will be return www.example.com/blog/post1.html

Thanks a lot, dear YoshinoriN.

I think it will be better if Hexo solves this small problem, because the doc of Hexo recommends using function url_for(page.path).

In #3701 full_url_for helper is added to Hexo and will be released with Hexo v4. Use full_url_for helper after Hexo v4 if you need to get absolute path.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JackieLuo picture JackieLuo  ·  45Comments

fabien-h picture fabien-h  ·  22Comments

dsaltares picture dsaltares  ·  46Comments

curbengh picture curbengh  ·  24Comments

Xuanwo picture Xuanwo  ·  42Comments