mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-14 21:27:59 +02:00
Add support for ads on best-practices
This commit is contained in:
@@ -13,8 +13,8 @@ if (!apiKey || !sheetId) {
|
|||||||
const sheetRange = 'A3:I1001';
|
const sheetRange = 'A3:I1001';
|
||||||
const sheetUrl = `https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/values/${sheetRange}?key=${apiKey}`;
|
const sheetUrl = `https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/values/${sheetRange}?key=${apiKey}`;
|
||||||
|
|
||||||
function populateRoadmapAds({
|
function populatePageAds({
|
||||||
roadmapUrl,
|
pageUrl,
|
||||||
company,
|
company,
|
||||||
redirectUrl,
|
redirectUrl,
|
||||||
imageUrl,
|
imageUrl,
|
||||||
@@ -30,26 +30,25 @@ function populateRoadmapAds({
|
|||||||
const isDateInRange = currentDate >= new Date(startDate) && currentDate <= new Date(endDate);
|
const isDateInRange = currentDate >= new Date(startDate) && currentDate <= new Date(endDate);
|
||||||
const shouldShowAd = isConfiguredActive && isDateInRange;
|
const shouldShowAd = isConfiguredActive && isDateInRange;
|
||||||
|
|
||||||
// get id from the roadmap URL
|
const urlPart = pageUrl.replace('https://roadmap.sh/', '').replace(/\?.+?$/, '');
|
||||||
const roadmapId = roadmapUrl
|
|
||||||
.split('/')
|
|
||||||
.pop()
|
|
||||||
.replace(/\?.+?$/, '');
|
|
||||||
|
|
||||||
const roadmapFilePath = path.join(__dirname, '../src/data/roadmaps', `${roadmapId}/${roadmapId}.md`);
|
const parentDir = urlPart.startsWith('best-practices/') ? 'best-practices' : 'roadmaps';
|
||||||
|
const pageId = urlPart.replace(`${parentDir}/`, '');
|
||||||
|
|
||||||
if (!fs.existsSync(roadmapFilePath)) {
|
const pageFilePath = path.join(__dirname, `../src/data/${parentDir}`, `${pageId}/${pageId}.md`);
|
||||||
console.error(`Roadmap file not found: ${roadmapFilePath}`);
|
|
||||||
|
if (!fs.existsSync(pageFilePath)) {
|
||||||
|
console.error(`Page file not found: ${pageFilePath}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Updating roadmap: ${roadmapId}`);
|
console.log(`Updating page: ${urlPart}`);
|
||||||
const roadmapFileContent = fs.readFileSync(roadmapFilePath, 'utf8');
|
const pageFileContent = fs.readFileSync(pageFilePath, 'utf8');
|
||||||
|
|
||||||
const frontMatterRegex = /---\n([\s\S]*?)\n---/;
|
const frontMatterRegex = /---\n([\s\S]*?)\n---/;
|
||||||
|
|
||||||
const existingFrontmatter = roadmapFileContent.match(frontMatterRegex)[1];
|
const existingFrontmatter = pageFileContent.match(frontMatterRegex)[1];
|
||||||
const contentWithoutFrontmatter = roadmapFileContent.replace(frontMatterRegex, ``).trim();
|
const contentWithoutFrontmatter = pageFileContent.replace(frontMatterRegex, ``).trim();
|
||||||
|
|
||||||
let frontmatterObj = yaml.load(existingFrontmatter);
|
let frontmatterObj = yaml.load(existingFrontmatter);
|
||||||
delete frontmatterObj.sponsor;
|
delete frontmatterObj.sponsor;
|
||||||
@@ -59,7 +58,7 @@ function populateRoadmapAds({
|
|||||||
const roadmapLabel = frontmatterObj.briefTitle;
|
const roadmapLabel = frontmatterObj.briefTitle;
|
||||||
|
|
||||||
// Insert sponsor data at 10 index i.e. after
|
// Insert sponsor data at 10 index i.e. after
|
||||||
// roadmap dimensions in the fronmatter
|
// roadmap dimensions in the frontmatter
|
||||||
frontmatterValues.splice(10, 0, [
|
frontmatterValues.splice(10, 0, [
|
||||||
'sponsor',
|
'sponsor',
|
||||||
{
|
{
|
||||||
@@ -81,7 +80,7 @@ function populateRoadmapAds({
|
|||||||
const newFrontmatter = yaml.dump(frontmatterObj, { lineWidth: 10000, forceQuotes: true, quotingType: '"' });
|
const newFrontmatter = yaml.dump(frontmatterObj, { lineWidth: 10000, forceQuotes: true, quotingType: '"' });
|
||||||
const newContent = `---\n${newFrontmatter}---\n\n${contentWithoutFrontmatter}`;
|
const newContent = `---\n${newFrontmatter}---\n\n${contentWithoutFrontmatter}`;
|
||||||
|
|
||||||
fs.writeFileSync(roadmapFilePath, newContent, 'utf8');
|
fs.writeFileSync(pageFilePath, newContent, 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(sheetUrl)
|
fetch(sheetUrl)
|
||||||
@@ -92,7 +91,7 @@ fetch(sheetUrl)
|
|||||||
rows.map((row) => {
|
rows.map((row) => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
const [
|
const [
|
||||||
roadmapUrl,
|
pageUrl,
|
||||||
company,
|
company,
|
||||||
redirectUrl,
|
redirectUrl,
|
||||||
imageUrl,
|
imageUrl,
|
||||||
@@ -103,8 +102,8 @@ fetch(sheetUrl)
|
|||||||
isActive,
|
isActive,
|
||||||
] = row;
|
] = row;
|
||||||
|
|
||||||
populateRoadmapAds({
|
populatePageAds({
|
||||||
roadmapUrl,
|
pageUrl,
|
||||||
company,
|
company,
|
||||||
redirectUrl,
|
redirectUrl,
|
||||||
imageUrl,
|
imageUrl,
|
||||||
|
@@ -1,27 +1,37 @@
|
|||||||
---
|
---
|
||||||
jsonUrl: '/jsons/best-practices/api-security.json'
|
jsonUrl: "/jsons/best-practices/api-security.json"
|
||||||
pdfUrl: '/pdfs/best-practices/api-security.pdf'
|
pdfUrl: "/pdfs/best-practices/api-security.pdf"
|
||||||
order: 2
|
order: 2
|
||||||
briefTitle: 'API Security'
|
briefTitle: "API Security"
|
||||||
briefDescription: 'API Security Best Practices'
|
briefDescription: "API Security Best Practices"
|
||||||
isNew: true
|
isNew: true
|
||||||
isUpcoming: false
|
isUpcoming: false
|
||||||
title: 'API Security Best Practices'
|
title: "API Security Best Practices"
|
||||||
description: 'Detailed list of best practices to make your APIs secure'
|
description: "Detailed list of best practices to make your APIs secure"
|
||||||
dimensions:
|
dimensions:
|
||||||
width: 968
|
width: 968
|
||||||
height: 1543.39
|
height: 1543.39
|
||||||
|
sponsor:
|
||||||
|
url: "https://www.getambassador.io/products/edge-stack-api-gateway?utm_source=roadmap-sh&utm_medium=edge-stack-page&utm_campaign=new-account"
|
||||||
|
title: "Featured Product"
|
||||||
|
imageUrl: "https://i.imgur.com/e5fdI0q.png"
|
||||||
|
description: "Get your Kubernetes API Gateway up and running in 5 minutes with Ambassador Edge Stack!"
|
||||||
|
event:
|
||||||
|
category: "SponsorClick"
|
||||||
|
action: "Ambassador Redirect"
|
||||||
|
label: "API Security / Ambassador Link"
|
||||||
schema:
|
schema:
|
||||||
headline: 'API Security Best Practices'
|
headline: "API Security Best Practices"
|
||||||
description: 'Detailed list of best practices to make your APIs secure. Each best practice carries further details and how to implement that best practice.'
|
description: "Detailed list of best practices to make your APIs secure. Each best practice carries further details and how to implement that best practice."
|
||||||
imageUrl: 'https://roadmap.sh/best-practices/api-security.png'
|
imageUrl: "https://roadmap.sh/best-practices/api-security.png"
|
||||||
datePublished: '2023-02-21'
|
datePublished: "2023-02-21"
|
||||||
dateModified: '2023-02-21'
|
dateModified: "2023-02-21"
|
||||||
seo:
|
seo:
|
||||||
title: 'API Security Best Practices'
|
title: "API Security Best Practices"
|
||||||
description: 'Detailed list of best practices to make your APIs secure. Each best practice carries further details and how to implement that best practice.'
|
description: "Detailed list of best practices to make your APIs secure. Each best practice carries further details and how to implement that best practice."
|
||||||
keywords:
|
keywords:
|
||||||
- 'API Security'
|
- "API Security"
|
||||||
- 'API Security Best Practices'
|
- "API Security Best Practices"
|
||||||
- 'API Security Checklist'
|
- "API Security Checklist"
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user