Skip to content

Commit

Permalink
version bump, add ignore option for routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Plum committed Jun 3, 2015
1 parent 908ffb3 commit 3d00bcf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ Note that the keystone admin application routes (/keystone/*) will not be part o
## Additional options
The sitemap create function accepts an optional options object parameter, which can be used to include additional information about your route structure.

### Hide route
To ignore a route completely from the sitemap, declare the route string in the `ignore` array in the same way as you declared the route string within your site routes.

```
app.get('/sitemap.xml', function(req, res) {
sitemap.create(keystone, req, res, {
ignore: ['/secret/:id']
});
});
```

If you want to ignore multiple routes with a common pattern, you can pass the regular expression that matches that pattern.

```
app.get('/sitemap.xml', function(req, res) {
sitemap.create(keystone, req, res, {
ignore: ['^\/api.*$']
});
});
```

### Hidden page filter
Some Keystone models may include a boolean to show/hide or publish/unpublish a specific piece of content tied to a model. You can use the `filters` option to declare the model name and the filter condition that should be applied to the routes that use that model to exclude any pages that are not shown/published from the sitemap file.

Expand Down
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ var KeystoneSitemap = function(keystone, req, res) {

// remove any kestyone admin paths (/keystone/)
if (path != null && path.match(/keystone\*{0,1}$|keystone\/|\/\*$|sitemap\.xml/) == null) {
var ignored = false;

//check routes against the ignored routes, if applicable
if (options && options.ignore && Object.prototype.toString.call(options.ignore) === '[object Array]') {
for (var ig in options.ignore) {
if (path === options.ignore[ig] || path.match(options.ignore[ig]) !== null) {
ignored = true;
break;
}
};
}

if (ignored) {
return false;
}

// check for dynamic routes (with parameters identified by :[parameter name])
if (path.indexOf(':') > 0) {
dynamicRoutes.push(path);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "keystone-express-sitemap",
"version": "1.1.0",
"version": "1.2.0",
"description": "Dynamic sitemap generation for applications built on KeystoneJS",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 3d00bcf

Please sign in to comment.