背着锄头的互联网农民

0%

hexo支持google搜索

当我们使用hexo搭建好一个网站后,自然希望博客内容能用google搜索到。但是这里我们需要做一些事情,才能被Google搜索引擎搜索到。下文将详细介绍需要做的事情:

验证网站

在Google搜索引擎中输入如下内容,如果能看到你自己网站的内容,则说明验证成功。如果你的网站是新建立的,自然在这里搜索不到。本文一下内容将介绍如何能够被搜索到。

1
site:springzzj.github.io

验证所有权

为了被Google搜索到,Google首先需要验证你是这个网站的所有人。前往Google Search Console,点添加资源,输入你的域名:https://springzzj.github.io。验证方式我们采用推荐的验证方式Html文件的方式,下载Html文件googlebddd24d26c36e362.html到hexo的source文件夹,并在文件中添加layout:false(否则会出现验证失败的问题),内容如下:

1
2
3
layout: false
---
google-site-verification: googlebddd24d26c36e362.html
回到Google Search Console页面,点击验证完成网站的所有权验证。

提交链接信息

要让Google搜索到我们需要提交站点地图文件sitemap.xml给到搜索引擎,进行如下步骤:

  • 安装生成sitemap.xml的插件工具
    1
    npm install hexo-generator-sitemap --save
  • 在_config.yml添加内容
    1
    2
    3
    urlforgoogle: https://springzzj.github.io/
    sitemap:
    path: sitemap.xml
  • 同时需要确保_config.yml中的url值为自己的域名地址,否则验证sitemap.xml会不通过
    1
    url: https://springzzj.github.io/
  • 执行hexo g && hexo d 提交内容到github
  • 验证sitemap 回到Google Search Console,点击站点地图,输入https://springzzj.github.io/sitemap.xml,完成站点地图验证
生成robots.txt

在hexo的source目录下生成robots.txt文件内容如下,并执行hexo g && hexo d发布出去。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
User-agent: *

Allow: /
Allow: /archives/
Allow: /categories/
Allow: /tags/

Disallow: /vendors/
Disallow: /js/
Disallow: /css/
Disallow: /fonts/
Disallow: /vendors/
Disallow: /fancybox/

Sitemap: https://springzzj.github.io/sitemap.xml

其他

为了加快Google扫描我们网站的速度,可以通过如下方式

  • 进入Google Search Console,点击网址检查,输入我们网址内容并点击请求编入索引
  • 在浏览器中输入https://www.google.com/ping?sitemap=https://springzzj.github.io/sitemap.xml要求Google给网站建立索引。

等待几分钟后,再在Google搜索中输入site:springzzj.github.io后就可以看到网站的内容。