print site building times

This commit is contained in:
facundoolano 2024-03-06 11:35:22 -03:00
parent d3ca71e95e
commit 2afd897ab3
2 changed files with 9 additions and 2 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"strings"
"time"
"github.com/alecthomas/kong"
"github.com/facundoolano/jorge/config"
@ -20,12 +21,16 @@ type Build struct {
// Read the files in src/ render them and copy the result to target/
func (cmd *Build) Run(ctx *kong.Context) error {
start := time.Now()
config, err := config.Load(cmd.ProjectDir)
if err != nil {
return err
}
return site.Build(*config)
err = site.Build(*config)
fmt.Printf("done in %.2fs\n", time.Since(start).Seconds())
return err
}
// Prompt the user for a string value

View file

@ -121,6 +121,7 @@ func runWatcher(config *config.Config, broker *EventBroker) (*fsnotify.Watcher,
// rebuilding the site and publishing a rebuild event to clients.
func rebuildSite(config *config.Config, watcher *fsnotify.Watcher, broker *EventBroker) {
fmt.Printf("building site\n")
start := time.Now()
// since new nested directories could be triggering this change, and we need to watch those too
// and since re-watching files is a noop, I just re-add the entire src everytime there's a change
@ -135,7 +136,8 @@ func rebuildSite(config *config.Config, watcher *fsnotify.Watcher, broker *Event
broker.publish("rebuild")
fmt.Println("done\nserving at", config.SiteUrl)
elapsed := time.Since(start)
fmt.Printf("done in %.2fs\nserving at %s\n", elapsed.Seconds(), config.SiteUrl)
}
// Configure the given watcher to notify for changes in the project source files