react-router-sitemap
react-router-sitemap copied to clipboard
changefreq, priority, img options
Hello , there's any way of adding the frequency of change for the routes, priority or image with this module?
The sitemap package does something like this:
urls: [
{ url: '/page-1/', changefreq: 'daily', priority: 0.3 },
{ url: '/page-2/', changefreq: 'monthly', priority: 0.7 },
{ url: '/page-3/'}, // changefreq: 'weekly', priority: 0.5
{ url: '/page-4/', img: "http://urlTest.com" }
]
@rafinskipg yes, it can be. But we need to think about where and how get the required values for these properties. Can add attributes to Route and parse their values in the generation. For the priority can be set depending on the nesting, but someone does not work. What do you think about it?
I think this should be handled via configuration, @kuflash , somehow like the .applyParams(paramsConfig)
, maybe the configuration that it is applied could both handle the parameters and the priority, etc.
@rafinskipg good idea
has this been implemented?
@j4mesjung no, I, unfortunately, did not have time to implement this feature. I will be grateful for the PR, if you want to implement this.
Would be super helpful!
This is my workaround for this case:
const router = require("../routes").default;
const Sitemap = require("react-router-sitemap").default;
const path = require("path");
function generateSitemap() {
var mySitemap = new Sitemap(router()).build("https://mysite.com");
for (let i = 0; i < mySitemap.sitemaps[0].urls.length; i++) {
mySitemap.sitemaps[0].urls[i].changefreq = 'daily';
mySitemap.sitemaps[0].urls[i].priority = 0.8;
}
mySitemap.save(path.basename(__dirname) + "/../sitemap.xml");
}
generateSitemap();
The generated xml contains changefreq and priority.
@annmirosh @kuflash Great workaround! 2 issues though:
1, mySitemap.sitemaps[0].urls[i].lastmod = 'no matter what is here' rendered 'NaN-NaN-NaN' or some stange number 'xxx-xxx-xxx'. This seems it does not support custom lastmod.
2, mySitemap.sitemaps[0].urls[i].changefreq = 'Always'; causes error, says unhandled promise rejection. However mySitemap.sitemaps[0].urls[i].changefreq = 'always'; works fine. It means case is sensitive and not allow to pass capitalized word.
Pass Date Object...
Example new Date()
in lastmod
.. it works ..
@edwardfxiao I managed to get the required result like that:
const date = new Date().toISOString().slice(0, 10);
for (const entry of baseSitemap.sitemaps[0].urls) {
entry.lastmod = date;
entry.changefreq = 'weekly';
entry.priority = 0.8;
}
@buddies2705 I am not sure that passing the whole date object is up to spec as specified here , in the sitemap protocol docs. It requires date format YYYY-MM-DD.
Any updates on this? It becomes a bit more complicated once you want to add image sitemaps image:image image:loc