about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2025-01-25 21:50:20 +0100
committerAlan Pearce2025-01-25 21:50:20 +0100
commit93c01942cb379b448dafab7ceffd78c005772928 (patch)
treecc2ea749569677ed8a283772551c8cb9d4350817
parent160a6e5084ed3c2a6d9ec3831325d3607cc222c1 (diff)
downloadwebsite-93c01942cb379b448dafab7ceffd78c005772928.tar.lz
website-93c01942cb379b448dafab7ceffd78c005772928.tar.zst
website-93c01942cb379b448dafab7ceffd78c005772928.zip
builder:make getHTMLStyleHash output-independent
-rw-r--r--internal/builder/builder.go8
-rw-r--r--internal/builder/template.go10
-rw-r--r--internal/outputs/files.go4
3 files changed, 12 insertions, 10 deletions
diff --git a/internal/builder/builder.go b/internal/builder/builder.go
index 7c1911e..6e5cfc9 100644
--- a/internal/builder/builder.go
+++ b/internal/builder/builder.go
@@ -39,7 +39,6 @@ func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result,
 		CompressFiles: !ioConfig.Development,
 	})
 
-	outDir := ioConfig.Destination
 	joinSource := joinSourcePath(ioConfig.Source)
 
 	log.Debug("output", "dir", ioConfig.Destination)
@@ -168,7 +167,12 @@ func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result,
 	// 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")
diff --git a/internal/builder/template.go b/internal/builder/template.go
index c318107..914b67d 100644
--- a/internal/builder/template.go
+++ b/internal/builder/template.go
@@ -155,14 +155,8 @@ func getFeedStylesHash(r io.Reader) (string, error) {
 	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
 	}
diff --git a/internal/outputs/files.go b/internal/outputs/files.go
index 3425d93..e8da259 100644
--- a/internal/outputs/files.go
+++ b/internal/outputs/files.go
@@ -70,6 +70,10 @@ func (f *FilesOutput) CopyRecursive(src string) error {
 	})
 }
 
+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 {