02 Jan 2022
Automating Sitemap Workflow
Sahil KokamkarGenerating sitemap
To generate sitemap first add the @netlify/plugin-sitemap
as Dev dependency in package.json using npm, yarn, pnpm or any other package node package manager of your choice.
npm install @netlify/plugin-sitemap --save-dev-dev
Configuring the plugin.
To configure the plugin, edit the netlify.toml
file.
[[plugins]]
package = "@netlify/plugin-sitemap"
[plugins.inputs]
buildDir = "dist/"
exclude = [
# To exclude the path from the sitemap
'**/admin/*'
]
This will generate sitemap at /sitemap.xml
on every production build.To check more about configuration, you can check their official documentation.
Submitting sitemap
Now after we have sitemap we can automate its submission, first we have to install netlify-plugin-submit-sitemap
as Dev Dependency.
npm install @netlify-plugin-submit-sitemap --save-dev-dev
Configuring the plugin
Now in the same netlify.toml
file, add the following.
[build]
publish = "public"
[[plugins]]
package = "netlify-plugin-submit-sitemap"
[plugins.inputs]
# The base url of your site
baseUrl = "https://yoursite.tld"
# Path to the sitemap
sitemapPath = "YourPath/sitemap.xml"
# Submitting sitemap to search engines. You can also remove those you don't what to submit
providers = [
"google",
"bing",
"yandex"
]
This will ping the search engines everytime after a new build using ping?sitemap=
.
You can also refer to their official documentation.