Options for static routes

delucis
8
delucis
commented 2 years ago

Hi, thanks for your work on this module!

When passing dynamic routes, setting extra options is possible, e.g.

routes: [
  { url: '/dynamic/1', changefreq: 'daily', priority: 1 /* etc. */ }
]

But for “static” routes, there doesn’t seem to be any way to pass such options.

If I add a static route to the routes option, it gets duplicated because static and dynamic routes are merged using lodash’s union(). It ends up comparing, e.g. '/route' with { url: '/route', changefreq: 'daily' }, which aren’t equal so both are included.

Is there a solution? If not, perhaps the following might make sense:

  1. Improve the merge strategy in the createCache() method to avoid such duplicates. This would allow overriding static routes by adding them to the routes option.

  2. Allow for a default set of route options to be set, which are applied to static routes (or all routes?)

// maybe something like this?
sitemap: {
  routeDefaults: {
    changefreq: 'daily'
  },
  routes: [ '/foo', '/bar' ]
}
// would be equivalent to, with routeDefaults also applying to static routes
sitemap: {
  routes: [
    { url: '/foo', changefreq: 'daily' },
    { url: '/bar', changefreq: 'daily' }
  ]
}

Any thoughts? I might have misread index.js, so maybe another solution would be better. Would be happy to work on a solution if there’s interest.

idea
0
Informations
Feature RequestOpen
#c10 - Created 2 years ago