about summary refs log tree commit diff stats
path: root/internal/builder
diff options
context:
space:
mode:
authorAlan Pearce2025-01-26 11:52:12 +0100
committerAlan Pearce2025-01-26 13:38:16 +0100
commit7d9e98a0996eca0372e38cee4b8826d84a9ace2b (patch)
tree6ae88100a923012f04ec316a45990b6902140136 /internal/builder
parent93c01942cb379b448dafab7ceffd78c005772928 (diff)
downloadwebsite-7d9e98a0996eca0372e38cee4b8826d84a9ace2b.tar.lz
website-7d9e98a0996eca0372e38cee4b8826d84a9ace2b.tar.zst
website-7d9e98a0996eca0372e38cee4b8826d84a9ace2b.zip
refactor outputs->storage for generalisation
Diffstat (limited to 'internal/builder')
-rw-r--r--internal/builder/builder.go30
1 files changed, 15 insertions, 15 deletions
diff --git a/internal/builder/builder.go b/internal/builder/builder.go
index 6e5cfc9..68eec14 100644
--- a/internal/builder/builder.go
+++ b/internal/builder/builder.go
@@ -9,8 +9,8 @@ import (
 
 	"go.alanpearce.eu/website/internal/config"
 	"go.alanpearce.eu/website/internal/content"
-	"go.alanpearce.eu/website/internal/outputs"
 	"go.alanpearce.eu/website/internal/sitemap"
+	"go.alanpearce.eu/website/internal/storage/files"
 	"go.alanpearce.eu/website/templates"
 	"go.alanpearce.eu/x/log"
 
@@ -35,8 +35,8 @@ func joinSourcePath(src string) func(string) string {
 }
 
 func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result, error) {
-	output := outputs.NewFilesOutput(ioConfig.Destination, log, &outputs.Options{
-		CompressFiles: !ioConfig.Development,
+	storage := files.NewWriter(ioConfig.Destination, log, &files.Options{
+		Compress: !ioConfig.Development,
 	})
 
 	joinSource := joinSourcePath(ioConfig.Source)
@@ -46,7 +46,7 @@ func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result,
 		Hashes: make([]string, 0),
 	}
 
-	err := output.CopyRecursive(joinSource("static"))
+	err := storage.CopyRecursive(joinSource("static"))
 	if err != nil {
 		return nil, errors.WithMessage(err, "could not copy static files")
 	}
@@ -69,13 +69,13 @@ func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result,
 	for _, post := range posts {
 		log.Debug("rendering post", "post", post.Basename)
 		sitemap.AddPath(post.URL, post.Date)
-		if err := output.RenderToFile(templates.PostPage(config, post), post.Output); err != nil {
+		if err := storage.RenderToFile(templates.PostPage(config, post), post.Output); err != nil {
 			return nil, err
 		}
 	}
 
 	log.Debug("rendering tags list")
-	if err := output.RenderToFile(
+	if err := storage.RenderToFile(
 		templates.TagsPage(config, "tags", mapset.Sorted(tags), "/tags"),
 		path.Join("tags", "index.html"),
 	); err != nil {
@@ -92,7 +92,7 @@ func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result,
 		}
 		log.Debug("rendering tags page", "tag", tag)
 		url := "/tags/" + tag
-		if err := output.RenderToFile(
+		if err := storage.RenderToFile(
 			templates.TagPage(config, tag, matchingPosts, url),
 			path.Join("tags", tag, "index.html"),
 		); err != nil {
@@ -110,13 +110,13 @@ func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result,
 		if err != nil {
 			return nil, errors.WithMessage(err, "could not render tag feed page")
 		}
-		if err := output.WriterToFile(feed, path.Join("tags", tag, "atom.xml")); err != nil {
+		if err := storage.WriterToFile(feed, path.Join("tags", tag, "atom.xml")); err != nil {
 			return nil, err
 		}
 	}
 
 	log.Debug("rendering list page")
-	if err := output.RenderToFile(
+	if err := storage.RenderToFile(
 		templates.ListPage(config, posts, "/post"),
 		path.Join("post", "index.html"),
 	); err != nil {
@@ -129,7 +129,7 @@ func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result,
 	if err != nil {
 		return nil, errors.WithMessage(err, "could not render feed")
 	}
-	if err := output.WriterToFile(feed, "atom.xml"); err != nil {
+	if err := storage.WriterToFile(feed, "atom.xml"); err != nil {
 		return nil, err
 	}
 
@@ -138,7 +138,7 @@ func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result,
 	if err != nil {
 		return nil, errors.WithMessage(err, "could not render feed styles")
 	}
-	if err := output.OutputToFile(feedStyles, "feed-styles.xsl"); err != nil {
+	if err := storage.OutputToFile(feedStyles, "feed-styles.xsl"); err != nil {
 		return nil, err
 	}
 	_, err = feedStyles.Seek(0, 0)
@@ -160,14 +160,14 @@ func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result,
 	if err != nil {
 		return nil, err
 	}
-	if err := output.RenderToFile(templates.Homepage(config, posts, content), "index.html"); err != nil {
+	if err := storage.RenderToFile(templates.Homepage(config, posts, content), "index.html"); err != nil {
 		return nil, err
 	}
 	// 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{})
-	f, err := output.Open("index.html")
+	f, err := storage.Open("index.html")
 	if err != nil {
 		return nil, err
 	}
@@ -176,7 +176,7 @@ func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result,
 	r.Hashes = append(r.Hashes, h)
 
 	log.Debug("rendering sitemap")
-	if err := output.WriterToFile(sitemap, "sitemap.xml"); err != nil {
+	if err := storage.WriterToFile(sitemap, "sitemap.xml"); err != nil {
 		return nil, err
 	}
 
@@ -185,7 +185,7 @@ func build(ioConfig *IOConfig, config *config.Config, log *log.Logger) (*Result,
 	if err != nil {
 		return nil, err
 	}
-	if err := output.OutputToFile(rob, "robots.txt"); err != nil {
+	if err := storage.OutputToFile(rob, "robots.txt"); err != nil {
 		return nil, err
 	}