@@ -13,8 +13,8 @@ if (!apiKey || !sheetId) {
1313const sheetRange = 'A3:I1001' ;
1414const 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
8786fetch ( 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,
0 commit comments