diff options
author | Alan Pearce | 2024-06-23 17:37:10 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-23 19:23:20 +0200 |
commit | 8cca5de5d0cd6b18c328a18de286eeb3b2c75b84 (patch) | |
tree | 2fdf48a815e81d8b6382e3dd9b3bdf6825d5606a /internal/builder/files.go | |
parent | fe4a23b550b7450e6e24cd3c78dfd575122d361d (diff) | |
download | website-8cca5de5d0cd6b18c328a18de286eeb3b2c75b84.tar.lz website-8cca5de5d0cd6b18c328a18de286eeb3b2c75b84.tar.zst website-8cca5de5d0cd6b18c328a18de286eeb3b2c75b84.zip |
pre-compress static files
Diffstat (limited to 'internal/builder/files.go')
-rw-r--r-- | internal/builder/files.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/builder/files.go b/internal/builder/files.go index 57d4d2e..20fedf9 100644 --- a/internal/builder/files.go +++ b/internal/builder/files.go @@ -3,7 +3,9 @@ package builder import ( "compress/gzip" "io" + "io/fs" "os" + "path/filepath" "github.com/andybalholm/brotli" ) @@ -81,3 +83,30 @@ func openFileAndVariants(filename string) (io.WriteCloser, error) { return openFileWrite(filename) } } + +func copyRecursive(src, dst string) error { + return filepath.WalkDir(src, func(path string, d fs.DirEntry, err error) error { + rel, err := filepath.Rel(src, path) + if err != nil { + return err + } + if d.IsDir() { + return mkdirp(dst, rel) + } else { + sf, err := os.Open(path) + if err != nil { + return err + } + defer sf.Close() + df, err := openFileAndVariants(filepath.Join(dst, rel)) + if err != nil { + return err + } + defer df.Close() + if _, err := io.Copy(df, sf); err != nil { + return err + } + } + return nil + }) +} |