@@ -72,11 +72,14 @@ func addMeta(tagMetas TagMetas, meta *Meta) {
72
72
73
73
func findTag (content []byte , r * regexp.Regexp ) string {
74
74
res := r .FindSubmatch (content )
75
+ if len (res ) < 2 {
76
+ return ""
77
+ }
75
78
return string (res [1 ])
76
79
}
77
80
78
81
func findMeta (content []byte , fp string ) * Meta {
79
- draft := findTag (content , draftRegex ) == "true"
82
+ draft := findTag (content , draftRegex ) == "" || findTag ( content , draftRegex ) == " true"
80
83
if draft {
81
84
return nil
82
85
}
@@ -104,8 +107,16 @@ func fileExists(path string) bool {
104
107
return ! os .IsNotExist (err )
105
108
}
106
109
110
+ func isDirectory (path string ) (bool , error ) {
111
+ fileInfo , err := os .Stat (path )
112
+ if err != nil {
113
+ return false , err
114
+ }
115
+ return fileInfo .IsDir (), err
116
+ }
117
+
107
118
func Run () {
108
- files , err := doublestar .Glob ("./solve/**/**.go " )
119
+ files , err := doublestar .Glob ("./solve/**/*" )
109
120
if err != nil {
110
121
log .Fatal (err )
111
122
}
@@ -114,7 +125,11 @@ func Run() {
114
125
wg := sync.WaitGroup {}
115
126
var lock sync.Mutex
116
127
for _ , fp := range files {
117
- if strings .HasSuffix (fp , "test.go" ) || ! strings .HasSuffix (fp , ".go" ) {
128
+ if isFolder , _ := isDirectory (fp ); isFolder {
129
+ continue
130
+ }
131
+
132
+ if strings .HasSuffix (fp , ".md" ) {
118
133
continue
119
134
}
120
135
wg .Add (1 )
@@ -125,9 +140,11 @@ func Run() {
125
140
log .Fatal (err )
126
141
}
127
142
meta := findMeta (content , fp )
128
- lock .Lock ()
129
- addMeta (tagMetas , meta )
130
- lock .Unlock ()
143
+ if meta != nil {
144
+ lock .Lock ()
145
+ addMeta (tagMetas , meta )
146
+ lock .Unlock ()
147
+ }
131
148
wg .Done ()
132
149
}()
133
150
}
0 commit comments