Skip to content

Commit db3ad0e

Browse files
Merge pull request #70 from kamranahmedse/master
Create a new pull request by comparing changes across two branches
2 parents 4792f7e + 42a5d5b commit db3ad0e

36 files changed

+308
-88
lines changed

.github/workflows/update-sponsors.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Update Sponsors
33
on:
44
workflow_dispatch: # allow manual run
55
schedule:
6-
- cron: '0 */3 * * *' # every 3 hours
6+
- cron: '0 0 * * *' # run daily at 00:00 UTC
77

88
env:
99
SPONSOR_SHEET_API_KEY: ${{ secrets.SPONSOR_SHEET_API_KEY }}

bin/update-sponsors.cjs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ if (!apiKey || !sheetId) {
1313
const sheetRange = 'A3:I1001';
1414
const sheetUrl = `https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/values/${sheetRange}?key=${apiKey}`;
1515

16-
function populateRoadmapAds({
17-
roadmapUrl,
16+
function populatePageAds({
17+
pageUrl,
1818
company,
1919
redirectUrl,
2020
imageUrl,
@@ -30,26 +30,25 @@ function populateRoadmapAds({
3030
const isDateInRange = currentDate >= new Date(startDate) && currentDate <= new Date(endDate);
3131
const shouldShowAd = isConfiguredActive && isDateInRange;
3232

33-
// get id from the roadmap URL
34-
const roadmapId = roadmapUrl
35-
.split('/')
36-
.pop()
37-
.replace(/\?.+?$/, '');
33+
const urlPart = pageUrl.replace('https://roadmap.sh/', '').replace(/\?.+?$/, '');
3834

39-
const roadmapFilePath = path.join(__dirname, '../src/data/roadmaps', `${roadmapId}/${roadmapId}.md`);
35+
const parentDir = urlPart.startsWith('best-practices/') ? 'best-practices' : 'roadmaps';
36+
const pageId = urlPart.replace(`${parentDir}/`, '');
4037

41-
if (!fs.existsSync(roadmapFilePath)) {
42-
console.error(`Roadmap file not found: ${roadmapFilePath}`);
38+
const pageFilePath = path.join(__dirname, `../src/data/${parentDir}`, `${pageId}/${pageId}.md`);
39+
40+
if (!fs.existsSync(pageFilePath)) {
41+
console.error(`Page file not found: ${pageFilePath}`);
4342
process.exit(1);
4443
}
4544

46-
console.log(`Updating roadmap: ${roadmapId}`);
47-
const roadmapFileContent = fs.readFileSync(roadmapFilePath, 'utf8');
45+
console.log(`Updating page: ${urlPart}`);
46+
const pageFileContent = fs.readFileSync(pageFilePath, 'utf8');
4847

4948
const frontMatterRegex = /---\n([\s\S]*?)\n---/;
5049

51-
const existingFrontmatter = roadmapFileContent.match(frontMatterRegex)[1];
52-
const contentWithoutFrontmatter = roadmapFileContent.replace(frontMatterRegex, ``).trim();
50+
const existingFrontmatter = pageFileContent.match(frontMatterRegex)[1];
51+
const contentWithoutFrontmatter = pageFileContent.replace(frontMatterRegex, ``).trim();
5352

5453
let frontmatterObj = yaml.load(existingFrontmatter);
5554
delete frontmatterObj.sponsor;
@@ -59,7 +58,7 @@ function populateRoadmapAds({
5958
const roadmapLabel = frontmatterObj.briefTitle;
6059

6160
// Insert sponsor data at 10 index i.e. after
62-
// roadmap dimensions in the fronmatter
61+
// roadmap dimensions in the frontmatter
6362
frontmatterValues.splice(10, 0, [
6463
'sponsor',
6564
{
@@ -81,7 +80,7 @@ function populateRoadmapAds({
8180
const newFrontmatter = yaml.dump(frontmatterObj, { lineWidth: 10000, forceQuotes: true, quotingType: '"' });
8281
const newContent = `---\n${newFrontmatter}---\n\n${contentWithoutFrontmatter}`;
8382

84-
fs.writeFileSync(roadmapFilePath, newContent, 'utf8');
83+
fs.writeFileSync(pageFilePath, newContent, 'utf8');
8584
}
8685

8786
fetch(sheetUrl)
@@ -92,7 +91,7 @@ fetch(sheetUrl)
9291
rows.map((row) => {
9392
// prettier-ignore
9493
const [
95-
roadmapUrl,
94+
pageUrl,
9695
company,
9796
redirectUrl,
9897
imageUrl,
@@ -103,8 +102,8 @@ fetch(sheetUrl)
103102
isActive,
104103
] = row;
105104

106-
populateRoadmapAds({
107-
roadmapUrl,
105+
populatePageAds({
106+
pageUrl,
108107
company,
109108
redirectUrl,
110109
imageUrl,

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
"test:e2e": "playwright test"
1919
},
2020
"dependencies": {
21-
"@astrojs/sitemap": "^1.1.0",
22-
"@astrojs/tailwind": "^3.0.1",
23-
"astro": "^2.0.17",
21+
"@astrojs/sitemap": "^1.2.0",
22+
"@astrojs/tailwind": "^3.1.0",
23+
"astro": "^2.1.2",
2424
"astro-compress": "^1.1.35",
2525
"node-html-parser": "^6.1.5",
26-
"npm-check-updates": "^16.7.10",
26+
"npm-check-updates": "^16.7.12",
2727
"rehype-external-links": "^2.0.1",
2828
"roadmap-renderer": "^1.0.4",
2929
"tailwindcss": "^3.2.7"

pnpm-lock.yaml

Lines changed: 62 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)