使用 Hexo 搭配 Next 主题搭建博客

Hexo 下载及安装

官方网址: http://hexo.io
Github: https://github.com/hexojs/hexo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 安装
npm install hexo-cli -g
# 初始化
hexo init blog
cd blog
# DEBUG 模式
hexo s --debug
# 新建文章
hexo new "Hello Hexo"
# 生成静态文件
hexo generate # 或 hexo g
# 部署(需要配置部署方式)
hexo deploy # 或 hexo d
# >>>>>> 升级 hexo
npm update

Algolia 插件安装

1
2
# 生成搜索索引
hexo algolia

Next 主题插件安装

官方网址: http://theme-next.iissnan.com
Github: https://github.com/iissnan/hexo-theme-next

  • 安装 Next
1
2
3
4
5
6
7
8
9
10
11
# 在站点根目录下
git clone https://github.com/iissnan/hexo-theme-next themes/next
# 站点配置文件 _config.yml 启用主题
theme: next
# >>>>>> 升级 next
git clone https://github.com/theme-next/hexo-theme-next themes/next-reloaded
# 站点配置文件 _config.yml 启用主题
theme: next-reloaded
# 语言改为 zh-CN
language: zh-CN
# 其他细节:https://github.com/theme-next/hexo-theme-next/blob/master/docs/zh-CN/UPDATE-FROM-5.1.X.md

SEO

  • 蜘蛛协议

在网站 source 目录增加蜘蛛协议 robots.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# hexo robots.txt
User-agent: *
Allow: /
Allow: /archives/

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

Sitemap: http://blog.longgen.me/sitemap.xml
Sitemap: http://blog.longgen.me/baidusitemap.xml
  • nofollow

为网站非友情链接的出站链接增加 nofollow 标签

  • 标题关键字优化

百度 SEO

1
2
3
4
5
# 生成百度 sitemap.xml
npm install hexo-generator-baidu-sitemap --save
# 站点配置文件 _config.yml 中添加百度 sitemap 配置
baidusitemap:
path: baidusitemap.xml

主动提交链接至百度

Github 屏蔽百度爬虫导致在 Github Pages 上托管的博客, 网站都无法被百度索引到. 所以需要针对性的进行一些特殊处理

  • 使用 hexo-baidu-url-submit 插件(注意: 站点配置文件 _config.yml 中的 URL 必须是百度站长平台注册的域名)
  • 注册百度站长工具, 然后在工具->网页抓取->链接提交里找到你的密匙 Token
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    # Hexo 博客根目录下安装插件
    npm install hexo-baidu-url-submit --save
    # 配置以下内容到站点配置文件 _config.yml
    baidu_url_submit:
    count: 1 ## 提交最新的一个链接
    host: blog.longgen.me ## 在百度站长平台中注册的域名
    token: your_token ## 请注意这是您的秘钥, 所以请不要把博客源代码发布在公众仓库里!
    path: baidu_urls.txt ## 文本文档的地址, 新链接会保存在此文本文档里
    # 站点配置文件 _config.yml 加入新的 deployer
    - type: baidu_url_submitter
    # 推送包含以下两个步骤
    hexo generate # 生成链接文件
    hexo deploy # 读取链接, 提交至百度搜索引擎

智能 DNS 解析方式

Google SEO

1
2
3
4
5
# 生成 Google sitemap.xml
npm install hexo-generator-sitemap --save
# 站点配置文件 _config.yml 中添加 sitemap 配置
sitemap:
path: sitemap.xml

问题集锦

  • Node 旧版本升级到新版本后, Hexo 命令执行失败. node_modules 缓存问题
1
2
3
4
5
Error: The module '/Users/guojunbing23/gitresource/blong/node_modules/hexo/node_modules/hexo-log/node_modules/bunyan/node_modules/dtrace-provider/build/Release/DTraceProviderBindings.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 46. This version of Node.js requires
NODE_MODULE_VERSION 51. Please try re-compiling or re-installing
the module (for instance, using npm rebuild ornpm install).

解决办法: https://github.com/hexojs/hexo/issues/2534