2

In Hexo how do I remove the index.html bit from page.path?

My code:

<link rel="canonical" href="<%= config.url %>/<%= page.path %><% } %>">

Rendered HTML:

<link rel="canonical" href="http://yoursite.com/about/index.html">

Thank you in advance

2 Answers2

1

This request is on the roadmap for Hexo 4.0. It hasn't been implemented yet (at the time of writing this answer).

In the issue above, sapegin gave a workaround using a custom helper:

hexo.extend.helper.register('page_url', function(path, options) {
    return this.url_for(path, options).replace(/index\.html$/, '');
});

If you place this helper in a file like scripts/helpers.js, you can then use it in your posts and pages:

<%= page_url(page.path) %>

It's not as nice as a built-in variable, but it works.

Nate Barbettini
  • 51,256
  • 26
  • 134
  • 147
0

Because pages need to place in subdirectory. It's looks like this:

source
  _posts
  ...
  about
    index.md

That's all. No need any helpers here.

P.S. You also can see live example and source code with this.

Ivan Nginx
  • 111
  • 1
  • 1
  • 5