Skip to content

Commit

Permalink
feat: update S3 bucket name
Browse files Browse the repository at this point in the history
  • Loading branch information
dipratap committed Aug 29, 2024
1 parent e37fbc5 commit e6fd210
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/metatags/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export default async function auditMetaTags(message, context) {
return ok();
}
// Fetch site's scraped content from S3
const bucketName = context.env.S3_BUCKET_NAME;
const bucketName = context.env.S3_SCRAPER_BUCKET_NAME;
const prefix = `scrapes/${siteId}/`;
const scrapedObjectKeys = await getObjectKeysUsingPrefix(s3Client, bucketName, prefix);
const scrapedObjectKeys = await getObjectKeysUsingPrefix(s3Client, bucketName, prefix, log);
const extractedTags = {};
for (const key of scrapedObjectKeys) {
// eslint-disable-next-line no-await-in-loop
Expand Down
20 changes: 10 additions & 10 deletions src/metatags/seo-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,29 @@ class SeoChecks {
* Checks if tag lengths are within recommended limits
* and adds to detected tags array if found lacking.
* @param {string} url - The URL of the page.
* @param {object} tags - An object containing the tags of the page.
* @param {object} pageTags - An object containing the tags of the page.
*/
checkForTagsLength(url, tags) {
checkForTagsLength(url, pageTags) {
[TITLE, DESCRIPTION].forEach((tagName) => {
if (tags[tagName]?.length > TAG_LENGTHS[tagName].maxLength
|| tags[tagName]?.length < TAG_LENGTHS[tagName].minLength) {
if (pageTags[tagName]?.length > TAG_LENGTHS[tagName].maxLength
|| pageTags[tagName]?.length < TAG_LENGTHS[tagName].minLength) {
this.addDetectedTagEntry(
url,
tagName,
tags[tagName],
pageTags[tagName],
MODERATE,
SeoChecks.createLengthCheckText(tagName, tags[tagName]),
SeoChecks.createLengthCheckText(tagName, pageTags[tagName]),
);
}
});

if (Array.isArray(tags[H1]) && tags[H1][0]?.length > TAG_LENGTHS[H1].maxLength) {
if (Array.isArray(pageTags[H1]) && pageTags[H1][0]?.length > TAG_LENGTHS[H1].maxLength) {
this.addDetectedTagEntry(
url,
H1,
tags[H1][0],
pageTags[H1][0],
MODERATE,
SeoChecks.createLengthCheckText(H1, tags[H1][0]),
SeoChecks.createLengthCheckText(H1, pageTags[H1][0]),
);
}
}
Expand All @@ -126,7 +126,7 @@ class SeoChecks {
* @param {object} pageTags - An object containing the tags of the page.
*/
checkForH1Count(url, pageTags) {
if (pageTags[H1]?.length > 1) {
if (Array.isArray(pageTags[H1]) && pageTags[H1]?.length > 1) {
this.addDetectedTagEntry(
url,
H1,
Expand Down
1 change: 1 addition & 0 deletions src/utils/s3-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export async function getObjectKeysUsingPrefix(s3Client, bucketName, prefix, log
data?.Contents?.forEach((obj) => {
objectKeys.push(obj.Key);
});
log.info(`Fetched ${objectKeys.length} keys from S3 for bucket ${bucketName} and prefix ${prefix}`);
} catch (err) {
log.error(`Error while fetching S3 object keys using bucket ${bucketName} and prefix ${prefix}`, err);
}
Expand Down
10 changes: 6 additions & 4 deletions test/audits/metatags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('Meta Tags', () => {
log: logStub,
dataAccess: dataAccessStub,
s3Client: s3ClientStub,
env: { S3_BUCKET_NAME: 'test-bucket' },
env: { S3_SCRAPER_BUCKET_NAME: 'test-bucket' },
};
});

Expand Down Expand Up @@ -271,7 +271,9 @@ describe('Meta Tags', () => {
Body: {
tags: {
title: 'Test Page',
description: 'This is a dummy H1 that is overly length from SEO perspective',
h1: [
'This is a dummy H1 that is overly length from SEO perspective',
],
},
},
}),
Expand Down Expand Up @@ -340,7 +342,7 @@ describe('Meta Tags', () => {
],
}));
expect(addAuditStub.calledOnce).to.be.true;
expect(logStub.info.calledTwice).to.be.true;
expect(logStub.info.calledThrice).to.be.true;
});

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

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

0 comments on commit e6fd210

Please sign in to comment.