react-router-sitemap icon indicating copy to clipboard operation
react-router-sitemap copied to clipboard

changefreq, priority, img options

Open rafinskipg opened this issue 8 years ago • 11 comments

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 avatar Nov 24 '16 10:11 rafinskipg

@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?

kuflash avatar Dec 01 '16 10:12 kuflash

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 avatar Dec 01 '16 10:12 rafinskipg

@rafinskipg good idea

kuflash avatar Dec 02 '16 09:12 kuflash

has this been implemented?

j4mesjung avatar Oct 04 '17 07:10 j4mesjung

@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.

kuflash avatar Oct 04 '17 07:10 kuflash

Would be super helpful!

Hudsonzp avatar Aug 17 '19 05:08 Hudsonzp

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 avatar Sep 14 '19 14:09 annmirosh

@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.

edwardfxiao avatar Feb 13 '20 13:02 edwardfxiao

Pass Date Object...

Example new Date() in lastmod .. it works ..

buddies2705 avatar Jun 04 '20 19:06 buddies2705

@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.

Dodobrat avatar Feb 16 '22 14:02 Dodobrat

Any updates on this? It becomes a bit more complicated once you want to add image sitemaps image:image image:loc

FrancescoKashew avatar Oct 13 '23 21:10 FrancescoKashew