From c0f46c5eedb6738c9a2eea7d78633f3fa4d67b58 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Mon, 13 Mar 2023 18:04:20 +0000 Subject: [PATCH] Add support for ads on best-practices --- bin/update-sponsors.cjs | 37 ++++++++-------- .../api-security/api-security.md | 42 ++++++++++++------- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/bin/update-sponsors.cjs b/bin/update-sponsors.cjs index ea8e2f9ed..2d687ee50 100644 --- a/bin/update-sponsors.cjs +++ b/bin/update-sponsors.cjs @@ -13,8 +13,8 @@ if (!apiKey || !sheetId) { const sheetRange = 'A3:I1001'; const sheetUrl = `https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/values/${sheetRange}?key=${apiKey}`; -function populateRoadmapAds({ - roadmapUrl, +function populatePageAds({ + pageUrl, company, redirectUrl, imageUrl, @@ -30,26 +30,25 @@ function populateRoadmapAds({ const isDateInRange = currentDate >= new Date(startDate) && currentDate <= new Date(endDate); const shouldShowAd = isConfiguredActive && isDateInRange; - // get id from the roadmap URL - const roadmapId = roadmapUrl - .split('/') - .pop() - .replace(/\?.+?$/, ''); + const urlPart = pageUrl.replace('https://roadmap.sh/', '').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)) { - console.error(`Roadmap file not found: ${roadmapFilePath}`); + const pageFilePath = path.join(__dirname, `../src/data/${parentDir}`, `${pageId}/${pageId}.md`); + + if (!fs.existsSync(pageFilePath)) { + console.error(`Page file not found: ${pageFilePath}`); process.exit(1); } - console.log(`Updating roadmap: ${roadmapId}`); - const roadmapFileContent = fs.readFileSync(roadmapFilePath, 'utf8'); + console.log(`Updating page: ${urlPart}`); + const pageFileContent = fs.readFileSync(pageFilePath, 'utf8'); const frontMatterRegex = /---\n([\s\S]*?)\n---/; - const existingFrontmatter = roadmapFileContent.match(frontMatterRegex)[1]; - const contentWithoutFrontmatter = roadmapFileContent.replace(frontMatterRegex, ``).trim(); + const existingFrontmatter = pageFileContent.match(frontMatterRegex)[1]; + const contentWithoutFrontmatter = pageFileContent.replace(frontMatterRegex, ``).trim(); let frontmatterObj = yaml.load(existingFrontmatter); delete frontmatterObj.sponsor; @@ -59,7 +58,7 @@ function populateRoadmapAds({ const roadmapLabel = frontmatterObj.briefTitle; // Insert sponsor data at 10 index i.e. after - // roadmap dimensions in the fronmatter + // roadmap dimensions in the frontmatter frontmatterValues.splice(10, 0, [ 'sponsor', { @@ -81,7 +80,7 @@ function populateRoadmapAds({ const newFrontmatter = yaml.dump(frontmatterObj, { lineWidth: 10000, forceQuotes: true, quotingType: '"' }); const newContent = `---\n${newFrontmatter}---\n\n${contentWithoutFrontmatter}`; - fs.writeFileSync(roadmapFilePath, newContent, 'utf8'); + fs.writeFileSync(pageFilePath, newContent, 'utf8'); } fetch(sheetUrl) @@ -92,7 +91,7 @@ fetch(sheetUrl) rows.map((row) => { // prettier-ignore const [ - roadmapUrl, + pageUrl, company, redirectUrl, imageUrl, @@ -103,8 +102,8 @@ fetch(sheetUrl) isActive, ] = row; - populateRoadmapAds({ - roadmapUrl, + populatePageAds({ + pageUrl, company, redirectUrl, imageUrl, diff --git a/src/data/best-practices/api-security/api-security.md b/src/data/best-practices/api-security/api-security.md index d772c23eb..fade3dc3b 100644 --- a/src/data/best-practices/api-security/api-security.md +++ b/src/data/best-practices/api-security/api-security.md @@ -1,27 +1,37 @@ --- -jsonUrl: '/jsons/best-practices/api-security.json' -pdfUrl: '/pdfs/best-practices/api-security.pdf' +jsonUrl: "/jsons/best-practices/api-security.json" +pdfUrl: "/pdfs/best-practices/api-security.pdf" order: 2 -briefTitle: 'API Security' -briefDescription: 'API Security Best Practices' +briefTitle: "API Security" +briefDescription: "API Security Best Practices" isNew: true isUpcoming: false -title: 'API Security Best Practices' -description: 'Detailed list of best practices to make your APIs secure' +title: "API Security Best Practices" +description: "Detailed list of best practices to make your APIs secure" dimensions: width: 968 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: - 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.' - imageUrl: 'https://roadmap.sh/best-practices/api-security.png' - datePublished: '2023-02-21' - dateModified: '2023-02-21' + 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." + imageUrl: "https://roadmap.sh/best-practices/api-security.png" + datePublished: "2023-02-21" + dateModified: "2023-02-21" seo: - 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.' + 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." keywords: - - 'API Security' - - 'API Security Best Practices' - - 'API Security Checklist' + - "API Security" + - "API Security Best Practices" + - "API Security Checklist" --- +