all repos — homestead @ 5ce60eee31c403537efd6ddb20308a3652a928b2

Code for my website

re-organise everything

Alan Pearce
commit

5ce60eee31c403537efd6ddb20308a3652a928b2

parent

4f48df92fa20e1c9cb4833400aabbeaf5c67718b

1 file changed, 16 insertions(+), 20 deletions(-)

changed files
M internal/builder/builder.gointernal/builder/builder.go
@@ -2,6 +2,7 @@ package builder
import ( "context" + "database/sql" "fmt" "io" "io/fs"
@@ -24,10 +25,11 @@ mapset "github.com/deckarep/golang-set/v2"
"gitlab.com/tozd/go/errors" ) -type IOConfig struct { +type Options struct { Source string `conf:"default:.,short:s,flag:src"` Destination string `conf:"default:public,short:d,flag:dest"` Development bool `conf:"default:false,flag:dev"` + DB *sql.DB } type Result struct {
@@ -74,27 +76,21 @@ }
func build( storage storage.Writer, - ioConfig *IOConfig, + options *Options, config *config.Config, log *log.Logger, ) (*Result, error) { ctx := context.TODO() buf := new(buffer.Buffer) - joinSource := joinSourcePath(ioConfig.Source) + joinSource := joinSourcePath(options.Source) - log.Debug("output", "dir", ioConfig.Destination) r := &Result{ Hashes: make([]string, 0), } - err := copyRecursive(storage, joinSource("static")) - if err != nil { - return nil, errors.WithMessage(err, "could not copy static files") - } - - log.Debug("reading posts") + log.Debug("reading posts", "source", options.Source) posts, tags, err := content.ReadPosts(&content.Config{ - Root: joinSource("content"), + Root: options.Source, InputDir: "post", }, log.Named("content")) if err != nil {
@@ -190,7 +186,7 @@ return nil, err
} log.Debug("rendering feed styles") - feedStyles, err := renderFeedStyles(ioConfig.Source) + feedStyles, err := renderFeedStyles(options.Source) if err != nil { return nil, errors.WithMessage(err, "could not render feed styles") }
@@ -212,7 +208,7 @@ }
r.Hashes = append(r.Hashes, h) log.Debug("rendering homepage") - _, text, err := content.GetPost(joinSource(filepath.Join("content", "index.md"))) + _, text, err := content.GetPost(joinSource("index.md")) if err != nil { return nil, err }
@@ -243,7 +239,7 @@ return nil, err
} log.Debug("rendering robots.txt") - rob, err := renderRobotsTXT(ioConfig.Source, config) + rob, err := renderRobotsTXT(config) if err != nil { return nil, err }
@@ -258,21 +254,21 @@
return r, nil } -func BuildSite(ioConfig *IOConfig, cfg *config.Config, log *log.Logger) (*Result, error) { +func BuildSite(options *Options, cfg *config.Config, log *log.Logger) (*Result, error) { if cfg == nil { return nil, errors.New("config is nil") } - cfg.InjectLiveReload = ioConfig.Development + cfg.InjectLiveReload = options.Development templates.Setup() - loadCSS(ioConfig.Source) + loadCSS() - storage, err := files.NewWriter(ioConfig.Destination, log, &files.Options{ - Compress: !ioConfig.Development, + storage, err := files.NewWriter(options.Destination, log, &files.Options{ + Compress: !options.Development, }) if err != nil { return nil, errors.WithMessage(err, "could not create storage writer") } - return build(storage, ioConfig, cfg, log) + return build(storage, options, cfg, log) }