Add support for multiple ads

update-sponsors
Kamran Ahmed 2 years ago
parent 057bbddd9f
commit 504ee8cf5e
  1. 30
      bin/update-sponsors.cjs

@ -22,7 +22,7 @@ function removeAllSponsors(baseContentDir) {
const contentDir = fs.readdirSync(contentDirPath); const contentDir = fs.readdirSync(contentDirPath);
contentDir.forEach((content) => { contentDir.forEach((content) => {
console.log('Removing sponsor from: ', content); console.log('Removing sponsors from: ', content);
const pageFilePath = path.join(contentDirPath, content, `${content}.md`); const pageFilePath = path.join(contentDirPath, content, `${content}.md`);
const pageFileContent = fs.readFileSync(pageFilePath, 'utf8'); const pageFileContent = fs.readFileSync(pageFilePath, 'utf8');
@ -35,7 +35,7 @@ function removeAllSponsors(baseContentDir) {
.trim(); .trim();
let frontmatterObj = yaml.load(existingFrontmatter); let frontmatterObj = yaml.load(existingFrontmatter);
delete frontmatterObj.sponsor; delete frontmatterObj.sponsors;
const newFrontmatter = yaml.dump(frontmatterObj, { const newFrontmatter = yaml.dump(frontmatterObj, {
lineWidth: 10000, lineWidth: 10000,
@ -87,27 +87,23 @@ function addPageSponsor({
.trim(); .trim();
let frontmatterObj = yaml.load(existingFrontmatter); let frontmatterObj = yaml.load(existingFrontmatter);
delete frontmatterObj.sponsor; const sponsors = frontmatterObj.sponsors || [];
const frontmatterValues = Object.entries(frontmatterObj); const frontmatterValues = Object.entries(frontmatterObj);
const roadmapLabel = frontmatterObj.briefTitle; 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 // Insert sponsor data at 10 index i.e. after
// roadmap dimensions in the frontmatter // roadmap dimensions in the frontmatter
frontmatterValues.splice(10, 0, [ frontmatterValues.splice(10, 0, ['sponsors', sponsors]);
'sponsor',
{
url: redirectUrl,
title: adTitle,
imageUrl,
description: adDescription,
event: {
category: 'SponsorClick',
action: `${company} Redirect`,
label: `${roadmapLabel} / ${company} Link`,
},
},
]);
frontmatterObj = Object.fromEntries(frontmatterValues); frontmatterObj = Object.fromEntries(frontmatterValues);

Loading…
Cancel
Save