@@ -104,31 +104,30 @@ pub(crate) fn pack(lc: &LeetCode<Authorized>, file: Option<std::path::PathBuf>)
104
104
. read ( true )
105
105
. write ( true )
106
106
. open ( GIT_README ) ?;
107
+ let mut write_to_root = true ;
107
108
if root_readme_file. metadata ( ) ?. len ( ) == 0 {
108
109
std:: io:: Write :: write_all ( & mut root_readme_file, "# LeetCode Solutions\n \n " . as_bytes ( ) ) ?;
109
- std:: io:: Write :: write_all (
110
- & mut root_readme_file,
111
- format ! (
112
- "- [{title}]({title}/main.{ex})\n " ,
113
- ex = code_file. language. extension( ) ,
114
- title = code_file. question_title,
115
- )
116
- . as_bytes ( ) ,
117
- ) ?;
118
110
} else {
119
111
let mut contents = String :: new ( ) ;
120
112
std:: io:: Read :: read_to_string ( & mut root_readme_file, & mut contents) ?;
121
- if !contents. contains ( & code_file. question_title ) {
122
- std:: io:: Write :: write_all (
123
- & mut root_readme_file,
124
- format ! (
125
- "- [{title}]({title}/main.{ex})\n " ,
126
- ex = code_file. language. extension( ) ,
127
- title = code_file. question_title,
128
- )
129
- . as_bytes ( ) ,
130
- ) ?;
113
+ if let Some ( i) = contents. find ( & code_file. question_title ) {
114
+ if * contents
115
+ . as_bytes ( )
116
+ . get ( i + code_file. question_title . len ( ) )
117
+ . unwrap_or ( & b'-' )
118
+ == b']'
119
+ {
120
+ // this is important as questions have variation
121
+ // like "frog-jump", "frog-jump-ii"
122
+ write_to_root = false
123
+ }
131
124
}
132
125
}
126
+ if write_to_root {
127
+ std:: io:: Write :: write_all (
128
+ & mut root_readme_file,
129
+ format ! ( "- [{title}]({title}/)\n " , title = code_file. question_title, ) . as_bytes ( ) ,
130
+ ) ?;
131
+ }
133
132
Ok ( ( ) )
134
133
}
0 commit comments