Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
gatsby-plugin-sitemap
Advanced tools
The gatsby-plugin-sitemap package is a Gatsby plugin that generates a sitemap for your Gatsby site. This helps search engines to better crawl your site and understand its structure.
Basic Sitemap Generation
This feature allows you to generate a basic sitemap for your Gatsby site. The sitemap will be output to the specified path, in this case, '/sitemap.xml'.
{
"resolve": "gatsby-plugin-sitemap",
"options": {
"output": "/sitemap.xml"
}
}
Custom Query for Sitemap
This feature allows you to customize the query used to generate the sitemap. You can specify which pages to include in the sitemap by modifying the GraphQL query.
{
"resolve": "gatsby-plugin-sitemap",
"options": {
"query": `{
site {
siteMetadata {
siteUrl
}
}
allSitePage {
nodes {
path
}
}
}`,
"output": "/sitemap.xml"
}
}
Excluding Specific Pages
This feature allows you to exclude specific pages from the sitemap. You can provide an array of paths that should not be included in the generated sitemap.
{
"resolve": "gatsby-plugin-sitemap",
"options": {
"exclude": [
"/path/to/page",
"/another/path/to/page"
],
"output": "/sitemap.xml"
}
}
Customizing Sitemap Entries
This feature allows you to customize the entries in the sitemap. You can specify additional properties like 'changefreq' and 'priority' for each URL.
{
"resolve": "gatsby-plugin-sitemap",
"options": {
"serialize": ({ site, allSitePage }) =>
allSitePage.nodes.map(node => {
return {
url: `${site.siteMetadata.siteUrl}${node.path}`,
changefreq: `daily`,
priority: 0.7,
}
}),
"output": "/sitemap.xml"
}
}
The 'sitemap' package is a general-purpose sitemap generator for Node.js. It provides more flexibility and can be used with any Node.js project, not just Gatsby. However, it requires more manual setup compared to gatsby-plugin-sitemap.
The 'next-sitemap' package is a sitemap generator specifically designed for Next.js projects. It offers similar functionalities to gatsby-plugin-sitemap but is tailored for the Next.js framework.
The 'react-router-sitemap' package generates sitemaps for React Router-based applications. It is useful for projects that use React Router for navigation, providing a way to create sitemaps based on the routes defined in the application.
Create a sitemap for your Gatsby site.
npm install --save gatsby-plugin-sitemap
// In your gatsby-config.js
siteMetadata: {
siteUrl: `https://www.example.com`,
},
plugins: [
{
resolve: `gatsby-plugin-sitemap`
}
]
Above is the minimal configuration required to have it work, however, note that
the
default query
only retrieves nodes of type MarkdownRemark
. Any parameter in defaultOptions
can be overridden.
FAQs
Gatsby plugin that automatically creates a sitemap for your site
The npm package gatsby-plugin-sitemap receives a total of 93,138 weekly downloads. As such, gatsby-plugin-sitemap popularity was classified as popular.
We found that gatsby-plugin-sitemap demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.