A react static pro plugin for exporting sitemap information
npm install react-static-pro-plugin-sitemapA [React-Static] plugin for exporting sitemap information.
In an existing react-static site run:
``bash`
$ yarn add react-static-pro-plugin-sitemap
Then add the plugin to your static.config.js:
`javascript`
export default {
plugins: ['react-static-pro-plugin-sitemap'],
}
- A config.siteRoot is required for this plugin to work properly, since sitemap's are required to use full
- Each route in your site will createt a item in the sitemap
- By default, the url's tag will be set to the prefixed path of each route.sitemap
- All property/value pairs under a route's object will be used as xml tags for that route, eg.
`javascripthttps://raw.githubusercontent.com/react-static/react-static/master/media/react-static-logo-2x.png
export default {
siteRoot: 'https://hello.com'
}
const routes = [
{
path: '/blog/post/1',
sitemap: {
hreflang: [
{language:'x-default', url: '/blog/post/1'},
{language:'en', url: '/blog/post/1'},
{language:'de-DE', url: '/de/blog/post/1'},
],
lastmod: '10/10/2010',
priority: 0.5,
'image:image': {
'image:loc': ,`
'image:caption': 'React Static',
},
},
},
{
path: '/blog/draft/2',
sitemap: {
noindex: true // Excludes route from sitemap.xml
},
},
]
Would result in the following XML:
`xml`
`javascript
export default {
plugins: [
[
'react-static-pro-plugin-sitemap',
{
getAttributes: route => ({
customXmlAttribute: route.customProperty,
}),
// Given a route where route.customProperty === 40,
// This would create a
// in that routes
},
],
],
}
``