讓 Google Search 找到你的網頁
本文介紹如何設定使用 Jekyll 的 GitHub Pages 網站,讓 Google Search 能夠搜尋到你的網頁。
1. 在 Google Search Console 中註冊網站
首先,在 Google Search Console 中註冊你的網站,主動要求 Google 的爬蟲索引你的網站。
由於 GitHub Pages 網站的網址通常是 https://<username>.github.io/,只有在這個網址底下的網頁屬於你的網站,因此在 Google Search Console 中註冊需選擇網址前置字元,並輸入你的網站網址,以新增網站。
在註冊完成後,Google Search Console 會要求你驗證網站的擁有權。可選擇透過HTML 檔案 來驗證。
下載該驗證之 HTML 驗證檔案,並將其放在 Github Pages Repository 的根目錄下,並進行 commit 及 push,再回到 Google Search Console 中,點擊驗證按鈕,完成網站的驗證。
2. 在 Jekyll 網站中加入 SEO 設定
我們需要在網站中加上 sitemap.xml 以提供網站的結構,讓 Google 的爬蟲可以快速解析網站的頁面內容。並提供 robots.txt 來告訴爬蟲哪些頁面可以被索引,哪些頁面不可以被索引。
另外,我們可以在網站中的 head 中加入 SEO 標籤,提供網站的描述、關鍵字等資訊,讓 Google 的爬蟲可以更快速的了解網站的內容,並且在搜尋結果中顯示網站的描述。
這些檔案可以透過 Jekyll 的 jekyll-sitemap 和 jekyll-seo-tag 來自動產生,前者會產生 sitemap.xml 及 robots.txt,後者會產生 SEO 標籤。
若您按照 使用 Jekyll 建立 GitHub Pages 建立網站,以下是設定的步驟:
-
在
Gemfile中加入jekyll-sitemap和jekyll-seo-tag的 plugin 設定# If you want to use GitHub Pages, remove the "gem "jekyll"" above and # uncomment the line below. To upgrade, run `bundle update github-pages`. gem "github-pages","~> 232", group: :jekyll_plugins # If you have any plugins, put them here! group :jekyll_plugins do gem "jekyll-feed", "~> 0.17" gem "jekyll-seo-tag", "~> 2.8" # 新增在這裡 gem "jekyll-sitemap", "~> 1.4" # 還有這裡 end -
在 shell 中執行
bundle install以安裝新增的 plugin,在本機上預覽網站時,才能正確顯示 sitemap.xml 和 robots.txtbundle install -
在
_config.yml中加入jekyll-sitemap和jekyll-seo-tag的設定以啟用新增的 pluginplugins: - jekyll-feed - jekyll-seo-tag # 新增在這裡 - jekyll-sitemap # 還有這裡 -
確保
_includes/head.html中有加入jekyll-seo-tag的設定```html
```
這行會自動產生 SEO 標籤,並加入網站的 head 中。
- 在本機上執行
bundle exec jekyll serve以預覽網站,並確認sitemap.xml和robots.txt是否正確產生,預設會產生在網站的根目錄下。
3. 在 Google Search Console 中註冊 sitemap.xml
在 Google Search Console 網頁中,點選左側的產生索引 > Sitemaps,在右側的新增 sitemap 欄位中,輸入 sitemap.xml,並點擊送出按鈕,完成 sitemap.xml 的註冊。
這樣 Google 的爬蟲就會定期抓取你的網站,並更新索引的內容。