LoginSignup
0
0

More than 1 year has passed since last update.

Gatsby.jsでsitemapを作成しGoogle Search Consoleに提出する

Posted at

方法

①プラグインgatsby-plugin-sitemapを使用し、サイトマップを作成する。
②{サイト名}.com/sitemap/sitemap-0.xmlにアクセスし、作成されていることを確認する。
③Google Search Consoleへ{サイト名}.com/sitemap/sitemap-0.xmlを提出する。

環境

Gatsby.jsバージョン4.6.0

①サイトマップの作成

プラグインのインストール

npm install gatsby-plugin-sitemap

gatsby-config.jsへの追加

gatsby-config.js
plugins: [
        {
            resolve: `gatsby-plugin-sitemap`,
            options: {
                excludes: [`/除外するページ/`,]
            }
        },
],

注意点として、Gatsby2以前は「exclude」だったoptionsの記述が現在「excludes」と記述するよう変更になっている。
※横着してググった記事を見て以前の記述の方法が載っているためうまくいかずにハマりました。公式のドキュメントを読むべきという自戒の意味を込めて書いておきます。

何かがおかしいことに気づかせて頂いた記事

https://qiita.com/ebifry_w_t/items/84fb29790c8357ca2819

公式のドキュメント

https://www.gatsbyjs.com/plugins/gatsby-plugin-sitemap/

②サイトマップの作成と確認

ビルドしてローカル環境のpublic/sitemap/sitemap-0.xmlが作成されていることを確認する。

gatsby build

ローカル環境から確認するためサーバーを立ち上げる

gatsby serve もしくは gatsby develop

{サイト名}.com/sitemap/sitemap-0.xmlにアクセス。
作成されていることと除外するページの指定などがうまくいっているかを確認する。

③提出

Google Search Consoleのサイトマップ欄から②で確認したサイトマップのURLを貼り付けて提出。
例: {サイト名}.com/sitemap/sitemap-0.xml

ステータスの更新に若干時間がかかった覚えがあります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0