about summary refs log tree commit diff stats
path: root/cmd
diff options
context:
space:
mode:
authorAlan Pearce2024-04-16 20:33:57 +0200
committerAlan Pearce2024-04-16 20:50:24 +0200
commitf628605bcd0c3f7fbd45a09bfebe4c7b44bc743a (patch)
treefa55d0bd681a2830acbfccad6571c30e5e59755c /cmd
parent00557c355c12458e65ae5cd9e0fa5ebfba229b3a (diff)
downloadwebsite-f628605bcd0c3f7fbd45a09bfebe4c7b44bc743a.tar.lz
website-f628605bcd0c3f7fbd45a09bfebe4c7b44bc743a.tar.zst
website-f628605bcd0c3f7fbd45a09bfebe4c7b44bc743a.zip
add debug logging
Diffstat (limited to 'cmd')
-rw-r--r--cmd/build/main.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/cmd/build/main.go b/cmd/build/main.go
index 5e19517..97b7ab7 100644
--- a/cmd/build/main.go
+++ b/cmd/build/main.go
@@ -92,6 +92,7 @@ func readPosts(root string, inputDir string, outputDir string) ([]Post, Tags, er
 		if !f.IsDir() && path.Ext(pathFromRoot) == ".md" {
 			output := outputReplacer.Replace(pathFromRoot)
 			url := urlReplacer.Replace(pathFromRoot)
+			slog.Debug("reading post", "post", pathFromRoot)
 			matter, content, err := getPost(pathFromRoot)
 			if err != nil {
 				return nil, nil, err
@@ -102,6 +103,7 @@ func readPosts(root string, inputDir string, outputDir string) ([]Post, Tags, er
 			}
 
 			var buf bytes.Buffer
+			slog.Debug("rendering markdown in post", "post", pathFromRoot)
 			if err := markdown.Convert(*content, &buf); err != nil {
 				return nil, nil, errors.WithMessage(err, "could not convert markdown content")
 			}
@@ -134,6 +136,7 @@ func purgeCSS(htmlFilename string, cssFilename string) (string, error) {
 	if purgedCSS == nil {
 		purgedCSS = make(map[string]string)
 	} else if purgedCSS[htmlFilename] == "" {
+		slog.Debug("running purgecss", "html", htmlFilename, "css", cssFilename)
 		bytes, err := exec.Command("bun", "./node_modules/.bin/purgecss", "--css", cssFilename, "--content", htmlFilename).Output()
 		if err != nil {
 			return "", errors.WithMessage(err, "failed running `purgecss` command")
@@ -428,6 +431,7 @@ func build() error {
 	if err := mkdirp(outDir, "post"); err != nil {
 		return errors.WithMessage(err, "could not create post output directory")
 	}
+	slog.Debug("reading posts")
 	posts, tags, err := readPosts("content", "post", outDir)
 	if err != nil {
 		return err
@@ -437,6 +441,7 @@ func build() error {
 		if err := mkdirp(outDir, "post", post.Basename); err != nil {
 			return errors.WithMessage(err, "could not create directory for post")
 		}
+		slog.Debug("rendering post", "post", post.Basename)
 		output, err := renderPost(post, *config)
 		if err != nil {
 			return errors.WithMessagef(err, "could not render post %s", post.Input)
@@ -449,6 +454,7 @@ func build() error {
 	if err := mkdirp(outDir, "tags"); err != nil {
 		return errors.WithMessage(err, "could not create directory for tags")
 	}
+	slog.Debug("rendering tags list")
 	output, err := renderTags(tags, *config)
 	if err != nil {
 		return errors.WithMessage(err, "could not render tags")
@@ -467,6 +473,7 @@ func build() error {
 		if err := mkdirp(outDir, "tags", tag); err != nil {
 			return errors.WithMessage(err, "could not create directory")
 		}
+		slog.Debug("rendering tags page", "tag", tag)
 		output, err := renderListPage(tag, *config, matchingPosts)
 		if err != nil {
 			return errors.WithMessage(err, "could not render tag page")
@@ -475,6 +482,7 @@ func build() error {
 			return err
 		}
 
+		slog.Debug("rendering tags feed", "tag", tag)
 		output, err = renderFeed(fmt.Sprintf("%s - %s", config.Title, tag), *config, matchingPosts, tag)
 		if err != nil {
 			return errors.WithMessage(err, "could not render tag feed page")
@@ -483,6 +491,8 @@ func build() error {
 			return err
 		}
 	}
+
+	slog.Debug("rendering list page")
 	listPage, err := renderListPage("", *config, posts)
 	if err != nil {
 		return errors.WithMessage(err, "could not render list page")
@@ -491,6 +501,7 @@ func build() error {
 		return err
 	}
 
+	slog.Debug("rendering feed")
 	feed, err := renderFeed(config.Title, *config, posts, "feed")
 	if err != nil {
 		return errors.WithMessage(err, "could not render feed")
@@ -499,6 +510,7 @@ func build() error {
 		return err
 	}
 
+	slog.Debug("rendering feed styles")
 	feedStyles, err := renderFeedStyles()
 	if err != nil {
 		return errors.WithMessage(err, "could not render feed styles")
@@ -507,6 +519,7 @@ func build() error {
 		return err
 	}
 
+	slog.Debug("rendering homepage")
 	homePage, err := renderHomepage(*config, posts)
 	if err != nil {
 		return errors.WithMessage(err, "could not render homepage")
@@ -515,6 +528,7 @@ func build() error {
 		return err
 	}
 
+	slog.Debug("rendering 404 page")
 	notFound, err := render404(*config)
 	if err != nil {
 		return errors.WithMessage(err, "could not render 404 page")
@@ -527,7 +541,7 @@ func build() error {
 }
 
 func main() {
-	if true {
+	if os.Getenv("DEBUG") != "" {
 		slog.SetLogLoggerLevel(slog.LevelDebug)
 	}
 	slog.Debug("starting build process")
@@ -536,7 +550,6 @@ func main() {
 		log.Panic(errors.Errorf("working directory does not exist: %v", err))
 	}
 
-	// log.SetFlags(log.Lshortfile)
 	if err := build(); err != nil {
 		switch cause := errors.Cause(err).(type) {
 		case *fs.PathError: