【问题标题】:Remove index.html from Hexo URL?从 Hexo URL 中删除 index.html?
【发布时间】:2016-10-04 07:20:24
【问题描述】:

在 Hexo 中,如何从 page.path 中删除 index.html 位?

我的代码:

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

呈现的 HTML:

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

提前谢谢你

【问题讨论】:

  • 这个的最终目标是什么?
  • 对于 SEO 来说,如果规范 URL 与 URL 相同,它会很好,我只在页面上获得 /index.html,但帖子很好。

标签: ejs hexo


【解决方案1】:

requestroadmap for Hexo 4.0 上。它尚未实施(在撰写此答案时)。

在上述问题中,sapegin 提供了一种使用自定义帮助程序的解决方法:

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

如果您将此帮助程序放在像 scripts/helpers.js 这样的文件中,您就可以在您的帖子和页面中使用它:

<%= page_url(page.path) %>

它不如内置变量好,但它可以工作。

【讨论】:

    【解决方案2】:

    因为页面需要放在子目录中。它看起来像这样:

    source
      _posts
      ...
      about
        index.md
    

    就是这样。这里不需要任何帮助。

    附:你也可以看到live examplesource code

    【讨论】:

      猜你喜欢
      • 2014-04-24
      • 2014-02-26
      • 2019-05-27
      • 2018-06-01
      • 2016-09-14
      • 1970-01-01
      • 2017-08-11
      • 2021-10-23
      • 2015-03-09
      相关资源
      最近更新 更多