Hexo之Next主题站点的SEO优化

通过对Hexo站点Next主题的静态网站做SEO优化,以提升个人博客排名。

添加sitemap.xml

1
2
3
npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save
hexo g # 生成的静态资源就会包含sitemap.xml

添加蜘蛛协议robots.txt

在网站根目录下添加robots.txt协议,网络上有专门生成改文件格式的网站。
配置好robbots.txt文件后,将其放在Next主题下的source目录中。

百度URL主动提交插件

可以及时主动地向搜索引擎提交你站的新增文章url,对于搜索引擎的及时收录有一定的帮助。如果是一个高质量的老站,而且蜘蛛爬取频次很快的站的话,并不需要该插件。

  1. 安装插件
    1
    npm install hexo-baidu-url-submit
  2. 站点配置文件
    1
    2
    3
    4
    5
    baidu_url_submit:
    count: 1 # count表示每次提交几条最新的url
    host: # 网站域名
    token: # 百度站长后台主动提交处的 token
    path: # baidu_urls.txt
  3. 站点配置文件中deploy的配置
    其中deploy的type只能同时存在一个,这就需要在部署与提交url之间相互切换了。
    1
    2
    3
    4
    5
    6
    7
    8
    deploy:
    # type: git
    type: baidu_url_submitter # 百度自动提交URL
    branch: master # 分支名称。如果您使用的是 GitHub 或 GitCafe 的话,程序会尝试自动检测。
    repo: # 库(Repository)地址
    coding:
    github:
    message: # 自定义提交信息 (默认为 Site updated: {{ now('YYYY-MM-DD HH:mm:ss') }})

对出站的链接添加nofollow标签

nofollow标签的意义在于指示搜索引擎不要追踪(即抓取)网页上的带有nofollow属性的任何出站链接,以减少垃圾链接的分散网站权重!
百度百科参看Nofollow说明

nofollow插件

nofollow插件能够给所有非本站的超链接加上nofollow标签。

  1. 安装nofollow插件

    1
    npm install hexo-autonofollow --save
  2. 站点配置文件

    1
    2
    3
    4
    5
    #nofollow插件配置
    nofollow:
    enable: true
    exclude: # 排除项
    - tophat.top

Next主题需要改以下几个地方:

手动添加已弃用,使用上面介绍的插件
以下内容是在next7.0版本中进行修改,其他版本如果有差异,请执行查找。

  1. sidebar.swig:
    路径:next/layout/_macro/sidebar.swig
    搜索https://hexo.iohttps://theme-next.org,在其后面添加(对a标签进行拼接):
    1
    + '"' + ' ref="external nofollow'
  2. footer.swig:
    路径:next/layout/_partials/footer.swig
    搜索https://creativecommons.org/,找到下方的next_url(ccURL在其后添加:
    1
    + '"' + ' ref="external nofollow'
    如果有其他区域自行查找。

文章三层目录地址以URL持久化

  1. 使用hexo-abbrlink这个插件,猜测是根据时间点算出的最终链接,后期不管怎么修改永久链接都不会变.一来自己不用再增加什么属性了,也不用考虑分类中文化的问题。
    二来后面的层级更短,更利于SEO。(一般SEO只爬三层)
    安装abbrlink插件模块:
    1
    npm install hexo-abbrlink --save
  2. 站点配置文件
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: http://tophat.top
    root: /
    permalink: posts/:abbrlink.html # 默认项 :year/:month/:day/:title/
    permalink_defaults:

    # 链接持久化插件abbrlink,添加插件:npm install hexo-abbrlink --save
    abbrlink:
    alg: crc32 # 算法:crc16(default) and crc32
    rep: hex # 进制:dec(default) and hex