Skip to content

Commit

Permalink
refactor(exclusions): uses affirmative name for isExcluded
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmandu committed Oct 17, 2024
1 parent 5ccfa25 commit ee8887d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
14 changes: 7 additions & 7 deletions src/assets/sitemapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export default class Sitemapper {
return modified >= this.lastmod;
})
.filter((site) => {
return this.isNotExcluded(site.loc[0])
return !this.isExcluded(site.loc[0])
})
.map((site) => {
if( !this.fields) {
Expand Down Expand Up @@ -352,7 +352,7 @@ export default class Sitemapper {
const sitemap = data.sitemapindex.sitemap
.map((map) => map.loc && map.loc[0])
.filter((url) => {
return this.isNotExcluded(url)
return !this.isExcluded(url)
});

// Parse all child urls within the concurrency limit in the settings
Expand Down Expand Up @@ -456,14 +456,14 @@ export default class Sitemapper {
}

/**
* Checks if a site is not excluded based on the exclusion patterns.
* Checks if a urls is excluded based on the exclusion patterns.
*
* @param {string} url - The URL to check.
* @returns {boolean} Returns true if the urls is not excluded, false otherwise.
* @returns {boolean} Returns true if the urls is excluded, false otherwise.
*/
isNotExcluded(url) {
if (this.exclusions.length === 0) return true;
return !this.exclusions.some((pattern) => pattern.test(url));
isExcluded(url) {
if (this.exclusions.length === 0) return false;
return this.exclusions.some((pattern) => pattern.test(url));
}
}

Expand Down
40 changes: 20 additions & 20 deletions src/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,44 +301,44 @@ describe('Sitemapper', function () {
});
});

describe('isNotExcluded method', function () {
it('should return true when no exclusions are set', function () {
const result = sitemapper.isNotExcluded('https://foo.com/page1');
result.should.be.true();
describe('isExcluded method', function () {
it('should return false when no exclusions are set', function () {
const result = sitemapper.isExcluded('https://foo.com/page1');
result.should.be.false();
});

it('should return true when url does not match any exclusion patterns', function () {
it('should return false when url does not match any exclusion patterns', function () {
sitemapper.exclusions = [/\.pdf$/, /private/];
const result = sitemapper.isNotExcluded('https://foo.com/page1');
result.should.be.true();
const result = sitemapper.isExcluded('https://foo.com/page1');
result.should.be.false();
});

it('should return false when url matches an exclusion pattern', function () {
sitemapper.exclusions = [/\.pdf$/, /private/];
const result = sitemapper.isNotExcluded('https://foo.com/document.pdf');
result.should.be.false();
const result = sitemapper.isExcluded('https://foo.com/document.pdf');
result.should.be.true();
});

it('should return false when url matches any of multiple exclusion patterns', function () {
it('should return true when url matches any of multiple exclusion patterns', function () {
sitemapper.exclusions = [/\.pdf$/, /private/, /temp/];
const result = sitemapper.isNotExcluded('https://foo.com/private/temp.html');
result.should.be.false();
const result = sitemapper.isExcluded('https://foo.com/private/temp.html');
result.should.be.true();
});

it('should handle complex regex patterns correctly', function () {
sitemapper.exclusions = [/^https:\/\/foo\.com\/([a-z]{2})\/private/]
const result1 = sitemapper.isNotExcluded('https://foo.com/en/private/page');
const result2 = sitemapper.isNotExcluded('https://foo.com/en/public/page');
result1.should.be.false();
result2.should.be.true();
const result1 = sitemapper.isExcluded('https://foo.com/en/private/page');
const result2 = sitemapper.isExcluded('https://foo.com/en/public/page');
result1.should.be.true();
result2.should.be.false();
});

it('should handle case sensitivity correctly', function () {
sitemapper.exclusions = [/private/i];
const result1 = sitemapper.isNotExcluded('https://foo.com/PRIVATE/page');
const result2 = sitemapper.isNotExcluded('https://foo.com/Private/page');
result1.should.be.false();
result2.should.be.false();
const result1 = sitemapper.isExcluded('https://foo.com/PRIVATE/page');
const result2 = sitemapper.isExcluded('https://foo.com/Private/page');
result1.should.be.true();
result2.should.be.true();
});
});
});

0 comments on commit ee8887d

Please sign in to comment.