diff options
author | Alan Pearce | 2024-06-27 13:34:21 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-27 13:34:21 +0200 |
commit | 879cc25421c66a959ab801f0937b4264a461fc7e (patch) | |
tree | 29141c22ef84cfc36ba74302b14546c21dbef199 /internal/builder | |
parent | d07ec650aafcfe4692bba8f481bc3cb8204cd4b0 (diff) | |
download | website-879cc25421c66a959ab801f0937b4264a461fc7e.tar.lz website-879cc25421c66a959ab801f0937b4264a461fc7e.tar.zst website-879cc25421c66a959ab801f0937b4264a461fc7e.zip |
use pointer to config in builder & templates
Diffstat (limited to 'internal/builder')
-rw-r--r-- | internal/builder/builder.go | 17 | ||||
-rw-r--r-- | internal/builder/template.go | 4 |
2 files changed, 12 insertions, 9 deletions
diff --git a/internal/builder/builder.go b/internal/builder/builder.go index 4436151..177fa2f 100644 --- a/internal/builder/builder.go +++ b/internal/builder/builder.go @@ -86,7 +86,7 @@ func writerToFile(writer io.WriterTo, pathParts ...string) error { return nil } -func build(outDir string, config config.Config) (*Result, error) { +func build(outDir string, config *config.Config) (*Result, error) { log.Debug("output", "dir", outDir) r := &Result{ Hashes: make([]string, 0), @@ -252,16 +252,19 @@ func build(outDir string, config config.Config) (*Result, error) { return r, nil } -func BuildSite(ioConfig IOConfig) (*Result, error) { - config, err := config.GetConfig() - if err != nil { - return nil, errors.WithMessage(err, "could not get config") +func BuildSite(ioConfig IOConfig, cfg *config.Config) (*Result, error) { + if cfg == nil { + var err error + cfg, err = config.GetConfig() + if err != nil { + return nil, errors.WithMessage(err, "could not get config") + } } - config.InjectLiveReload = ioConfig.Development + cfg.InjectLiveReload = ioConfig.Development compressFiles = !ioConfig.Development templates.Setup() loadCSS() - return build(ioConfig.Destination, *config) + return build(ioConfig.Destination, cfg) } diff --git a/internal/builder/template.go b/internal/builder/template.go index da45fb7..d46844d 100644 --- a/internal/builder/template.go +++ b/internal/builder/template.go @@ -66,7 +66,7 @@ func (q *QueryDocument) Find(selector string) *QuerySelection { return &QuerySelection{q.Document.Find(selector)} } -func renderRobotsTXT(config config.Config) (io.Reader, error) { +func renderRobotsTXT(config *config.Config) (io.Reader, error) { r, w := io.Pipe() tpl, err := template.ParseFiles("templates/robots.tmpl") if err != nil { @@ -87,7 +87,7 @@ func renderRobotsTXT(config config.Config) (io.Reader, error) { func renderFeed( title string, - config config.Config, + config *config.Config, posts []content.Post, specific string, ) (io.Reader, error) { |