README
keystone-express-sitemap
Dynamic sitemap generation for applications built on KeystoneJS
Introduction
keystone-sitemap allows you to set up your KeystoneJS app to return a dynamic sitemap.xml file that is aware of all database-driven content within your site.
For example, this set of routes in routes/index.js:
app.get('/', routes.views.index);
app.get('/recipe/:_id', routes.views.recipe);
app.get('/order', routes.views.order);
will be parsed into:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://mysite.com/</loc>
</url>
<url>
<loc>http://mysite.com/recipe/1214</loc>
<lastmod>2015-03-03</lastmod>
</url>
<url>
<loc>http://mysite.com/recipe/8183</loc>
<lastmod>2014-04-01</lastmod>
</url>
<url>
<loc>http://mysite.com/recipe/6685</loc>
<lastmod>2015-04-03</lastmod>
</url>
<url>
<loc>http://mysite.com/order</loc>
</url>
</urlset>
Note that the keystone admin application routes (/keystone/*) will not be part of the sitemap. An option to choose whether or not to include these routes may be included in a later version. If you're impatient, feel free to fork me and set it up yourself.
Installation
Install the package and save it with the rest of your site dependencies
npm install keystone-express-sitemap --saveAdd the sitemap.xml route to the rest of your site routes
routes/index.js
var keystone = require('keystone'), sitemap = require('keystone-express-sitemap'); // other middleware/dependencies go here exports = module.exports = function(app) { app.get('/sitemap.xml', function(req, res) { sitemap.create(keystone, req, res); }); // other application routes go here }Go to sitemap.xml on your domain and watch the SEO magic fairy dust sprinkle itself magically over your site.
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.*