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?
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_forreturn from root path. How aboutrelative_url?If you want to get absolute path, how about
config.root + page.prev.path? It will be returnwww.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.
Addressed by https://github.com/hexojs/hexo/pull/3701
Most helpful comment
The
url_forreturn from root path. How aboutrelative_url?If you want to get absolute path, how about
config.root + page.prev.path? It will be returnwww.example.com/blog/post1.html