hexo-seo推广

People who are crazy enough to think they can change the world, are the ones who do.
Apple Computers

刚搭建完博客,可能你会发现你发表的文章在谷歌或者百度都搜索不到,因为需要进行SEO优化的,什么是SEO,顾名思义,SEO即(Search Engine Optimization):汉译为搜索引擎优化,下面来总结一下SEO优化的方法,让自己的博文能在谷歌百度上搜索到。

生成sitemap

添加站点地图sitemap

Sitemap用于通知搜索引擎网站上有哪些可供抓取的网页,以便搜索引擎可以更加智能地抓取网站。

安装sitemap站点地图自动生成插件hexo-generator-sitemaphexo-generator-baidu-sitemap,用于生成sitemap,在git Bash中执行以下命令:

1
2
npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save

修改站点配置文件将sitemap文件添加到站点配置文件_config.yml中,并修改url字段的值,其值默认为http://yoursite.com。在站点配置文件 _config.yml中添加如下:

1
2
3
4
5
6
sitemap:
path: sitemap.xml
baidusitemap:
path: baidusitemap.xml

url: https://blog.enjoytoshare.club

配置好后,执行hexo g 就能在网站根目录(public目录)中生成sitemap.xml 和 baidusitemap.xml了;其中第一个是一会要提交给google的,后面那个看名字当然就是提交给Baidu的了;

添加蜘蛛协议

网站通过Robots协议告诉搜索引擎哪些页面可以抓取,哪些页面不能抓取。robots.txt 通常存放于网站根目录(public目录)。由于我们每次hexo clean都会清空public,着实不方便,我们都知道source目录下的文件通过hexo g命令会转换成public中的文件,所以为了方便起见,我们把robots.txt文件放在source目录下,我的 robots.txt 内容为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
User-agent: *
Allow: /
Allow: /archives/
Allow: /categories/
Allow: /tags/
Allow: /links/
Allow: /about/
Allow: /index-la/
Allow: /page/
Allow: /js/
Allow: /css/
Disallow: /fonts/
Disallow: /vendors/
Disallow: /fancybox/
Sitemap: https://lamirs.vercel.app/sitemap.xml
Sitemap: https://lamirs.vercel.app/baidusitemap.xml

其中Allow后面的就是你的menu

请自行将blog.enjoytoshare.club改成自己的域名,然后hexo g提交一下

关于js、css能否设置为允许爬虫爬取,请见网站robots文件中到底要不要屏蔽js和css

提交站点到Google

首先保证你要能翻墙出去,连到谷歌,如果没有VPN,可参考下面网址获取:工具盒子

提交博客域名

打开Google Search Console
根据提示注册好之后,添加你的博客域名。

进行站点验证

首先启用相应的styl

1
2
3
4
5
6
7
8
9
10
11
12
13
# Define custom file paths.
# Create your custom files in site directory `source/_data` and uncomment needed files below.
custom_file_path:
head: source/_data/head.njk
#header: source/_data/header.njk
#sidebar: source/_data/sidebar.njk
#postMeta: source/_data/post-meta.njk
#postBodyEnd: source/_data/post-body-end.njk
#footer: source/_data/footer.njk
#bodyEnd: source/_data/body-end.njk
#variable: source/_data/variables.styl
#mixin: source/_data/mixins.styl
#style: source/_data/styles.styl

打开\source\_data/styles.styl

我选择了备用方法中的HTML 标记,将给出的元标记复制到source/_data/head.njk文件中。

添加后运行hexo d -g将改动提交,稍后就可以验证成功了。

提交站点地图

还记得我们刚才创建创建sitemap.xml文件吧,现在它要派上用场了。点击左侧工具栏的站点地图

验证站点是否被收录

在搜索引擎搜索框输入site:your.domain可以查看域名是否被该搜索引擎收录,用户可以使用各大搜索引擎站长工具提交个人博客网址。

验证谷歌收录

site:blog.enjoytoshare.club

域名换成你自己的,谷歌是一定支持的,不过你需要翻墙VPN!如果没有,可参考下面网址获取:工具盒子,如果没有找到你的博客说明没有被收录!