Sitemap优化
引入如下两个插件
npm install hexo-generator-sitemap --save #sitemap.xml适合提交给谷歌搜素引擎
npm install hexo-generator-baidu-sitemap --save #baidusitemap.xml适合提交百度搜索引擎
然后在站点配置文件_config.yml
中添加以下代码:
# 自动生成sitemap
sitemap:
path: sitemap.xml
baidusitemap:
path: baidusitemap.xml
每次hexo g
后都会在/public
目录下生成sitemap.xml
和baidusitemap.xml
资源路径优化
缩短URI资源路径,最佳结构是用户从首页点击三次就可以到达任何一个页面。修改 permalink:
配置, 如下我将所有文章都放在了 /p/
路径下:
url: http://你的网站
root: /
permalink: p/:title.html
permalink_defaults:
首页标题优化
SEO最重要的是Website的标题,搜索引擎一定会检索标题。
找到你站点 theme 的 layout模块(或者head模块)
将title
的格式处理成: {{post_title}} - {{config.title}} - {{description}}
的格式。
如果向把 keyworlds
方进来也可以,但不能太长(整个标题不超过80个字符),如: {{post_title}}:{{post_keyworlds}} - {{config.title}} - {{description}}
关键词优化
搜索引擎除了主要抓取标题外,页面的关键词和描述也会抓取。
在\scaffolds\post.md
中添加如下代码,用于生成的文章中添加关键字和描述。
keywords:
description:
<meta name="keywords" content="<%= page.keywords %>">
<meta name="description" content="<%= config.description %>">
外链优化-nofollow标记
给所有外链增加 nofollow
标记,意义是告诉搜索引擎”不要追踪此网页上的链接或不要追踪此特定链接”,让搜索引擎在爬取页面时不会出站。
npm install hexo-autonofollow --save
然后在 _config.yml
中增加配置:
nofollow:
enable: true
exclude: #例外的地址
robots.txt文件
在source/ 中创建robots.txt
文件,并写入:
User-agent: *
Allow: /
Allow: /p/
Allow: /archives/
Allow: /about/
Allow: /tags/
Allow: /friends/
Allow: /categories/
Disallow: /js/
Disallow: /css/
Disallow: /libs/
Disallow: /medias/
Sitemap: http://www.ibug.info/sitemap.xml
Sitemap: http://www.ibug.info/baidusitemap.xml
开启推送
将网站链接提交到百度,百度搜索引擎提交入口,然后验证你的网站,这一点网上有很详细的教程我就不复述了,验证确认你的网站后,继续验证你的网站的robots.txt和sitemap文件是否可用,一般都是可用的。
然后就可以开始推送了,基本上推送有三种方式:主动推送>自动推送>sitemap三种,一般主动提交比手动提交效果好。
自动推送
在站点中引入如下js, 每次页面访问都会向百度推送这个页面。
(function(){
var bp = document.createElement('script');
bp.src = '//push.zhanzhang.baidu.com/push.js';
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
手动推送
参考百度资源平台 写个脚本,在每次发布博客后,向 http://data.zz.baidu.com/urls
发起提交。
获取关键词
发布文章前,根据 https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=
关键词结果,回填文章 keyworlds