@@ -42,21 +42,23 @@ function updateMetricsFile(total_views) {
4242function updateMarkdownBadges ( total_views ) {
4343 const refreshDate = new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
4444 const badgeRegex = / < ! - - S T A R T B A D G E - - > [ \s \S ] * ?< ! - - E N D B A D G E - - > / g;
45-
45+
4646 const badgeBlock = `<!-- START BADGE -->
4747<div align="center">
4848 <img src="https://img.shields.io/badge/Total%20views-${ total_views } -limegreen" alt="Total views">
4949 <p>Refresh Date: ${ refreshDate } </p>
5050</div>
5151<!-- END BADGE -->` ;
5252
53- const markdownFiles = findMarkdownFiles ( '.' ) ;
53+ const markdownFiles = findMarkdownFiles ( '.' ) ; // Find all Markdown files in the directory
5454 markdownFiles . forEach ( file => {
5555 let content = fs . readFileSync ( file , 'utf-8' ) ;
56- if ( badgeRegex . test ( content ) ) {
56+ if ( badgeRegex . test ( content ) ) {
5757 const updated = content . replace ( badgeRegex , badgeBlock ) ;
5858 fs . writeFileSync ( file , updated ) ;
5959 console . log ( `Updated badge in ${ file } ` ) ;
60+ } else {
61+ console . log ( `Badge block not found in ${ file } ` ) ;
6062 }
6163 } ) ;
6264}
@@ -68,9 +70,9 @@ function findMarkdownFiles(dir) {
6870 const filePath = path . join ( dir , file ) ;
6971 const stat = fs . statSync ( filePath ) ;
7072 if ( stat && stat . isDirectory ( ) ) {
71- results = results . concat ( findMarkdownFiles ( filePath ) ) ;
73+ results = results . concat ( findMarkdownFiles ( filePath ) ) ; // Recursively search subdirectories
7274 } else if ( file . endsWith ( '.md' ) ) {
73- results . push ( filePath ) ;
75+ results . push ( filePath ) ; // Add Markdown files to the results
7476 }
7577 } ) ;
7678 return results ;
0 commit comments