From 88932b8dc1d2a73195dcb1a9c4b82e15acd908c4 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 26 Jan 2025 14:34:58 +0100 Subject: move / -> /index.html convention to storage layer --- internal/storage/files/writer.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'internal/storage') 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) +} -- cgit 1.4.1