@@ -49,8 +49,11 @@ function generateMarkdown(obj) {
49
49
// Clear and recreate the level folder
50
50
const levelsFolder = path . resolve ( __dirname , `${ repo } /level` ) ;
51
51
clearFolder ( levelsFolder ) ;
52
+
53
+ const uniqueLevels = new Set ( ) ;
52
54
data . forEach ( obj => {
53
55
if ( obj . level ) {
56
+ uniqueLevels . add ( obj . level ) ;
54
57
const levelFolderPath = path . join ( levelsFolder , obj . level ) ;
55
58
const content = generateMarkdown ( obj ) ;
56
59
writeToFile ( levelFolderPath , `${ obj . title . replace ( / [ ^ a - z 0 - 9 ] + / gi, '_' ) } .md` , content ) ;
@@ -60,10 +63,13 @@ data.forEach(obj => {
60
63
// Clear and recreate the theme folder
61
64
const themesFolder = path . resolve ( __dirname , `${ repo } /theme` ) ;
62
65
clearFolder ( themesFolder ) ;
66
+
67
+ const uniqueThemes = new Set ( ) ;
63
68
data . forEach ( obj => {
64
69
if ( obj . theme ) {
65
70
const themes = obj . theme . split ( ',' ) . map ( theme => theme . trim ( ) ) ;
66
71
themes . forEach ( theme => {
72
+ uniqueThemes . add ( theme ) ;
67
73
const themeFolderPath = path . join ( themesFolder , theme ) ;
68
74
const content = generateMarkdown ( obj ) ;
69
75
writeToFile ( themeFolderPath , `${ obj . title . replace ( / [ ^ a - z 0 - 9 ] + / gi, '_' ) } .md` , content ) ;
@@ -74,18 +80,58 @@ data.forEach(obj => {
74
80
// Clear and recreate the video folder
75
81
const videoFolder = path . resolve ( __dirname , `${ repo } /video` ) ;
76
82
clearFolder ( videoFolder ) ;
83
+
84
+ const videoQuestions = [ ] ;
77
85
data . forEach ( obj => {
78
86
if ( obj . url && obj . url . includes ( 'tiktok' ) ) {
87
+ videoQuestions . push ( obj ) ;
79
88
const content = generateMarkdown ( obj ) ;
80
89
writeToFile ( videoFolder , `${ obj . title . replace ( / [ ^ a - z 0 - 9 ] + / gi, '_' ) } .md` , content ) ;
81
90
}
82
91
} ) ;
83
92
84
- // Save the Markdown content to a README.md file
85
- const outputFilePath = path . resolve ( __dirname , './repo/README.md' ) ;
93
+ // Generate the README header
94
+ const totalQuestions = data . length ;
95
+ const levelsLinks = Array . from ( uniqueLevels )
96
+ . map ( level => `- [${ level } ](./level/${ level } )` )
97
+ . join ( '\n' ) ;
98
+ const themesLinks = Array . from ( uniqueThemes )
99
+ . map ( theme => `- [${ theme } ](./theme/${ theme } )` )
100
+ . join ( '\n' ) ;
101
+ const videosLinks = videoQuestions
102
+ . map ( q => `- [${ q . title } ](${ q . url } )` )
103
+ . join ( '\n' ) ;
104
+
105
+ // Convert the array of objects to Markdown format
106
+ const markdownContent = data . map ( obj => {
107
+ const titleWithLink = obj . link ? `[${ obj . title } ](${ obj . link } )` : obj . title ;
108
+ const tags = obj . level && obj . theme ? `**Tags**: ${ obj . level } , ${ obj . theme } ` : '' ;
109
+ const url = obj . url ? `**URL**: [${ obj . url } ](${ obj . url } )` : '' ;
110
+ return `## ${ titleWithLink } \n\n${ obj . text } \n\n${ tags } \n\n${ url } \n` ;
111
+ } ) . join ( '\n---\n\n' ) ;
112
+
113
+ const readmeContent = `
114
+ # javascript-questions-pro (${ totalQuestions } questions)
115
+
116
+ ## [Levels](./level/)
117
+ ${ levelsLinks }
118
+
119
+ ## [Themes](./theme/)
120
+ ${ themesLinks }
121
+
122
+ ## [Tutorials with Videos](./video/)
123
+ ${ videosLinks }
124
+
125
+ ## All questions
126
+ ${ markdownContent }
127
+ ---
128
+ ` ;
129
+
130
+ // Write the README header and questions
131
+ const outputFilePath = path . resolve ( __dirname , `${ repo } /README.md` ) ;
86
132
try {
87
- fs . writeFileSync ( outputFilePath , generateMarkdown , 'utf8' ) ;
88
- console . log ( `Markdown file has been saved to ${ outputFilePath } ` ) ;
133
+ fs . writeFileSync ( outputFilePath , readmeContent , 'utf8' ) ;
134
+ console . log ( `README file has been saved to ${ outputFilePath } ` ) ;
89
135
} catch ( err ) {
90
136
console . error ( `Failed to write to file at ${ outputFilePath } :` , err . message ) ;
91
137
process . exit ( 1 ) ;
0 commit comments