Skip to content

Commit

Permalink
Add support for multiple ads
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranahmedse committed May 2, 2023
1 parent 057bbdd commit 504ee8c
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions bin/update-sponsors.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function removeAllSponsors(baseContentDir) {

const contentDir = fs.readdirSync(contentDirPath);
contentDir.forEach((content) => {
console.log('Removing sponsor from: ', content);
console.log('Removing sponsors from: ', content);

const pageFilePath = path.join(contentDirPath, content, `${content}.md`);
const pageFileContent = fs.readFileSync(pageFilePath, 'utf8');
Expand All @@ -35,7 +35,7 @@ function removeAllSponsors(baseContentDir) {
.trim();

let frontmatterObj = yaml.load(existingFrontmatter);
delete frontmatterObj.sponsor;
delete frontmatterObj.sponsors;

const newFrontmatter = yaml.dump(frontmatterObj, {
lineWidth: 10000,
Expand Down Expand Up @@ -87,27 +87,23 @@ function addPageSponsor({
.trim();

let frontmatterObj = yaml.load(existingFrontmatter);
delete frontmatterObj.sponsor;
const sponsors = frontmatterObj.sponsors || [];

const frontmatterValues = Object.entries(frontmatterObj);
const roadmapLabel = frontmatterObj.briefTitle;

sponsors.push({
url: redirectUrl,
title: adTitle,
imageUrl,
description: adDescription,
page: roadmapLabel,
company,
});

// Insert sponsor data at 10 index i.e. after
// roadmap dimensions in the frontmatter
frontmatterValues.splice(10, 0, [
'sponsor',
{
url: redirectUrl,
title: adTitle,
imageUrl,
description: adDescription,
event: {
category: 'SponsorClick',
action: `${company} Redirect`,
label: `${roadmapLabel} / ${company} Link`,
},
},
]);
frontmatterValues.splice(10, 0, ['sponsors', sponsors]);

frontmatterObj = Object.fromEntries(frontmatterValues);

Expand Down

0 comments on commit 504ee8c

Please sign in to comment.