GenomeUS / keystone-express-sitemap

Dynamic sitemap generation for applications built on KeystoneJS
19 stars 15 forks source link

Ignore a specific route for a set of dynamic paths #3

Closed raduchiriac closed 8 years ago

raduchiriac commented 8 years ago

(Probably not an issue but) I am trying to ignore one specific route from a set of others. I am using:

app.get('/artist/:name', routes.views.artist);

I want to ignore artist/admin and I have tried this below but did succeeded

...
ignore: ['^.(\bartist/admin\b)?.$']
...
s-plum commented 8 years ago

Have you tried one of the following:

ignore: ['/artist/admin']

or

ignore: ['^.(\bartist\/admin\b)?$']
raduchiriac commented 8 years ago

Nope they don't. The problem is that at line 61 you are checking the pure dynamic routes with that regex, which does a match between:

"/artist/:name".match('artist/admin');

This will never match. You should do the ignore test inside the addListRoutes() too.

If you tell me how to go about, I could start writing a PR

s-plum commented 8 years ago

In the case you are trying to solve for, is "admin" the name of one of the artists you have stored in Keystone, or is it a custom route that you have declared separately? If it is the name of an artist, you might be able to use the filters option like so:

app.get('/sitemap.xml', function(req, res) {
    sitemap.create(keystone, req, res, {
        filters: {
            'Artist': function(artist) {
                return artist.name.toLowerCase() !== 'admin';
            }
        }
    });
});

If not, let me know how the artists/admin route is being generated and I will look into adding a filter in the addListRoutes function.

raduchiriac commented 8 years ago

That is exactly it, filters are great. Thank you!