mrt add sitemaps
- Create
server/sitemaps.js
which contains something like:
sitemaps.add('/sitemap.xml', function() {
// 'page' is reqired
// 'lastmod', 'changefreq', 'priority' are optional.
return [
{ page: 'x', lastmod: new Date() },
{ page: 'y', lastmod: new Date(), changefreq: 'monthly' },
{ page: 'z', lastmod: new Date().getTime(), changefreq: 'monthly', priority: 0.8 },
{ page: 'lang/english', xhtmlLinks: [
{ rel: 'alternate', hreflang: 'de', href: 'lang/deutsch' },
{ rel: 'alternate', hreflang: 'de-ch', href: 'lang/schweiz-deutsch' },
{ rel: 'alternate', hreflang: 'en', href: 'lang/english' }
]}
];
});
You can call sitemaps.add()
as many times as you like. More details on the format below.
Note that the url
is automatically added to the data served from
/robots.txt
(since 0.0.4, using the robots.txt smart package).
sitemaps.add(url, list);
The obvious example is /sitemap.xml
. You can call the function
more than once to have many different (types of) sitemaps. The URL is added
to the output of /robots.txt automatically (since 0.0.4).
Note that the location is important. A sitemap can only reference other URLs in it's own path or descendant paths. e.g. /sitemap.xml can reference all URLs on the site. /articles/sitemap.xml can only reference other pages in the /articles/ directory/path/route.
The list can either be an array in the following format, or a function that returns an array in the following format (e.g. a function that iterates over information in a Collection).
[
{
// Required. http[s]://sitename.com automatically prepended */
page: '/pageName',
// Optional. Timestamp of when the page was last modified.
lastmod: new Date(), // or new Date().getTime()
// Optional. always, hourly, daily, weekly, monthly, yearly, never
// http://www.sitemaps.org/protocol.html#changefreqdef
changefreq: 'monthly',
// Optional. http://www.sitemaps.org/protocol.html#prioritydef
priority: 0.8
// Optional. https://support.google.com/webmasters/answer/2620865
// Again, the base URL is automatically prepended to the href key
xHtmlLinks: [
{ ref: 'alternate', 'hreflang': 'en', 'href': 'en/blah' },
{ ref: 'alternate', 'hreflang': 'de', 'href': 'de/blah' }
]
}
]
Other options might come soon, e.g. to automatically use routes in your app to build the sitemap.
sitemaps.add('/mw_AllPages_sitemap.xml', function() {
var out = [], pages = WikiPages.find().fetch();
_.each(pages, function(page) {
out.push({
page: 'read/' + page.name,
lastmod: page.lastUpdated
});
});
return out;
});
You can see this output here: http://www.meteorpedia.com/mw_AllPages_sitemap.xml