Skip to content

Commit

Permalink
Use base url setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Nov 13, 2012
1 parent 713efa9 commit 8bfc8a6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/index.js
@@ -1,17 +1,18 @@
var builder = require('xmlbuilder');
var url = require('url')
, builder = require('xmlbuilder');

// TODO: Implement support for sitemaps in directories.

// http://www.sitemaps.org/protocol.html
// http://support.google.com/webmasters/bin/answer.py?hl=en&answer=156184&topic=8476&ctx=topic

exports = module.exports = function(host) {
// strip trailing slash
if ('/' == host[host.length - 1]) {
host = host.slice(0, -1);
}
exports = module.exports = function() {

return function sitemap(site, pages) {
if (!site.get('base url')) throw new Error('sitemap requires "base url" setting');

var uri = url.parse(site.get('base url'));

site.page('/sitemap.xml', function(page, next) {
page.sitemap = true;

Expand All @@ -22,10 +23,12 @@ exports = module.exports = function(host) {
, pg;
for (var i = 0, len = paths.length; i < len; i++) {
pg = pages[paths[i]];
if (pg.sitemap || pg.path == '/robots.txt') { continue; }
if (pg.sitemap || pg.path == '/.htaccess' || pg.path == '/robots.txt') { continue; }

uri.pathname = pg.path;

sm.e('url')
.e('loc', host + pg.path);
.e('loc', url.format(uri));
}

var xml = sm.end({ pretty: true });
Expand Down

0 comments on commit 8bfc8a6

Please sign in to comment.