builder:make getHTMLStyleHash output-independent
Alan Pearce alan@alanpearce.eu
Sat, 25 Jan 2025 21:50:20 +0100
3 files changed, 12 insertions(+), 10 deletions(-)
M internal/builder/builder.go → internal/builder/builder.go
@@ -39,7 +39,6 @@ output := outputs.NewFilesOutput(ioConfig.Destination, log, &outputs.Options{ CompressFiles: !ioConfig.Development, }) - outDir := ioConfig.Destination joinSource := joinSourcePath(ioConfig.Source) log.Debug("output", "dir", ioConfig.Destination) @@ -168,7 +167,12 @@ // it would be nice to set LastMod here, but using the latest post // date would be wrong as the homepage has its own content file // without a date, which could be newer sitemap.AddPath("/", time.Time{}) - h, _ = getHTMLStyleHash(outDir, "index.html") + f, err := output.Open("index.html") + if err != nil { + return nil, err + } + defer f.Close() + h, _ = getHTMLStyleHash(f) r.Hashes = append(r.Hashes, h) log.Debug("rendering sitemap")
M internal/builder/template.go → internal/builder/template.go
@@ -155,14 +155,8 @@ return hash(style.InnerText()), nil } -func getHTMLStyleHash(filenames ...string) (string, error) { - fn := filepath.Join(filenames...) - f, err := os.Open(fn) - if err != nil { - return "", err - } - defer f.Close() - doc, err := NewDocumentFromReader(f) +func getHTMLStyleHash(r io.Reader) (string, error) { + doc, err := NewDocumentFromReader(r) if err != nil { return "", err }
M internal/outputs/files.go → internal/outputs/files.go
@@ -70,6 +70,10 @@ return nil }) } +func (f *FilesOutput) Open(filename string) (io.ReadCloser, error) { + return os.Open(filepath.Join(f.outputDirectory, filename)) +} + func (f *FilesOutput) OutputToFile(output io.Reader, filename string) error { fn := path.Join(f.outputDirectory, filename) if err := f.mkdirp(filepath.Dir(filename)); err != nil {