Hexo博客功能扩展 - 菜单,SEO以及作者信息

401 阅读5分钟

Hexo博客功能扩展 - 菜单,SEO以及作者信息(四)

目前hexo博客的基本图床已经搭建,现在需要让我们的博客扩散出去,Hexo V7 之后,将seo优化整合到了内部,目前优化的方式比较多,可以使用下面几种方式:

  • 百度站长
    • 主动推送
    • 自动推送
    • sitemap
  • 谷歌search
    • sitemap
  • robot.txt 蜘蛛协议
  • 友链
    • 因为a链接的缘故,加快搜索引擎的收录
  • 使用博客网站附上个人博客链接的方式,增加爬虫抓取

添加菜单项:

  • 添加“分类”
  • 添加“标签”

后续操作之前,先修改theme/next/_config.yml文件

配置具体如下:

menu:
  home: / || home
  about: /about/ || user
  tags: /tags/ || tags
  categories: /categories/ || th
  archives: /archives/ || archive
  #schedule: /schedule/ || calendar
  #sitemap: /sitemap.xml || sitemap
  #commonweal: /404/ || heartbeat
  

添加分类菜单

  • 进入hexo根目录,运行git bash
  • 输入命令 hexo new page categories
    • 生成一个categories页面,里面存在index.md文件
  • 编辑index.md,添加如下内容
title: 分类
date: 2020-01-29 14:35:32
type: "categories"
comments: false #关闭评论

添加标签信息

  • 进入hexo根目录,运行git bash
  • 输入命令 hexo new page tags
    • 生成一个categories页面,里面存在index.md文件
  • 编辑index.md,添加如下内容
title: 标签
date: 2020-01-29 14:35:32
type: "tags"
comments: false #关闭评论

文章底部作者的相关信息

比较麻烦,需要更改源代码,同时还要增加对应的组件

blog.csdn.net/u011236348/…

这里嫌麻烦就没有处理了,有需要后续再进行整理

修改头像

  • 修改/theme/next/_coonfig.yml
# Sidebar Avatar
avatar:
  # Replace the default image and set the url here.
  url: /images/avatar1.jpg
  # If true, the avatar would be dispalyed in circle.
  rounded: true
  # If true, the avatar would be rotated with the cursor.
  rotated: false
  • rotated 是经过的时候旋转图片,个人决定花眼还毫无意义,就关闭了

SEO百度优化(重点)

next 7 之后的版本可以更为快捷,使用HTML验证模式

在配置文件党政加入如下内容

# See: https://ziyuan.baidu.com/site
baidu_site_verification: MBold0Egj9

# Enable baidu push so that the blog will push the url to baidu automatically which is very helpful for SEO.
baidu_push: true

重新部署网站之后,点击验证即可

SEO 谷歌优化

个人不满足国内网站的seo收录,这里也想要让谷歌收录我的网站

  • 前提条件

  • 自备科学上网工具

  • 登陆谷歌,进入下面的网址

  • 这里选择网站前缀验证(和百度的类似)

  • 选择HTML验证

    • 将html 中的content 验证码复制一下
  • 打开next/_config.yml文件

    • 找到如下内容
    # Google Webmaster tools verification.
    # See: https://www.google.com/webmasters
    google_site_verification: ZyC1bd11DZ5XV3P11yBfvTIuaPZzFxxkUEnAhZ6zQSA
    
  • 重新部署一下你的网站

    • 这一步不能少,否则验证失败
  • 返回谷歌验证网站,点击验证

  • 等待返回结果,进入到管理界面,新建立的站点需要一天左右收集信息

添加百度和谷歌的站点地图

参考:tengj.top/2016/03/14/…

  • 执行如下两个命令

    • npm install hexo-generator-sitemap --save
    • npm install hexo-generator-baidu-sitemap --save
  • 如果你在你的博客根目录的public下面发现生成了sitemap.xml以及baidusitemap.xml就表示成功了

  • 谷歌设置sitemap

    • 进入管理页面:search.google.com/search-cons…
    • 在域名后面接入sitenap.xml
    • 提交,查看返回结果是否正确,如果正确表示isitemap设置成功
  • 百度设置stemap

    百度主动推送

新增蜘蛛协议

这里直接给出一份robots文件做参考

# hexo robots.txt
User-agent: * Allow: /
Allow: /archives/
Disallow: /vendors/
Disallow: /js/
Disallow: /css/
Disallow: /fonts/
Disallow: /vendors/
Disallow: /fancybox/

Sitemap: http://lazytime.site/sitemap.xml
Sitemap: http://lazytime.site/baidusitemap.xml

前置准备:

  • hexo/_config.yml下面增加如下配置:
# 自动生成sitemap
sitemap: 
  path: sitemap.xml
baidusitemap: 
  path: baidusitemap.xml

开始

为了让网站更好的抓取我们的博客,提高我们博客的排名,这里在hexo/source下面增加了一个robots.txt文件,用于配置蜘蛛协议的相关信息

# hexo robots.txt
User-agent: * Allow: /
Allow: /archives/
Disallow: /vendors/
Disallow: /js/
Disallow: /css/
Disallow: /fonts/
Disallow: /vendors/
Disallow: /fancybox/

Sitemap: http://网站域名/sitemap.xml
Sitemap: http://网站域名/baidusitemap.xml
  • 注意更改一下sitemap为自己的
  • 重新部署即可生效

hexo文章模板的配置参考

为了更好的让后续的文章被收录,这里我修改了下默认的文字模板配置

  • 修改D:\interllinjIdea\hexo\scaffolds\posts.md 打开
title: {{ title }}
subtitle: '这个人很懒,不想写副标题'
author: lazytime
date: {{ date }}
tags:
- 无
categories:
- 未分类
keywords: 请输入关键字(英文逗号分隔多个关键字)
description: 请输入描述信息

  • 这里我关掉了description会替换掉我们的介绍信息的设置,我只是让他作为一个简短介绍使用
# Automatically excerpt description in homepage as preamble text.
excerpt_description: false

题外话

  1. 本次教程使用文字描述,不是很好懂,写博客的时候国内申请的域名还在审核阶段,后续还需要备案比较蛋疼
  2. 一些SEO优化建议多谷歌一下翻翻资料,包括蜘蛛robot.txt文件的编写,这些都是很有帮助的,个人对于爬虫知识欠缺,请多多包涵
  3. 隔三差五的去看看个人网站收录是否成功,因为github 会被百度禁用

推荐一下这篇文章

www.jianshu.com/p/5b4c98490…

对于seo的优化介绍的比较详细