1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-30 12:40:03 +02:00

Add script to update sponsors

This commit is contained in:
Kamran Ahmed
2023-03-01 02:28:46 +00:00
parent c5d14d2543
commit e57b889f73
3 changed files with 29 additions and 20 deletions

View File

@@ -51,25 +51,34 @@ function populateRoadmapAds({
const existingFrontmatter = roadmapFileContent.match(frontMatterRegex)[1];
const contentWithoutFrontmatter = roadmapFileContent.replace(frontMatterRegex, ``).trim();
const yamlObject = yaml.load(existingFrontmatter);
let fronmatterObj = yaml.load(existingFrontmatter);
if (shouldShowAd) {
yamlObject.sponsor = {
url: redirectUrl,
title: adTitle,
imageUrl,
description: adDescription,
event: {
category: 'SponsorClick',
action: `${company} Redirect`,
label: `Clicked ${company} Link`,
const frontmatterValues = Object.entries(fronmatterObj);
// Insert sponsor data at 10 index i.e. after
// roadmap dimensions in the fronmatter
frontmatterValues.splice(10, 0, [
'sponsor',
{
url: redirectUrl,
title: adTitle,
imageUrl,
description: adDescription,
event: {
category: 'SponsorClick',
action: `${company} Redirect`,
label: `Clicked ${company} Link`,
},
},
};
]);
fronmatterObj = Object.fromEntries(frontmatterValues);
} else {
delete yamlObject.sponsor;
delete fronmatterObj.sponsor;
}
const newFrontmatter = yaml.dump(yamlObject, { lineWidth: 10000, forceQuotes: true, quotingType: '"' });
const newFrontmatter = yaml.dump(fronmatterObj, { lineWidth: 10000, forceQuotes: true, quotingType: '"' });
const newContent = `---\n${newFrontmatter}---\n\n${contentWithoutFrontmatter}`;
fs.writeFileSync(roadmapFilePath, newContent, 'utf8');