Skip to content

Commit

Permalink
feat: changes for reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
dipratap committed Sep 12, 2024
1 parent fc6a230 commit 5ff695d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"all": true,
"include": [
"src/**/*.js"
],
"exclude": [
"src/metatags/*.js"
]
}
3 changes: 3 additions & 0 deletions src/metatags/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const H1 = 'h1';
export const HIGH = 'High';
export const MODERATE = 'Moderate';

// Audit result constants
export const NON_UNIQUE = 'non-unique';

// Tags lengths
export const TAG_LENGTHS = {
[TITLE]: {
Expand Down
1 change: 0 additions & 1 deletion src/metatags/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async function fetchAndProcessPageObject(s3Client, bucketName, key, prefix, log)
return null;
}
const pageUrl = key.slice(prefix.length - 1).replace('scrape.json', ''); // Remove the prefix and .json suffix
log.info(`Scraped tags for ${pageUrl} : ${JSON.stringify(object.scrapeResult.tags)}`);
return {
[pageUrl]: {
title: object.scrapeResult.tags.title,
Expand Down
19 changes: 15 additions & 4 deletions src/metatags/seo-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
H1,
TAG_LENGTHS,
HIGH,
MODERATE,
MODERATE, NON_UNIQUE,
} from './constants.js';

class SeoChecks {
Expand Down Expand Up @@ -146,9 +146,10 @@ class SeoChecks {
const tags = {
[TITLE]: pageTags[TITLE],
[DESCRIPTION]: pageTags[DESCRIPTION],
[H1]: Array.isArray(pageTags[H1]) ? pageTags[H1][0] : '',
[H1]: Array.isArray(pageTags[H1]) ? pageTags[H1] : [],
};
Object.entries(tags).forEach(([tagName, tagContent = '']) => {
[TITLE, DESCRIPTION].forEach((tagName) => {
const tagContent = tags[tagName];
if (tagContent && this.allTags[tagName][tagContent.toLowerCase()]) {
this.addDetectedTagEntry(
url,
Expand All @@ -159,7 +160,17 @@ class SeoChecks {
+ `It's recommended to have unique ${tagName} tags for each page.`,
);
}
this.allTags[tagName][tagContent.toLowerCase()] = url;
this.allTags[tagName][tagContent?.toLowerCase()] = url;
});
tags[H1].forEach((tag) => {
this.allTags[H1][tag] ??= { count: 0, urls: [] };
this.allTags[H1][tag].urls.push(url);
this.allTags[H1][tag].count += 1;

if (this.allTags[H1][tag].count > 1) {
this.detectedTags[H1][NON_UNIQUE] ??= {};
this.detectedTags[H1][NON_UNIQUE][tag] = { ...this.allTags[H1][tag] };
}
});
}

Expand Down
4 changes: 2 additions & 2 deletions test/audits/metatags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ describe('Meta Tags', () => {
],
}));
expect(addAuditStub.calledOnce).to.be.true;
expect(logStub.info.callCount).to.equal(6);
expect(logStub.info.callCount).to.equal(4);
});

it('should process site tags and perform SEO checks for pages with invalid H1s', async () => {
Expand Down Expand Up @@ -454,7 +454,7 @@ describe('Meta Tags', () => {
],
}));
expect(addAuditStub.calledOnce).to.be.true;
expect(logStub.info.callCount).to.equal(6);
expect(logStub.info.callCount).to.equal(4);
});

it('should handle errors and return internalServerError', async () => {
Expand Down

0 comments on commit 5ff695d

Please sign in to comment.