Hexo NexT - Enable noindex HTML Meta Tag

有时我们可能不希望某些文章出现在搜索引擎的结果中。根据 Google 的帮助文档,主要有两种解决方案:

  1. 在页面内容中的 <head>  部分添加含有 noindex 指令的 <meta>  标签
  2. 在页面的 HTTP 响应头中添加 X-Robots-Tag: noindex 字段

本文将介绍如何在 NexT 主题中实现第一种方法。

经过一番 code review 我找到了这个文件 themes/next/layout/_partials/head/head-unique.swig 。在该文件的最后添加几行:

1
2
3
{% if page.noindex %}
<meta name="robots" content="noindex"/>
{% endif %}

保存退出,接下来在不想被搜索引擎收录的页面的 Front-matter 中添加一行即可:

1
noindex: true