next-with-sitemap v2.5.2
next-with-sitemap
Higher order Next.js config to generate sitemap.xml and robots.txt.
Read more at Medium.
Heavily inspired from IlusionDev/nextjs-sitemap-generator.
Install
yarn add next-with-sitemapBasic Usage
Update or create next.config.js with
const withSitemap = require("next-with-sitemap");
module.exports = withSitemap({
sitemap: {
baseUrl: "https://www.example.com",
},
// .
// ..
// ... other Next.js config
});Add sitemap.xml and robots.txt to your .gitignore
robots.txt
sitemap.xmlConfiguration
There are options you can use to customize the behavior of this plugin
by adding sitemap object in the Next.js config in next.config.js.
Alongside those given sitemap options, this library would also rely
on your Next.js config values exportPathMap,
exportTrailingSlash,
and pageExtensions
to come up with the correct sitemap.xml content.
const withSitemap = require("next-with-sitemap");
module.exports = withSitemap({
sitemap: {
baseUrl: "https://www.example.com",
alternateBaseUrls: [
{
lang: "jp",
url: "https://example.jp",
},
{
lang: "es",
url: "https://example.com/es",
},
],
dest: "public",
excludedPaths: ["/login", "/signup"],
extraPaths: ["/extra/path"],
pages: "pages",
pageTags: [
{
path: "/",
priority: 1.0,
},
{
path: "/extra/path",
changefreq: "monthly",
},
{
path: "/about",
changefreq: "weekly",
priority: 0.5,
},
],
robots: true,
sitemap: true,
},
});Available Options
- baseUrl: string (required) - the baseUrl name including protocol and subdomain (e.g.
https://www.example.com). - alternateBaseUrls: array - an array of alternative base urls for given languages.
- defaults to
[]. - for each object in array:
- set
lang(required) to the language identifier, - set
url(required) to the base url that should be used for thatlang.
- set
- defaults to
- dest: string - the destination folder to put generated files, relative to the project root.
- defaults to
public.
- defaults to
- excludedPaths: array - an array of paths that should be excluded from the sitemap.
- defaults to
[].
- defaults to
- extraPaths: array - an array of extra paths that cannot be found at
pagesfolder and that should be included to the sitemap.- defaults to
[].
- defaults to
- pages: string - the folder that contains page files, relative to the project root.
- defaults to
pages.
- defaults to
- pageTags: array - an array of additional tags for any given path.
- defaults to
[]. - for each object in array:
- set
path(required) to the relative path of the page, - set
changefreqto one ofalways,hourly,daily,weekly,monthly,yearly,nevervalues, - set
priorityto a number value between0and1(inclusive).
- set
- defaults to
- robots: boolean - whether to enable
robots.txtgeneration.- defaults to
true, - set
robots: false, so it won't generate arobots.txt, - set
robots: trueto generate arobots.txt.
- defaults to
- sitemap: boolean - whether to enable
sitemap.xmlgeneration.- defaults to
true, - set
sitemap: false, so it won't generate asitemap.xml, - set
sitemap: trueto generate asitemap.xml.
- defaults to
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago