about summary refs log tree commit diff stats
path: root/internal/builder/builder.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/builder/builder.go')
-rw-r--r--internal/builder/builder.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/internal/builder/builder.go b/internal/builder/builder.go
index 44ab402..4f305db 100644
--- a/internal/builder/builder.go
+++ b/internal/builder/builder.go
@@ -32,30 +32,34 @@ type Result struct {
 	Hashes []string
 }
 
+var compressFiles = false
+
 func mkdirp(dirs ...string) error {
 	err := os.MkdirAll(path.Join(dirs...), 0755)
 
 	return errors.Wrap(err, "could not create directory")
 }
 
-func outputToFile(output io.Reader, filename ...string) error {
-	// log.Debug("outputting file", "filename", path.Join(filename...))
-	file, err := os.OpenFile(path.Join(filename...), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
+func outputToFile(output io.Reader, pathParts ...string) error {
+	filename := path.Join(pathParts...)
+	// log.Debug("outputting file", "filename", filename)
+	file, err := openFileAndVariants(filename)
 	if err != nil {
 		return errors.WithMessage(err, "could not open output file")
 	}
 	defer file.Close()
 
-	if _, err := file.ReadFrom(output); err != nil {
+	if _, err := io.Copy(file, output); err != nil {
 		return errors.WithMessage(err, "could not write output file")
 	}
 
 	return nil
 }
 
-func renderToFile(component templ.Component, filename ...string) error {
-	// log.Debug("outputting file", "filename", path.Join(filename...))
-	file, err := os.OpenFile(path.Join(filename...), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
+func renderToFile(component templ.Component, pathParts ...string) error {
+	filename := path.Join(pathParts...)
+	// log.Debug("outputting file", "filename", filename)
+	file, err := openFileAndVariants(filename)
 	if err != nil {
 		return errors.WithMessage(err, "could not open output file")
 	}
@@ -68,9 +72,10 @@ func renderToFile(component templ.Component, filename ...string) error {
 	return nil
 }
 
-func writerToFile(writer io.WriterTo, filename ...string) error {
+func writerToFile(writer io.WriterTo, pathParts ...string) error {
+	filename := path.Join(pathParts...)
 	// log.Debug("outputting file", "filename", path.Join(filename...))
-	file, err := os.OpenFile(path.Join(filename...), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
+	file, err := openFileAndVariants(filename)
 	if err != nil {
 		return errors.WithMessage(err, "could not open output file")
 	}
@@ -252,6 +257,7 @@ func BuildSite(ioConfig IOConfig) (*Result, error) {
 		return nil, errors.WithMessage(err, "could not get config")
 	}
 	config.InjectLiveReload = ioConfig.Development
+	compressFiles = !ioConfig.Development
 
 	if ioConfig.BaseURL.URL != nil {
 		config.BaseURL.URL, err = url.Parse(ioConfig.BaseURL.String())