77 "io"
88 "io/fs"
99 "log"
10+ "path"
1011 "path/filepath"
1112 "strings"
1213)
@@ -24,6 +25,11 @@ func (f FilePath) Join(paths ...string) FilePath {
2425 return FilePath (filepath .Join (paths ... ))
2526}
2627
28+ func (f FilePath ) JoinEmbed (paths ... string ) FilePath {
29+ paths = append ([]string {string (f )}, paths ... )
30+ return FilePath (path .Join (paths ... ))
31+ }
32+
2733type RegExp string
2834
2935type TemplateExpression string
@@ -61,41 +67,37 @@ func GetFiles(filesystem embed.FS, params GetFilesParams) []File {
6167 if params .IsNotRecursive {
6268 continue
6369 }
64- params .relFolder = params .relFolder .Join (f .Name ())
65- params .RootFolder = params .RootFolder .Join (f .Name ())
66- result = append (result ,
67- GetFiles (filesystem , params )... ,
68- )
70+ params .relFolder = params .relFolder .JoinEmbed (f .Name ())
71+ params .RootFolder = params .RootFolder .JoinEmbed (f .Name ())
72+ result = append (result , GetFiles (filesystem , params )... )
6973 } else {
7074 splitted := strings .Split (f .Name (), "." )
7175 var extension string
7276 if len (splitted ) > 0 {
7377 extension = splitted [len (splitted )- 1 ]
7478 }
7579
76- path := params .RootFolder .Join (f .Name ())
77- requested := strings .ReplaceAll (path .ToString (), "\\ " , "/" ) // fix for windows
80+ requested := params .RootFolder .JoinEmbed (f .Name ()).ToString ()
7881 content , err := filesystem .ReadFile (requested )
7982 if err != nil {
8083 PrintFilesForDebug (filesystem )
81- fmt .Println (err .Error (), "failed to read file from embeded fs of" ,
82- "path=" , path ,
83- "requested" , requested ,
84+ fmt .Println (err .Error (), "failed to read file from embedded fs" ,
85+ "requested=" , requested ,
8486 )
8587 }
8688
87- is_allowed_extension := false
88- for _ , allowed_extension := range params .AllowedExtensions {
89- if allowed_extension == extension {
90- is_allowed_extension = true
89+ isAllowedExtension := false
90+ for _ , allowed := range params .AllowedExtensions {
91+ if allowed == extension {
92+ isAllowedExtension = true
9193 }
9294 }
93- if ! is_allowed_extension {
95+ if ! isAllowedExtension {
9496 continue
9597 }
9698
9799 result = append (result , File {
98- Relpath : params .relFolder .Join (f .Name ()),
100+ Relpath : params .relFolder .JoinEmbed (f .Name ()),
99101 Name : f .Name (),
100102 Extension : extension ,
101103 Content : string (content ),
0 commit comments