Skip to content

Commit

Permalink
Exclude by filename, remove dead code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Oct 7, 2017
1 parent 9faef79 commit 793f786
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
2 changes: 0 additions & 2 deletions lib/middleware/sitemapindex.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ exports = module.exports = function() {
var sm = builder.create('sitemapindex', { version: '1.0', encoding: 'UTF-8' });
sm.a('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9')

console.log(page.site.pages)

pages = page.site.pages.filter(function(p) {
return p.sitemap == true;
});
Expand Down
22 changes: 7 additions & 15 deletions lib/middleware/urlset.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ exports = module.exports = function() {
'.html',
];

var pathExcludes = [
var fileExcludes = [
// Used by Apache to make configuration changes on a per-directory basis
// https://httpd.apache.org/docs/current/howto/htaccess.html
'/.htaccess',
'.htaccess',
// Used by GitHub Pages when setting up a custom domain
// https://help.github.com/articles/using-a-custom-domain-with-github-pages/
// https://help.github.com/articles/setting-up-a-www-subdomain/
// https://help.github.com/articles/setting-up-a-custom-subdomain/
// https://help.github.com/articles/troubleshooting-custom-domains/
'/CNAME',
'/robots.txt'
'CNAME',
'robots.txt'
];

// TODO: Implement support for image sitemaps
Expand All @@ -76,7 +76,7 @@ exports = module.exports = function() {
page.sitemap = true;

var pages = page.site.pages
, res, rext, smu, i, len;
, res, rbase, rext, smu, i, len;

var sm = builder.create('urlset', { version: '1.0', encoding: 'UTF-8' });
sm.a('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9')
Expand All @@ -88,31 +88,23 @@ exports = module.exports = function() {
if (res.sitemap || res.sitemapIndex) { continue; }

// if the resource has already been included in another sitemap, omit
//if (res.site.sitemap) { continue; }
if (res._inSitemap) { continue; }

// if the resource isn't in the same section as the sitemap, omit; unless
// the sitemap is for the entire site
//if (res.section && res.section != page.section && page.site != page.section) { continue; }

rbase = path.basename(res.url);
rext = path.extname(res.url);

if (pathExcludes.indexOf(res.url) != -1) { continue; }
if (fileExcludes.indexOf(rbase) != -1) { continue; }
if (rext && extIncludes.indexOf(rext) == -1) { continue; }

if (res.fullURL) {
smu = sm.e('url');
//smu.e('loc', uri.format(url));
smu.e('loc', res.fullURL);
if (res.modifiedAt) { smu.e('lastmod', res.modifiedAt.toISOString().substring(0,19)+'+00:00'); }

res._inSitemap = page.absoluteURL;
}
}

// Record the sitemap for this section.
//if (page.section) { page.section.sitemap = page; }

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

0 comments on commit 793f786

Please sign in to comment.