diff --git a/cmd/build.go b/cmd/build.go index 28955a6..6f60c84 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -39,7 +39,7 @@ var ( // directory dst. type Builder func(src, dst string, cfg document.Config) error -func newBuildCmd(logger *slog.Logger) *cobra.Command { +func newBuildCmd() *cobra.Command { buildCmd := &cobra.Command{ Use: "build", Short: "Build a Winter project", @@ -47,19 +47,19 @@ func newBuildCmd(logger *slog.Logger) *cobra.Command { Build the Winter project in the current directory into ` + "`./dist`" + `. `), RunE: func(cmd *cobra.Command, args []string) error { - logger.Debug("Reading config.") + slog.Debug("Reading config.") cfg, err := document.NewConfig() if err != nil { return err } - logger.Debug("Building substructure.") - s, err := document.NewSubstructure(logger, cfg) + slog.Debug("Building substructure.") + s, err := document.NewSubstructure(cfg) if err != nil { return err } - logger.Debug("Executing templates.") + slog.Debug("Executing templates.") if err := s.ExecuteAll(dist); err != nil { return err } @@ -94,7 +94,7 @@ func newBuildCmd(logger *slog.Logger) *cobra.Command { } server.RegisterOnShutdown(reloader.Shutdown) - go listenForCtrlC(logger, stop, &server, &reloader) + go listenForCtrlC(stop, &server, &reloader) go startFileServer(&server) if err := reloader.Watch(append(cfg.Src, ".")); err != nil { @@ -112,16 +112,21 @@ func newBuildCmd(logger *slog.Logger) *cobra.Command { } f := buildCmd.PersistentFlags() - serve = f.BoolP(serveFlag, "s", false, "start a webserver and rebuild on file changes") + serve = f.BoolP( + serveFlag, + "s", + false, + "start a webserver and rebuild on file changes", + ) return buildCmd } -func listenForCtrlC(logger *slog.Logger, stop chan struct{}, srvr *http.Server, reloader *Reloader) { +func listenForCtrlC(stop chan struct{}, srvr *http.Server, reloader *Reloader) { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) <-c - logger.Debug("Stopping") + slog.Debug("Stopping") ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second) defer cancel() if err := srvr.Shutdown(ctx); err != nil { diff --git a/cmd/clean.go b/cmd/clean.go index c6abbdb..2c4e553 100644 --- a/cmd/clean.go +++ b/cmd/clean.go @@ -2,7 +2,6 @@ package cmd // import "twos.dev/winter/cmd" import ( "fmt" - "log/slog" "os" "github.com/adrg/xdg" @@ -11,7 +10,7 @@ import ( "twos.dev/winter/document" ) -func newCleanCmd(logger *slog.Logger) *cobra.Command { +func newCleanCmd() *cobra.Command { cmd := &cobra.Command{ Use: "clean", Short: "Purge the Winter cache", diff --git a/cmd/config.go b/cmd/config.go index d1613b9..d04bc58 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -2,7 +2,6 @@ package cmd // import "twos.dev/winter/cmd" import ( "fmt" - "log/slog" "os" "github.com/mitchellh/mapstructure" @@ -12,7 +11,7 @@ import ( "twos.dev/winter/document" ) -func newConfigCmd(logger *slog.Logger) *cobra.Command { +func newConfigCmd() *cobra.Command { cmd := &cobra.Command{ Use: "config", Short: "Interact with Winter configuration", diff --git a/cmd/freeze.go b/cmd/freeze.go index cc20dec..3fc53de 100644 --- a/cmd/freeze.go +++ b/cmd/freeze.go @@ -3,7 +3,6 @@ package cmd // import "twos.dev/winter/cmd" import ( "context" "fmt" - "log/slog" "os" "path/filepath" @@ -17,7 +16,7 @@ const ( KnownURLsPath = "src/urls.txt" ) -func newFreezeCmd(logger *slog.Logger) *cobra.Command { +func newFreezeCmd() *cobra.Command { cmd := &cobra.Command{ Use: "freeze [shortname...]", Short: "Turn a warm file cold", @@ -56,7 +55,7 @@ func newFreezeCmd(logger *slog.Logger) *cobra.Command { if err != nil { return err } - s, err := document.NewSubstructure(logger, cfg) + s, err := document.NewSubstructure(cfg) if err != nil { return err } @@ -68,11 +67,18 @@ func newFreezeCmd(logger *slog.Logger) *cobra.Command { for _, shortname := range args { document, ok := s.DocBySourcePath(shortname) if !ok { - return fmt.Errorf("cannot find document with shortname `%s`", shortname) + return fmt.Errorf( + "cannot find document with shortname `%s`", + shortname, + ) } oldpath := document.Metadata().SourcePath - newpath := filepath.Join("src", "cold", filepath.Base(document.Metadata().SourcePath)) + newpath := filepath.Join( + "src", + "cold", + filepath.Base(document.Metadata().SourcePath), + ) // The directory to remove warm files from, in addition to src/warm, so // that the file doesn't just sync back to src/warm after removal. TODO: diff --git a/cmd/generate.go b/cmd/generate.go index 82faf07..4ea5c1a 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -5,7 +5,6 @@ import ( "encoding/json" "io" "io/fs" - "log/slog" "os" "regexp" @@ -15,7 +14,7 @@ import ( "twos.dev/winter/document" ) -func newGenerateCommand(logger *slog.Logger) *cobra.Command { +func newGenerateCommand() *cobra.Command { cmd := &cobra.Command{ Use: "generate", Short: "Generate internal Winter code", @@ -57,5 +56,9 @@ func runGenerateCmd(in io.Reader, out io.Writer) error { if err := json.Indent(&buf, schema, "", " "); err != nil { return err } - return os.WriteFile("./cmd/winter.schema.yml", buf.Bytes(), fs.FileMode(0o644)) + return os.WriteFile( + "./cmd/winter.schema.yml", + buf.Bytes(), + fs.FileMode(0o644), + ) } diff --git a/cmd/init.go b/cmd/init.go index 23cc0e5..2dc273f 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -3,7 +3,6 @@ package cmd // import "twos.dev/winter/cmd" import ( "errors" "fmt" - "log/slog" "os" "path/filepath" @@ -11,7 +10,7 @@ import ( "twos.dev/winter/cliutils" ) -func newInitCmd(logger *slog.Logger) *cobra.Command { +func newInitCmd() *cobra.Command { cmd := &cobra.Command{ Use: "init [DIR]", Short: "Start a new Winter project", diff --git a/cmd/root.go b/cmd/root.go index e38b1de..3eaf790 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -11,16 +11,14 @@ import ( ) const ( - dist = "dist" - verboseFlag = "verbose" + dist = "dist" ) // Execute sets up the root command and all attached subcommands, // then runs them according to the CLI arguments supplied. func Execute(version string) { - opts := slog.HandlerOptions{Level: slog.LevelDebug} - logger := slog.New(slog.NewTextHandler(os.Stderr, &opts)) - var verbosity int + opts := slog.HandlerOptions{Level: slog.LevelWarn} + var moreVerbose, lessVerbose int rootCmd := &cobra.Command{ Use: "winter", Short: cliutils.Sprintf("Build or serve a static website locally"), @@ -53,28 +51,45 @@ func Execute(version string) { it automatically stops and errors. `), PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - if verbosity <= 0 { + verbosity := moreVerbose - lessVerbose + switch verbosity { + case -1: + opts.Level = slog.LevelError + case 0: opts.Level = slog.LevelWarn - } else if verbosity == 1 { + case 1: opts.Level = slog.LevelInfo - } else { + case 2: opts.Level = slog.LevelDebug } + slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &opts))) return nil }, Version: version, } f := rootCmd.PersistentFlags() _ = *f.StringArrayP("source", "i", []string{}, "supplemental source file or directory to build (can be specified multiple times)") - f.CountVarP(&verbosity, verboseFlag, "v", "output more details when running") - rootCmd.AddCommand(newBuildCmd(logger)) - rootCmd.AddCommand(newCleanCmd(logger)) - rootCmd.AddCommand(newConfigCmd(logger)) - rootCmd.AddCommand(newFreezeCmd(logger)) - rootCmd.AddCommand(newGenerateCommand(logger)) - rootCmd.AddCommand(newInitCmd(logger)) - rootCmd.AddCommand(newServeCmd(logger)) - rootCmd.AddCommand(newTestCmd(logger)) + f.CountVarP( + &moreVerbose, + "verbose", + "v", + "output more details", + ) + f.CountVarP( + &lessVerbose, + "quiet", + "q", + "output fewer details", + ) + + rootCmd.AddCommand(newBuildCmd()) + rootCmd.AddCommand(newCleanCmd()) + rootCmd.AddCommand(newConfigCmd()) + rootCmd.AddCommand(newFreezeCmd()) + rootCmd.AddCommand(newGenerateCommand()) + rootCmd.AddCommand(newInitCmd()) + rootCmd.AddCommand(newServeCmd()) + rootCmd.AddCommand(newTestCmd()) err := rootCmd.ExecuteContext(context.Background()) if err != nil { os.Exit(1) diff --git a/cmd/serve.go b/cmd/serve.go index b7dbb78..b95ed50 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -1,13 +1,11 @@ package cmd // import "twos.dev/winter/cmd" import ( - "log/slog" - "github.com/spf13/cobra" "twos.dev/winter/cliutils" ) -func newServeCmd(logger *slog.Logger) *cobra.Command { +func newServeCmd() *cobra.Command { return &cobra.Command{ Use: "serve", Short: cliutils.Sprintf("Alias of `winter build --serve`"), @@ -26,7 +24,7 @@ func newServeCmd(logger *slog.Logger) *cobra.Command { along with any related page that may have changed as a result. `), RunE: func(cmd *cobra.Command, args []string) error { - buildCmd := newBuildCmd(logger) + buildCmd := newBuildCmd() if err := buildCmd.Flag(serveFlag).Value.Set("true"); err != nil { return err } diff --git a/cmd/test.go b/cmd/test.go index 1b9b4b4..7910e15 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -3,7 +3,6 @@ package cmd // import "twos.dev/winter/cmd" import ( "fmt" "io" - "log/slog" "net/http" "net/url" @@ -11,7 +10,7 @@ import ( "twos.dev/winter/cliutils" ) -func newTestCmd(logger *slog.Logger) *cobra.Command { +func newTestCmd() *cobra.Command { return &cobra.Command{ Use: "test ", Short: "Run site-specific integration tests", @@ -50,7 +49,9 @@ func newTestCmd(logger *slog.Logger) *cobra.Command { // In case I ever move off GitHub Pages, make sure we continue this implementation detail; // twos.dev/winter is a required path because that's the Go import path. if string(winterBody) != string(winterHTMLBody) { - return fmt.Errorf("twos.dev/winter and twos.dev/winter.html must be the same page") + return fmt.Errorf( + "twos.dev/winter and twos.dev/winter.html must be the same page", + ) } return nil }, diff --git a/document/img.go b/document/img.go index 3819b2d..98c0c62 100644 --- a/document/img.go +++ b/document/img.go @@ -46,9 +46,8 @@ type img struct { // WebPath is the path component of the URL to the image as it will exist after building. WebPath string - cfg *Config - logger *slog.Logger - photo image.Image + cfg *Config + photo image.Image } type thumbnail struct { @@ -78,17 +77,19 @@ func (t thumbnails) Swap(i, j int) { // NewIMG returns a struct that represents an image to be built. // The returned value implements [Document]. -func NewIMG(logger *slog.Logger, src string, cfg *Config) (*img, error) { +func NewIMG(src string, cfg *Config) (*img, error) { relpath, err := filepath.Rel("src", src) if err != nil { return nil, fmt.Errorf("can't get relpath for photo `%s`: %w", src, err) } return &img{ SourcePath: src, - WebPath: fmt.Sprintf("%s.webp", strings.TrimSuffix(relpath, filepath.Ext(relpath))), + WebPath: fmt.Sprintf( + "%s.webp", + strings.TrimSuffix(relpath, filepath.Ext(relpath)), + ), - cfg: cfg, - logger: logger, + cfg: cfg, }, nil } @@ -141,7 +142,11 @@ func (im *img) Load(r io.Reader) error { func (im *img) Render(w io.Writer) error { if err := webpbin.Encode(w, im.photo); err != nil { - return fmt.Errorf("cannot encode source image %q to WebP: %w", im.SourcePath, err) + return fmt.Errorf( + "cannot encode source image %q to WebP: %w", + im.SourcePath, + err, + ) } if err := im.thumbnails(im.SourcePath); err != nil { return fmt.Errorf("can't generate thumbnails: %w", err) @@ -206,7 +211,12 @@ func (d *img) generatedPhotosAreFresh(src string) (bool, error) { return false, fmt.Errorf("cannot compute hash for %q: %w", src, err) } - sumPath, err := xdg.CacheFile(fmt.Sprintf("%s.sum", filepath.Join(AppName, "generated", "img", filepath.Base(src)))) + sumPath, err := xdg.CacheFile( + fmt.Sprintf( + "%s.sum", + filepath.Join(AppName, "generated", "img", filepath.Base(src)), + ), + ) if err != nil { return false, fmt.Errorf("cannot find Winter cache: %w", err) } @@ -221,7 +231,11 @@ func (d *img) generatedPhotosAreFresh(src string) (bool, error) { return true, nil } if err := os.MkdirAll(filepath.Dir(sumPath), 0o755); err != nil { - return false, fmt.Errorf("cann't make thumbnail directory for sums %q: %w", filepath.Dir(sumPath), err) + return false, fmt.Errorf( + "cann't make thumbnail directory for sums %q: %w", + filepath.Dir(sumPath), + err, + ) } if err := os.WriteFile(sumPath, []byte(fmt.Sprintf("%d", newSum)), 0o644); err != nil { return false, fmt.Errorf("cannot write hash for %q: %w", src, err) @@ -275,7 +289,12 @@ func (im *img) loadEXIF(r io.Reader) error { _, err = x.Get(exif.GPSInfoIFDPointer) if err == nil { // location data is set! no no no! - panic(fmt.Sprintf("photo %s has location data! please strip it.", im.SourcePath)) + panic( + fmt.Sprintf( + "photo %s has location data! please strip it.", + im.SourcePath, + ), + ) } im.EXIF = EXIF{ @@ -296,12 +315,19 @@ func (im *img) loadEXIF(r io.Reader) error { // The file at src is read at least once every time this function is called, // but the thumbnails are only regenerated if src has changed since their last generation. func (im *img) thumbnails(srcPath string) error { - im.logger.Debug(fmt.Sprintf("Creating thumbnails for %s.", srcPath)) + slog.Debug(fmt.Sprintf("Creating thumbnails for %s.", srcPath)) for _, thmb := range im.Thumbnails { if thmb.Width <= 0 || thmb.Height <= 0 { continue } - im.logger.Debug(fmt.Sprintf("Created %dx%d thumbnail for %s.", thmb.Width, thmb.Height, srcPath)) + slog.Debug( + fmt.Sprintf( + "Created %dx%d thumbnail for %s.", + thmb.Width, + thmb.Height, + srcPath, + ), + ) dstPhoto := image.NewRGBA(image.Rect(0, 0, thmb.Width, thmb.Height)) draw.CatmullRom.Scale( @@ -337,7 +363,11 @@ func (im *img) thumbnails(srcPath string) error { defer destinationFile.Close() if err := webpbin.Encode(destinationFile, dstPhoto); err != nil { - return fmt.Errorf("cannot encode WebP thumbnail to %q: %w", thmb.WebPath, err) + return fmt.Errorf( + "cannot encode WebP thumbnail to %q: %w", + thmb.WebPath, + err, + ) } } @@ -359,7 +389,10 @@ func (im *img) thumbnails(srcPath string) error { // foo.1x1.webp, // foo.2x2.webp, // and so on. -func (im *img) intuitThumbnails(srcPhoto image.Image, srcPath, thumbdir string) error { +func (im *img) intuitThumbnails( + srcPhoto image.Image, + srcPath, thumbdir string, +) error { var thmbs thumbnails p := srcPhoto.Bounds().Size() for height := 1; height < p.X; height *= 2 { @@ -369,11 +402,20 @@ func (im *img) intuitThumbnails(srcPhoto image.Image, srcPath, thumbdir string) } destPath := filepath.Join( thumbdir, - fmt.Sprintf("%s.%dx%d.webp", strings.TrimSuffix(filepath.Base(srcPath), filepath.Ext(srcPath)), width, height), + fmt.Sprintf( + "%s.%dx%d.webp", + strings.TrimSuffix(filepath.Base(srcPath), filepath.Ext(srcPath)), + width, + height, + ), ) webPath, err := filepath.Rel(im.cfg.Dist, destPath) if err != nil { - return fmt.Errorf("cannot get relative path for thumbnail %q: %w", thumbdir, err) + return fmt.Errorf( + "cannot get relative path for thumbnail %q: %w", + thumbdir, + err, + ) } thmbs = append(thmbs, &thumbnail{ Height: height, @@ -392,7 +434,10 @@ func (im *img) intuitThumbnails(srcPhoto image.Image, srcPath, thumbdir string) // // If the EXIF data is present but winter.yml does not index it, // an error is returned. -func (im *img) findGear(x *exif.Exif, make, model exif.FieldName) (*Gear, error) { +func (im *img) findGear( + x *exif.Exif, + make, model exif.FieldName, +) (*Gear, error) { gearMake, err := x.Get(make) if err != nil { if errors.Is(err, exif.TagNotPresentError(make)) { @@ -411,7 +456,11 @@ func (im *img) findGear(x *exif.Exif, make, model exif.FieldName) (*Gear, error) gearModelStr := sanitizeEXIFField(gearModel) g, ok := im.cfg.GearByString(gearMakeStr, gearModelStr) if !ok { - return nil, fmt.Errorf("no such gear with make=%q and model=%q", gearMakeStr, gearModelStr) + return nil, fmt.Errorf( + "no such gear with make=%q and model=%q", + gearMakeStr, + gearModelStr, + ) } return g, nil } diff --git a/document/winter.go b/document/winter.go index 2481a29..7d2aef2 100644 --- a/document/winter.go +++ b/document/winter.go @@ -208,22 +208,24 @@ type Substructure struct { docs *documents // galleries is a map of gallery name to slice of galleries in that gallery. galleries map[string][]*img - logger *slog.Logger } // NewSubstructure returns a substructure with the given configuration. // Upon initialization, a substructure is the result of a discovery phase of content on the filesystem. // Further calls are needed to build the full graph of content and render it to HTML. -func NewSubstructure(logger *slog.Logger, cfg *Config) (*Substructure, error) { +func NewSubstructure(cfg *Config) (*Substructure, error) { devURL, err := url.Parse(cfg.Development.URL) if err != nil { - return nil, fmt.Errorf("cannot parse config development.url %q: %w", cfg.Development.URL, err) + return nil, fmt.Errorf( + "cannot parse config development.url %q: %w", + cfg.Development.URL, + err, + ) } s := Substructure{ cfg: cfg, devURL: devURL, docs: &documents{}, - logger: logger, } return &s, s.discover() } @@ -251,11 +253,21 @@ func (s *Substructure) ImageCount() int { func (s *Substructure) Build(doc Document) error { r, err := os.Open(doc.Metadata().SourcePath) if err != nil { - return fmt.Errorf("cannot read %q for building %q: %w", doc.Metadata().SourcePath, doc.Metadata().Title, err) + return fmt.Errorf( + "cannot read %q for building %q: %w", + doc.Metadata().SourcePath, + doc.Metadata().Title, + err, + ) } defer r.Close() if err := doc.Load(r); err != nil { - return fmt.Errorf("cannot load %q for building %q: %w", doc.Metadata().SourcePath, doc.Metadata().Title, err) + return fmt.Errorf( + "cannot load %q for building %q: %w", + doc.Metadata().SourcePath, + doc.Metadata().Title, + err, + ) } if err := s.buildWWW(doc); err != nil { @@ -270,28 +282,43 @@ func (s *Substructure) Build(doc Document) error { func (s *Substructure) buildWWW(doc Document) error { dest := filepath.Join(s.cfg.Dist, doc.Metadata().WebPath) - s.logger.Debug(fmt.Sprintf(" → %s", pad(dest))) + slog.Debug(fmt.Sprintf(" → %s", pad(dest))) if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil { return fmt.Errorf("cannot make directory structure for %q: %w", dest, err) } w, err := os.Create(dest) if err != nil { - return fmt.Errorf("cannot build %q (web path %q) into %q: %w", doc.Metadata().SourcePath, doc.Metadata().WebPath, dest, err) + return fmt.Errorf( + "cannot build %q (web path %q) into %q: %w", + doc.Metadata().SourcePath, + doc.Metadata().WebPath, + dest, + err, + ) } defer w.Close() if err := doc.Render(w); err != nil { - return fmt.Errorf("cannot render %q for building: %w", doc.Metadata().SourcePath, err) + return fmt.Errorf( + "cannot render %q for building: %w", + doc.Metadata().SourcePath, + err, + ) } return nil } func (s *Substructure) buildGemini(doc Document) error { if doc.Metadata().GeminiPath == "" { - s.logger.Debug(fmt.Sprintf("Skipping building %s into Gemini file", doc.Metadata().SourcePath)) + slog.Debug( + fmt.Sprintf( + "Skipping building %s into Gemini file", + doc.Metadata().SourcePath, + ), + ) return nil } dest := filepath.Join(s.cfg.Dist, doc.Metadata().GeminiPath) - s.logger.Debug(fmt.Sprintf(" → %s", pad(dest))) + slog.Debug(fmt.Sprintf(" → %s", pad(dest))) if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil { return fmt.Errorf("cannot make directory structure for %q: %w", dest, err) } @@ -307,7 +334,11 @@ func (s *Substructure) buildGemini(doc Document) error { defer w.Close() if gr, ok := doc.(GeminiRenderer); ok { if err := gr.RenderGemini(w); err != nil { - return fmt.Errorf("cannot render %q for building: %w", doc.Metadata().SourcePath, err) + return fmt.Errorf( + "cannot render %q for building: %w", + doc.Metadata().SourcePath, + err, + ) } } return nil @@ -331,7 +362,7 @@ func (s *Substructure) ExecuteAll(dist string) error { builtIMGs := map[string]*img{} for _, gallery := range s.galleries { for _, im := range gallery { - s.logger.Info(fmt.Sprintf("Building image %s.", im.SourcePath)) + slog.Info(fmt.Sprintf("Building image %s.", im.SourcePath)) if prev, ok := builtIMGs[im.WebPath]; ok { return fmt.Errorf( "both %s (%T) and %q (%T) wanted to build to %q/%q; remove one", @@ -345,7 +376,11 @@ func (s *Substructure) ExecuteAll(dist string) error { } fresh, err := im.generatedPhotosAreFresh(im.SourcePath) if err != nil { - return fmt.Errorf("cannot check freshness of %q: %w", im.SourcePath, err) + return fmt.Errorf( + "cannot check freshness of %q: %w", + im.SourcePath, + err, + ) } if fresh { if err := im.LoadEXIF(); err != nil { @@ -363,18 +398,31 @@ func (s *Substructure) ExecuteAll(dist string) error { return fmt.Errorf("cannot load image: %w", err) } if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil { - return fmt.Errorf("cannot make gallery dir %q: %w", filepath.Dir(dest), err) + return fmt.Errorf( + "cannot make gallery dir %q: %w", + filepath.Dir(dest), + err, + ) } destf, err := os.Create(dest) if err != nil { - return fmt.Errorf("cannot write image %q to %q during ExecuteAll: %w", im.SourcePath, dest, err) + return fmt.Errorf( + "cannot write image %q to %q during ExecuteAll: %w", + im.SourcePath, + dest, + err, + ) } defer destf.Close() if err := im.Render(destf); err != nil { return err } if err := s.Rebuild(im.SourcePath); err != nil { - return fmt.Errorf("cannot rebuild image %q during ExecuteAll: %w", im.SourcePath, err) + return fmt.Errorf( + "cannot rebuild image %q during ExecuteAll: %w", + im.SourcePath, + err, + ) } builtIMGs[im.WebPath] = im } @@ -414,13 +462,13 @@ func (s *Substructure) ExecuteAll(dist string) error { // // If src isn't known to the substructure, Rebuild no-ops and returns no error. func (s *Substructure) Rebuild(src string) error { - s.logger.Debug(fmt.Sprintf("%s ↓", src)) + slog.Debug(fmt.Sprintf("%s ↓", src)) if doc, ok := s.DocBySourcePath(src); ok { if err := s.Build(doc); err != nil { return fmt.Errorf("cannot retrieve doc at %q: %w", src, err) } } else { - s.logger.Debug(" + Tracking new file.") + slog.Debug(" + Tracking new file.") if err := s.discoverAtPath(src); err != nil { return fmt.Errorf("cannot add document to in-flight substructure: %w", err) } @@ -428,7 +476,12 @@ func (s *Substructure) Rebuild(src string) error { for _, doc := range s.docs.All { if doc.DependsOn(src) && doc.Metadata().SourcePath != src { if err := s.Build(doc); err != nil { - return fmt.Errorf("cannot build %q (dependent of %q): %w", doc.Metadata().SourcePath, src, err) + return fmt.Errorf( + "cannot build %q (dependent of %q): %w", + doc.Metadata().SourcePath, + src, + err, + ) } } } @@ -458,7 +511,7 @@ func (s *Substructure) addIMG(im *img) error { // discover clears the substructure of any known documents and discovers all documents from scratch on the filesystem. func (s *Substructure) discover() error { - s.logger.Debug("Starting discovery.") + slog.Debug("Starting discovery.") paths := append(s.cfg.Src, "src") for _, path := range paths { if err := s.discoverAtPath(path); err != nil { @@ -512,8 +565,8 @@ func (s *Substructure) discoverGalleries(src string) error { if shouldIgnore(src) { return nil } - s.logger.Debug(fmt.Sprintf("+ %s", src)) - im, err := NewIMG(s.logger, src, s.cfg) + slog.Debug(fmt.Sprintf("+ %s", src)) + im, err := NewIMG(src, s.cfg) if err != nil { return fmt.Errorf("cannot create gallery document from %s: %w", src, err) } @@ -548,7 +601,7 @@ func (s *Substructure) discoverHTML(path string) error { if shouldIgnore(src) { continue } - s.logger.Debug(fmt.Sprintf("+ %s", src)) + slog.Debug(fmt.Sprintf("+ %s", src)) meta := NewMetadata(src, tmplPath) s.add( NewHTMLDocument(src, meta, @@ -588,7 +641,7 @@ func (s *Substructure) discoverMarkdown(path string) error { if shouldIgnore(src) { continue } - s.logger.Debug(fmt.Sprintf("+ %s", src)) + slog.Debug(fmt.Sprintf("+ %s", src)) meta := NewMetadata(src, tmplPath) s.add( NewMarkdownDocument(src, meta, @@ -627,7 +680,7 @@ func (s *Substructure) discoverOrg(path string) error { if shouldIgnore(src) { continue } - s.logger.Debug(fmt.Sprintf("+ %s", src)) + slog.Debug(fmt.Sprintf("+ %s", src)) meta := NewMetadata(src, tmplPath) s.add( NewOrgDocument(src, meta, @@ -676,7 +729,7 @@ func (s *Substructure) discoverStatic(path string) error { } else if stat.IsDir() { continue } - s.logger.Debug(fmt.Sprintf("+ %s", src)) + slog.Debug(fmt.Sprintf("+ %s", src)) webPath, err := filepath.Rel(path, src) if err != nil { return fmt.Errorf("cannot determine desired web path of %q: %w", src, err) @@ -708,7 +761,7 @@ func (s *Substructure) discoverTemplates(path string) error { if shouldIgnore(src) { continue } - s.logger.Debug(fmt.Sprintf("+ %s", src)) + slog.Debug(fmt.Sprintf("+ %s", src)) meta := NewMetadata(src, tmplPath) s.add( NewHTMLDocument(src, meta,