diff options
Diffstat (limited to 'internal/storage/files/writer.go')
-rw-r--r-- | internal/storage/files/writer.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/internal/storage/files/writer.go b/internal/storage/files/writer.go index 9831435..f0fe6a9 100644 --- a/internal/storage/files/writer.go +++ b/internal/storage/files/writer.go @@ -7,6 +7,7 @@ import ( "io/fs" "os" "path/filepath" + "strings" "go.alanpearce.eu/x/log" @@ -70,11 +71,11 @@ func (f *Files) CopyRecursive(src string) error { } func (f *Files) Open(filename string) (io.ReadCloser, error) { - return os.Open(filepath.Join(f.outputDirectory, filename)) + return os.Open(f.join(filename)) } func (f *Files) OutputToFile(output io.Reader, filename string) error { - fn := filepath.Join(f.outputDirectory, filename) + fn := f.join(filename) if err := f.mkdirp(filepath.Dir(filename)); err != nil { return err } @@ -93,7 +94,7 @@ func (f *Files) OutputToFile(output io.Reader, filename string) error { } func (f *Files) RenderToFile(component templ.Component, filename string) error { - fn := filepath.Join(f.outputDirectory, filename) + fn := f.join(filename) if err := f.mkdirp(filepath.Dir(filename)); err != nil { return err } @@ -112,7 +113,7 @@ func (f *Files) RenderToFile(component templ.Component, filename string) error { } func (f *Files) WriterToFile(writer io.WriterTo, filename string) error { - fn := filepath.Join(f.outputDirectory, filename) + fn := f.join(filename) if err := f.mkdirp(filepath.Dir(filename)); err != nil { return err } @@ -209,3 +210,10 @@ func (f *Files) mkdirp(dir string) error { return errors.WithMessage(err, "could not create directory") } + +func (f *Files) join(filename string) string { + if strings.HasSuffix(filename, "/") { + filename = filename + "index.html" + } + return filepath.Join(f.outputDirectory, filename) +} |