Yao Lirong's Blog

博客SEO优化

2022/04/23

谷歌和我网站有仇吗,弄了好几天,怎么别人等一天就行了,我等一个礼拜也搞不定。换了域名以后还不如原来,原来谷歌自动就给我 index 了。这样想还是要感谢营销号和爬虫,爬了我一个我自己都看不下去的题解,竟然让我原来的博客被收录了,可惜这个新的弄起来就麻烦了…

验证所有权

首先我们需要验证网站所有权,选用 HTML tag 方式

在 Hexo - Archer 主题下找到 layout - _partial - base-head.ejs 中在 <head> tag 下添加需要的验证 tag

对于不同的主题,一个快速找到 <head> 在哪里生成的方法就是直接查找 <head> tag

本地插件生成必要文件

使用 npm install <name> --save 安装以下几个插件:

  • hexo-generator-robotstxt
  • hexo-generator-sitemap
  • hexo-generator-baidu-sitemap
  • hexo-autonofollow

Add the following plugin’s settings to root directory _config.yml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
sitemap:
path: sitemap.xml
baidusitemap:
path: baidusitemap.xml

robotstxt:
useragent: "*"
disallow:
- /assets/
- /css/
- /avatar/
- /scripts/
- /font/
- /lib/
allow:
- /
- /archives/
- /categories/
- /tags/
- /about/
- /page/
sitemap:
- https://yao-lirong.github.io/sitemap.xml
- https://yao-lirong.github.io/baidusitemap.xml

nofollow:
enable: true

Google

有些时候如果不进行这些所谓『优化』,你只能等有人链接到你的页面谷歌才会收录,所以这些优化实际上是必要的。

  1. Canonical Tag 优化: 和前文一样,找到在 <head> tag 中对应位置,添加以下代码

    1
    2
    3
    4
    5
    6
    <% 
    var base_url = config.url;
    if (config.url.charAt(config.url.length - 1) !== '/') base_url += '/';
    var canonical_url = base_url + page.canonical_path.replace('index.html', '');
    %>
    <link rel="canonical" href="<%= canonical_url %>">
  2. 提交 sitemap.xml: 首先从 Search Console 中提交,在通过 ping 提交上双保险

  3. 提交 robots.txt: 从这里可以提交并看到谷歌最新抓取到的 robots.txt

  4. 提交了这些东西以后需要等好久,这时为了确认我们网站啥的确实没问题,心理求个安慰,使用 URL Inspection in Search Console, or directly at this link https://search.google.com/search-console/inspect?resource_id=<url you want to check rn>.

    如果显示”URL is not on Google”,选择 “TEST LIVE URL”, 只要我们看到 “URL is available to Google” 以及 “User-declared canonical” 这一栏确实是本文网址一般就没问题。

    此时,为了加快 index 进程,我们可以 “Request Indexing” 虽然只有这一个 page,但芝麻肉也是肉…

Google Sitemap 的问题

上面用了 URL inspection tool 全是因为老显示我 sitemap couldn’t fetch. 查询了一下能做的只有等待…

谷歌工作人员的回复, 一个描述问题比较全的网站

Reference

  1. Hexo搜索引擎优化: 大部分有用的 Google SEO 优化步骤都来自这里
  2. Get Google to Index Your Site: 以及国外的一个比较全的 Google 排雷网站
CATALOG
  1. 1. 验证所有权
  2. 2. 本地插件生成必要文件
  3. 3. Google
  4. 4. Google Sitemap 的问题
  5. 5. Reference