all repos — homestead @ d70fced11c8c4cdbc53d6434527e6bfef514399d

Code for my website

set mtime of output based on input content

Alan Pearce
commit

d70fced11c8c4cdbc53d6434527e6bfef514399d

parent

9bea362c53a1631f4cf23deba1ba617a02814094

1 file changed, 30 insertions(+), 5 deletions(-)

changed files
M internal/storage/sqlite/writer.gointernal/storage/sqlite/writer.go
@@ -13,6 +13,7 @@ "github.com/andybalholm/brotli"
"github.com/klauspost/compress/gzip" "github.com/klauspost/compress/zstd" "go.alanpearce.eu/website/internal/buffer" + "go.alanpearce.eu/website/internal/content" "go.alanpearce.eu/website/internal/storage" "go.alanpearce.eu/x/log"
@@ -170,15 +171,27 @@ func contentType(pathname string) string {
return mime.TypeByExtension(filepath.Ext(pathNameToFileName(pathname))) } -func (s *Writer) Write(pathname string, content *buffer.Buffer) error { - s.log.Debug("storing content", "pathname", pathname) +func (s *Writer) WritePost(post *content.Post, content *buffer.Buffer) error { + s.log.Debug("storing post", "title", post.Title) bytes := content.Bytes() + etag, err := etag(bytes) + if err != nil { + return errors.WithMessage(err, "calculating etag") + } - urlID, err := s.storeURL(pathname) - if err != nil { - return errors.WithMessage(err, "storing URL") + file := &storage.File{ + Path: post.URL, + ContentType: contentType(post.URL), + LastModified: post.Date, + Etag: etag, } + return s.write(file, content) +} + +func (s *Writer) Write(pathname string, content *buffer.Buffer) error { + bytes := content.Bytes() + etag, err := etag(bytes) if err != nil { return errors.WithMessage(err, "calculating etag")
@@ -189,6 +202,18 @@ Path: pathname,
ContentType: contentType(pathname), LastModified: time.Now(), Etag: etag, + } + + return s.write(file, content) +} + +func (s *Writer) write(file *storage.File, content *buffer.Buffer) error { + s.log.Debug("storing content", "pathname", file.Path) + bytes := content.Bytes() + + urlID, err := s.storeURL(file.Path) + if err != nil { + return errors.WithMessage(err, "storing URL") } fileID, err := s.storeFile(urlID, file)