# Hexo SEO 搜尋引擎最佳化


# Sitemap

Hexo 生成站點地圖

1
yarn add hexo-generator-sitemap

# 提交 Sitemap

Go to Google Search Console

輸入 Domain Name > 選擇 Sitemap > 提供 Sitemap 路徑

sitemap.xml


# robots.txt

建立 robots.txt 檔案 (放置在 source 資料夾下)

robots.txt 是用來給爬蟲的,爬蟲會遵循這個檔案來哪些是可以存取的內容
善用 robots 可以增強 SEO

內容如下

1
2
3
4
5
6
7
8
9
10
11
User-agent: *
Allow: /
Allow: /archives/
Allow: /categories/
Allow: /tags/
Disallow: /vendors/
Disallow: /fonts/
Disallow: /vendors/
Disallow: /fancybox/
Sitemap: https://hsiangfeng.github.io/sitemap.xml
Sitemap: https://hsiangfeng.github.io/baidusitemap.xml

由於爬蟲會爬出所有連結,如果發生遞迴的狀況,就會卡住,但 Theme 通常都有版權聲明,我們要用 nofollow 來協助他

以 shoka 為例 (改變 theme link 與 hexo link)

1
{{ __('footer.powered', _url('https://hexo.io', 'Hexo') + ' & Theme.' + _url('https://github.com/amehime/hexo-theme-shoka', 'Shoka')) }}

改成

1
{{ __('footer.powered') }} <a href='https://hexo.io' rel='external nofollow'>Hexo</a>   {{' & Theme.' }} <a href='https://github.com/amehime/hexo-theme-shoka',rel='external nofollow'>Shoka</a>

基本上只要是非友情連結都可以加上 rel=“external nofollow”,避免爬蟲爬進去後就不回來了。


這是一款打包好的 Hexo Plugin 你可以安裝後稍微設定就可以自動將 link 設置成 nofollow

1
yarn add hexo-autonofollow

在 hexo/source/_config.yml 非主題

1
2
3
4
5
nofollow:
enable: true
exclude: # 註記不被 nofollow 的連結
- xxx.com
- xxx.com

# 填入 keyword

填入 keyword 會讓文章增加 SEO

文章格式如下

1
2
3
4
5
title: ###
date: ###
categories: ###
tags: ###
keywords: ###

# Reference

  • Hexo 搜尋引擎優化