enable easier MIME type detection
6 files changed, 23 insertions(+), 10 deletions(-)
M internal/builder/builder.go → internal/builder/builder.go
@@ -261,7 +261,7 @@ buf.Reset() if err := templates.GoPackagePage(siteSettings, &config.Go, p).Render(buf); err != nil { return fault.Wrap(err) } - if err := storage.Write(fmt.Sprintf("/go/%s", p), siteSettings.Title, buf); err != nil { + if err := storage.Write(fmt.Sprintf("/go/%s.html", p), siteSettings.Title, buf); err != nil { return fault.Wrap(err) } }
M internal/storage/file.go → internal/storage/file.go
@@ -5,14 +5,15 @@ "io" "strings" "time" + "alin.ovh/homestead/internal/buffer" + "alin.ovh/homestead/internal/builder/template" "github.com/Southclaws/fault" "github.com/Southclaws/fault/fmsg" - "alin.ovh/homestead/internal/buffer" - "alin.ovh/homestead/internal/builder/template" ) type File struct { Path string + FSPath string ContentType string LastModified time.Time Etag string
M internal/storage/files/file.go → internal/storage/files/file.go
@@ -10,10 +10,10 @@ "os" "path/filepath" "strings" + "alin.ovh/homestead/internal/buffer" + "alin.ovh/homestead/internal/storage" "github.com/Southclaws/fault" "github.com/Southclaws/fault/fmsg" - "alin.ovh/homestead/internal/buffer" - "alin.ovh/homestead/internal/storage" ) var encodings = map[string]string{@@ -45,6 +45,7 @@ } file := &storage.File{ Path: path, + FSPath: filename, ContentType: mime.TypeByExtension(filepath.Ext(filename)), LastModified: stat.ModTime(), Etag: etag,
M internal/storage/files/writer.go → internal/storage/files/writer.go
@@ -92,6 +92,7 @@ func (f *Files) NewFileFromPost(post *content.Post) *storage.File { return &storage.File{ Path: post.URL, + FSPath: pathNameToFileName(post.URL), Encodings: map[string]*buffer.Buffer{}, } }
M internal/storage/sqlite/file.go → internal/storage/sqlite/file.go
@@ -11,3 +11,11 @@ } return pathname } + +func cleanPathName(pathname string) string { + if strings.HasSuffix(pathname, ".html") { + pathname = strings.TrimSuffix(pathname, ".html") + } + + return pathname +}
M internal/storage/sqlite/writer.go → internal/storage/sqlite/writer.go
@@ -10,13 +10,13 @@ "net/http" "path/filepath" "time" - "github.com/andybalholm/brotli" - "github.com/klauspost/compress/gzip" - "github.com/klauspost/compress/zstd" "alin.ovh/homestead/internal/buffer" "alin.ovh/homestead/internal/content" "alin.ovh/homestead/internal/storage" "alin.ovh/x/log" + "github.com/andybalholm/brotli" + "github.com/klauspost/compress/gzip" + "github.com/klauspost/compress/zstd" "github.com/Southclaws/fault" "github.com/Southclaws/fault/fmsg"@@ -209,6 +209,7 @@ func (s *Writer) NewFileFromPost(post *content.Post) *storage.File { file := &storage.File{ Title: post.Title, Path: post.URL, + FSPath: pathNameToFileName(post.URL), LastModified: post.Date, Encodings: map[string]*buffer.Buffer{}, }@@ -225,7 +226,8 @@ func (s *Writer) Write(pathname string, title string, content *buffer.Buffer) error { file := &storage.File{ Title: title, - Path: pathname, + Path: cleanPathName(pathname), + FSPath: pathname, LastModified: time.Now(), Encodings: map[string]*buffer.Buffer{}, }@@ -247,7 +249,7 @@ } file.Encodings["identity"] = content if file.ContentType == "" { - file.ContentType = contentType(file.Path) + file.ContentType = contentType(file.FSPath) } if file.Etag == "" {