添加站點地圖
安裝插件
需要安裝兩個插件來生成 sitemap 文件,前一個是傳統(tǒng)的 sitemap得湘,后一個是百度的 sitemap杖玲。
npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save
修改站點配置文件
將sitemap
文件添加到站點配置文件_config.yml
中,并修改url
字段的值淘正,其值默認(rèn)為http://yoursite.com
天揖。
sitemap:
path: sitemap.xml
baidusitemap:
path: baidusitemap.xml
url: https://hoxis.github.io
安裝完成后執(zhí)行hexo g
即會在站點public
目錄下生成sitemap.xml
和baidusitemap.xml
夺欲。
添加蜘蛛?yún)f(xié)議
在站點source
文件夾下新建robots.txt
文件,文件內(nèi)容如下:
User-agent: *
Allow: /
Allow: /archives/
Allow: /categories/
Allow: /tags/
Allow: /resources/
Disallow: /vendors/
Disallow: /js/
Disallow: /css/
Disallow: /fonts/
Disallow: /vendors/
Disallow: /fancybox/
Sitemap: https://hoxis.github.io/sitemap.xml
Sitemap: https://hoxis.github.io/baidusitemap.xml
Allow
字段的值即為允許搜索引擎爬區(qū)的內(nèi)容今膊,可以對應(yīng)到主題配置文件中的menu目錄配置些阅,如果菜單欄還有其他選項都可以按照格式自行添加。
需要將https://hoxis.github.io
改成自己的域名斑唬。
提交站點到 Google
打開Google Search Console市埋,添加博客地址。
站點驗證
Google
給出的推薦方法是上傳HTML
文件恕刘,但是不知道為什么一直驗證失敗缤谎,所以我選擇了備用方法中的HTML 標(biāo)記
,將給出的元標(biāo)記復(fù)制到\themes\hexo-theme-next\layout\_partials\head.swig
文件中褐着。添加后運行hexo d -g
將改動提交坷澡。稍后就可以驗證成功了。
your-hexo-site\themes\hexo-theme-next\layout\_partials\head.swig
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="{{ theme.android_chrome_color }}">
<meta name="google-site-verification" content="xxxxxxxxxxxxx" />
<meta name="baidu-site-verification" content="xxxxxxxxx" />
該方法是通過校驗網(wǎng)頁中<head>
中的屬性來進(jìn)行校驗的含蓉。
<html>
<head>
<meta name="google-site-verification" content="S2s6Oge-PuQt56EBO4t90FLwhL0P0faoH08iSNXe8iU" />
<title> 我的標(biāo)題 </title>
</head>
<body>
網(wǎng)頁內(nèi)容
</body>
</html>
測試 robots.txt 文件
點擊左側(cè)的robots.txt測試工具频敛,根據(jù)提示提交你的robots.txt。
注意要0錯誤才可以馅扣,如果有錯誤的話斟赚,會有提示,改正確就可以了差油。
提交站點地圖
點擊右上角添加/測試站點地圖輸入 sitemap.xml 進(jìn)行測試拗军,測試無誤后再提交文件。
Google抓取方式
到了最后一步蓄喇,如果上方的輸入框留空表示抓取首頁发侵,抓取方式可以選擇桌面,智能手機(jī)等等妆偏,自行根據(jù)需要選擇器紧。填好url之后,點擊抓取楼眷。
抓取完成后可能會有幾種狀態(tài):完成灶挟、部分完成和已重定向等逛揩,不過無需擔(dān)心,這些狀態(tài)并不會影響提交满力。此時點擊請求編入索引即可狰住,至此博客就成功提交到了 Google张吉,你的博客在google搜索上排名想不靠前都難了,馬上上google搜索一下你的關(guān)鍵詞和博客title測試一下吧催植。
網(wǎng)站結(jié)構(gòu)自身優(yōu)化
出站鏈接添加nofollow標(biāo)簽
網(wǎng)絡(luò)爬蟲會在當(dāng)前頁面搜索所有的鏈接肮蛹,然后一個個查看勺择,所以就很有可能跳到別的網(wǎng)站就不回來了。這個時候就需要nofollow
起作用了伦忠。
nofollow標(biāo)簽
是由谷歌領(lǐng)頭創(chuàng)新的一個反垃圾鏈接
的標(biāo)簽省核,并被百度、yahoo等各大搜索引擎廣泛支持昆码,引用nofollow標(biāo)簽的目的是:用于指示搜索引擎不要追蹤(即抓绕摇)網(wǎng)頁上的帶有nofollow屬性的任何出站鏈接,以減少垃圾鏈接的分散網(wǎng)站權(quán)重赋咽。
修改footer.swig文件
路徑在your-hexo-site\themes\next\layout\_partials
旧噪,將下面代碼中的a標(biāo)簽加上rel="external nofollow"
屬性。
{{ __('footer.powered', '<a rel="external nofollow" class="theme-link" target="_blank" ) }}
<a rel="external nofollow" class="theme-link" target="_blank" >
修改sidebar.swig文件
路徑在your-hexo-site\themes\next\layout_macro
脓匿,將下面代碼中的a標(biāo)簽加上rel="external nofollow"
屬性淘钟;
<a href="https://creativecommons.org/{% if theme.creative_commons === 'zero' %}publicdomain/zero/1.0{% else %}licenses/{{ theme.creative_commons }}/4.0{% endif %}/" rel="external nofollow" class="cc-opacity" target="_blank">
<a href="{{ link }}" title="{{ name }}" rel="external nofollow" target="_blank">{{ name }}</a>
<a rel="external nofollow" href="{{ link.split('||')[0] | trim }}" target="_blank" title="{{ name }}">
添加關(guān)鍵字
修改模板your-hexo-site\scaffolds\post.md
文件,添加keywords
和description
字段陪毡,用于生成的文章中添加關(guān)鍵字和描述米母。
title: {{ title }}
date: {{ date }}
tags:
keywords:
description:
---
修改博文鏈接
HEXO默認(rèn)的文章鏈接形式為domain/year/month/day/postname
,默認(rèn)就是一個四級url缤骨,并且可能造成url過長爱咬,對搜索引擎是十分不友好的,我們可以改成domain/postname 的形式绊起。編輯站點_config.yml
文件精拟,修改其中的permalink
字段改為permalink: :title.html
即可。
#permalink: :year/:month/:day/:title/
permalink: :title.html
首頁title優(yōu)化
更改index.swig
文件your-hexo-site\themes\next\layout
將下面這段代碼:
{% block title %} {{ config.title }} {% endblock %}
改成
{% block title %} {{ config.title }} - {{ theme.description }} {% endblock %}
這時候你的首頁會更符合網(wǎng)站名稱-網(wǎng)站描述
這習(xí)慣虱歪。
進(jìn)階蜂绎,做了seo優(yōu)化,把關(guān)鍵詞也顯示在title標(biāo)題里笋鄙,可改成
{% block title %} {{ theme.keywords }} - {{ config.title }}{{ theme.description }} {% endblock %}
注意:別堆砌關(guān)鍵字师枣,整個標(biāo)題一般不超過80個字符,可以通過chinaz的seo綜合查詢檢查萧落。
如果覺得有用践美,歡迎關(guān)注我的微信,有問題可以直接交流: