package storage import ( "io" "strings" "time" "github.com/Southclaws/fault" "github.com/Southclaws/fault/fmsg" "go.alanpearce.eu/homestead/internal/buffer" "go.alanpearce.eu/homestead/internal/builder/template" ) type File struct { Path string ContentType string LastModified time.Time Etag string Title string StyleHash string Encodings map[string]*buffer.Buffer } func (f *File) AvailableEncodings() []string { encs := make([]string, 0, len(f.Encodings)) for enc := range f.Encodings { encs = append(encs, enc) } return encs } func (f *File) CalculateStyleHash() (err error) { buf := f.Encodings["identity"] if buf == nil { return fault.New("buffer not initialised") } if _, err := buf.Seek(0, io.SeekStart); err != nil { return fault.Wrap(err, fmsg.With("could not seek buffer")) } mime, _, _ := strings.Cut(f.ContentType, ";") switch mime { case "text/html": f.StyleHash, err = template.GetHTMLStyleHash(buf) if err != nil { return fault.Wrap(err, fmsg.With("could not calculate HTML style hash")) } default: return } if _, err := buf.Seek(0, io.SeekStart); err != nil { return fault.Wrap(err, fmsg.With("could not seek buffer")) } return }