Gatsbyで構築したサイトにSitemapを出力する
Published on April 03, 2020
Google検索により早く表示されるように、GoogleSearchConsoleにSitemapを送信します。
gatsby-plugin-sitemapをインストール
gatsby-plugin-sitemapというサイトマップを自動で作成してくれるプラグインです。 インストールしましょう。
$ yarn add gatsby-plugin-sitemap
gatsby-config.jsに設定追加
module.exports = {
siteMetadata: {
siteUrl: `https://www.example.com`, //自サイトのURL
//other settings
},
plugins: [
// other plugins
`gatsby-plugin-sitemap`,
]
除外したいページがある場合は、以下のように
plugins: [
// other plugins
{
resolve: `gatsby-plugin-sitemap`,
options: {
exclude: [`/tags/*`, `/privacy-policy`, `/archive`],
},
},
]
GoogleSearchConsoleでSitemapのURLを追加
デフォルトの設定では、 https://ドメイン/sitemap.xml
にSitemapが出力されています。
以下のようにSitemapのURLを送信して、成功すればOKです。
If you like it, share it!