@@ -24,36 +24,27 @@ import (
2424//
2525//////////////////////////////////////////////////////////////////////////////
2626
27- // CopyDirectoryImages is a shortcut for copying over all non-md files into the /public/images/<identifier>/.
28- func CopyDirectoryImages (c * modulir.Context , source , target string ) error {
29- dirs , err := ReadDirWithOptions (c , source , & ReadDirOptions {ShowDirs : true })
30- if err != nil {
27+ // CopyDirectory copies all files from source directory directly to target directory (non-recursive).
28+ // This is useful for copying static assets like images without subdirectory structure.
29+ func CopyDirectory (c * modulir.Context , source , target string ) error {
30+ // Ensure target directory exists
31+ if err := EnsureDir (c , target ); err != nil {
3132 return err
3233 }
3334
34- for _ , dir := range dirs {
35- // Read the files from that dir ignoring *.md
36- files , err := ReadDirWithOptions (c , dir , & ReadDirOptions {IgnoreMDs : true })
37- if err != nil {
38- return err
39- }
40-
41- // Make new target directory path
42- justNameOfDir := filepath .Base (dir )
43- targetDir := filepath .Join (target , justNameOfDir )
35+ // Read files from source directory (ignoring subdirectories by default)
36+ files , err := ReadDirWithOptions (c , source , & ReadDirOptions {IgnoreMDs : true })
37+ if err != nil {
38+ return err
39+ }
4440
45- // Ensure target directory exists
46- if err = EnsureDir (c , targetDir ); err != nil {
41+ // Copy all files to target directory
42+ for _ , file := range files {
43+ if err = CopyFileToDir (c , file , target ); err != nil {
4744 return err
4845 }
49-
50- // Copy all files into there
51- for _ , file := range files {
52- if err = CopyFileToDir (c , file , targetDir ); err != nil {
53- return err
54- }
55- }
5646 }
47+
5748 return nil
5849}
5950
@@ -204,20 +195,6 @@ func MustAbs(path string) string {
204195 return absPath
205196}
206197
207- //
208- // ReadDir
209- //
210-
211- // ReadDir reads files in a directory and returns a list of file paths.
212- //
213- // Unlike os.ReadDir, this function skips hidden, "meta" (i.e. prefixed by
214- // an underscore), and Vim backup (i.e. suffixed with a tilde) files, and
215- // returns a list of full paths (easier to plumb into other functions), and
216- // sets up a watch on the listed source.
217- func ReadDir (c * modulir.Context , source string ) ([]string , error ) {
218- return ReadDirWithOptions (c , source , nil )
219- }
220-
221198// ReadDirOptions are options for ReadDirWithOptions.
222199type ReadDirOptions struct {
223200 // RecurseDir tells the function to recurse into subdirectories.
0 commit comments