From b4095d108a2646bcf9e7fff64788b10d9bce8da3 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sat, 29 Jun 2024 16:48:40 +0200 Subject: build outside of working directory --- internal/builder/builder.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'internal/builder/builder.go') 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) } -- cgit 1.4.1