about summary refs log tree commit diff stats
path: root/internal/builder/builder.go
diff options
context:
space:
mode:
authorAlan Pearce2024-06-29 16:48:40 +0200
committerAlan Pearce2024-06-29 16:48:40 +0200
commitb4095d108a2646bcf9e7fff64788b10d9bce8da3 (patch)
treef45554857a3128922b665ab0fb04150380c0d44e /internal/builder/builder.go
parente8221541404a8d2ca0758d48ba5fe9c85f9067ac (diff)
downloadwebsite-b4095d108a2646bcf9e7fff64788b10d9bce8da3.tar.lz
website-b4095d108a2646bcf9e7fff64788b10d9bce8da3.tar.zst
website-b4095d108a2646bcf9e7fff64788b10d9bce8da3.zip
build outside of working directory
Diffstat (limited to 'internal/builder/builder.go')
-rw-r--r--internal/builder/builder.go30
1 files changed, 20 insertions, 10 deletions
diff --git a/internal/builder/builder.go b/internal/builder/builder.go
index 256d422..a4e44c6 100644
--- a/internal/builder/builder.go
+++ b/internal/builder/builder.go
@@ -6,6 +6,7 @@ import (
 	"io"
 	"os"
 	"path"
+	"path/filepath"
 	"slices"
 	"time"
 
@@ -86,13 +87,21 @@ func writerToFile(writer io.WriterTo, pathParts ...string) error {
 	return nil
 }
 
-func build(outDir string, config *config.Config) (*Result, error) {
+func joinSourcePath(src string) func(string) string {
+	return func(rel string) string {
+		return filepath.Join(src, rel)
+	}
+}
+
+func build(ioConfig *IOConfig, config *config.Config) (*Result, error) {
+	outDir := ioConfig.Destination
+	joinSource := joinSourcePath(ioConfig.Source)
 	log.Debug("output", "dir", outDir)
 	r := &Result{
 		Hashes: make([]string, 0),
 	}
 
-	err := copyRecursive("static", outDir)
+	err := copyRecursive(joinSource("static"), outDir)
 	if err != nil {
 		return nil, errors.WithMessage(err, "could not copy static files")
 	}
@@ -101,7 +110,7 @@ func build(outDir string, config *config.Config) (*Result, error) {
 		return nil, errors.WithMessage(err, "could not create post output directory")
 	}
 	log.Debug("reading posts")
-	posts, tags, err := content.ReadPosts("content", "post", outDir)
+	posts, tags, err := content.ReadPosts(joinSource("content"), "post", outDir)
 	if err != nil {
 		return nil, err
 	}
@@ -162,6 +171,7 @@ func build(outDir string, config *config.Config) (*Result, error) {
 
 		log.Debug("rendering tags feed", "tag", tag)
 		feed, err := renderFeed(
+			ioConfig.Source,
 			fmt.Sprintf("%s - %s", config.Title, tag),
 			config,
 			matchingPosts,
@@ -182,7 +192,7 @@ func build(outDir string, config *config.Config) (*Result, error) {
 	sitemap.AddPath("/post/", lastMod)
 
 	log.Debug("rendering feed")
-	feed, err := renderFeed(config.Title, config, posts, "feed")
+	feed, err := renderFeed(ioConfig.Source, config.Title, config, posts, "feed")
 	if err != nil {
 		return nil, errors.WithMessage(err, "could not render feed")
 	}
@@ -191,7 +201,7 @@ func build(outDir string, config *config.Config) (*Result, error) {
 	}
 
 	log.Debug("rendering feed styles")
-	feedStyles, err := renderFeedStyles()
+	feedStyles, err := renderFeedStyles(ioConfig.Source)
 	if err != nil {
 		return nil, errors.WithMessage(err, "could not render feed styles")
 	}
@@ -209,7 +219,7 @@ func build(outDir string, config *config.Config) (*Result, error) {
 	r.Hashes = append(r.Hashes, h)
 
 	log.Debug("rendering homepage")
-	_, text, err := content.GetPost(path.Join("content", "index.md"))
+	_, text, err := content.GetPost(joinSource(filepath.Join("content", "index.md")))
 	if err != nil {
 		return nil, err
 	}
@@ -233,7 +243,7 @@ func build(outDir string, config *config.Config) (*Result, error) {
 	}
 
 	log.Debug("rendering robots.txt")
-	rob, err := renderRobotsTXT(config)
+	rob, err := renderRobotsTXT(ioConfig.Source, config)
 	if err != nil {
 		return nil, err
 	}
@@ -247,7 +257,7 @@ func build(outDir string, config *config.Config) (*Result, error) {
 func BuildSite(ioConfig *IOConfig, cfg *config.Config) (*Result, error) {
 	if cfg == nil {
 		var err error
-		cfg, err = config.GetConfig()
+		cfg, err = config.GetConfig(ioConfig.Source)
 		if err != nil {
 			return nil, errors.WithMessage(err, "could not get config")
 		}
@@ -256,7 +266,7 @@ func BuildSite(ioConfig *IOConfig, cfg *config.Config) (*Result, error) {
 	compressFiles = !ioConfig.Development
 
 	templates.Setup()
-	loadCSS()
+	loadCSS(ioConfig.Source)
 
-	return build(ioConfig.Destination, cfg)
+	return build(ioConfig, cfg)
 }