最近对 Hexo 博客进行了结构化数据(Structured Data)与 SEO 配置优化,过程中踩了不少坑,以下是完整的记录与总结,希望对同样使用 Hexo 的朋友有所帮助。

一、起因:Search Console 无法检测结构化数据

起初在 Google 的 Rich Results 测试工具和 Search Console 中发现博客页面无法识别任何结构化数据,怀疑是结构化数据输出有误。

二、排查过程与问题定位

1. 替换 schema.org.cn 为 schema.org

在检查页面源代码后发现结构化数据的 @context 字段中使用了 https://schema.org.cn,而 Google 仅识别 https://schema.org,于是批量替换:

1
find . -type f -exec sed -i 's/schema\.org\.cn/schema.org/g' {} +

修改后重新部署,Rich Results 测试开始可以正常识别结构化数据。但具体是因为该原因还是只是延迟导致的,还没有完全确定。

2. Search Console 仍无索引

虽然 Rich Results 工具成功检测,但 Search Console 中依然没有任何结构化数据结果。考虑可能是 Google 尚未重新抓取,决定暂时不再深究。

三、SEO 配置优化建议(基础 + Open Graph + Structured Data)

(1)基础 SEO 设置

keywords 配置

1
use_tags_as_keywords: true

建议在首页或重要页面额外加上 front-matter 中的 keywords 字段,并限制关键词数量(推荐 5–10 个)以避免关键词堆砌。

description 描述

1
use_excerpt_as_description: true

摘要需控制在 150–160 字,建议重要页面手动设置 description,可加入品牌词、核心亮点。

robots 设置

1
2
3
4
5
home_first_page: index,follow
home_other_pages: noindex,follow
archive: noindex,follow
category: noindex,follow
tag: noindex,follow

若分页/分类/标签页确实有价值内容,可将其调整为 index,follow

sitemap.xml 配置

确保安装并正确配置:

1
npm install hexo-generator-sitemap --save

并在 robots.txt 中声明:

1
Sitemap: https://your-domain.com/sitemap.xml

canonical 链接

建议启用,避免重复页面影响权重。

(2)Open Graph 社交分享

默认图片

open_graph.image 建议使用完整 URL,例如:

1
2
open_graph:
image: https://cdn.jsdelivr.net/gh/your-repo/img/android-chrome-192x192.png

Twitter 类型

如果文章有大封面图,建议使用:

1
twitter_card_type: summary_large_image

Twitter ID

1
2
twitter_id: "@your_id"
twitter_site: "@your_site"

(3)Structured Data 结构化数据

已启用类型:BlogPosting、BreadcrumbList、Organization、Person、Website。

建议确认以下字段输出完整:

  • headline
  • datePublished
  • dateModified
  • mainEntityOfPage
  • author.name
  • publisher.logo

组织信息 Organization

1
2
3
4
5
6
7
8
structured_data:
data:
organization:
name: "Your Brand"
url: "https://your-domain.com"
sameAs:
- "https://twitter.com/your_brand"
- "https://github.com/your_brand"

作者信息 Person

1
2
3
4
person:
name: "Your Name"
url: "https://your-domain.com/about"
image: "https://your-domain.com/img/avatar.png"

四、Search Console 报错 sitemap.xml “Couldn’t fetch” 的解决

在 Search Console 添加 sitemap.xml 时出现 “Couldn’t fetch” 报错,但直接访问如 https://ai.example.xyz/sitemap.xml 却正常。

排查后确认是插件未安装导致未生成 sitemap 文件。解决方法:

1
npm install hexo-generator-sitemap --save

然后重新部署:

1
hexo clean && hexo g && hexo d

再次提交 sitemap 即可正常解析。

五、总结

通过上述一系列配置与排查,博客的结构化数据已能被 Google 正确识别,同时也梳理了 SEO 的相关策略,包括关键词、摘要、社交分享优化等。

建议所有 Hexo 用户结合自己内容情况进行适度调整,重点关注 sitemap 输出、结构化数据 schema 正确性、以及 Meta 标签内容丰富性。

祝各位博客 SEO 提升顺利!