about summary refs log tree commit diff stats
path: root/cmd/build/build.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/build/build.go')
-rw-r--r--cmd/build/build.go53
1 files changed, 32 insertions, 21 deletions
diff --git a/cmd/build/build.go b/cmd/build/build.go
index ea611aa..121d5aa 100644
--- a/cmd/build/build.go
+++ b/cmd/build/build.go
@@ -408,17 +408,35 @@ func build(outDir string) error {
 	if err != nil {
 		return err
 	}
-	if err := mkdirp(outDir, "post"); err != nil {
+
+	privateDir := path.Join(outDir, "private")
+	if err := mkdirp(privateDir); err != nil {
+		return errors.Errorf("could not create private directory: %w", err)
+	}
+	publicDir := path.Join(outDir, "public")
+	if err := mkdirp(publicDir); err != nil {
+		return errors.Errorf("could not create public directory: %w", err)
+	}
+
+	err = cp.Copy("static", publicDir, cp.Options{
+		PreserveTimes:     true,
+		PermissionControl: cp.AddPermission(0755),
+	})
+	if err != nil {
+		log.Panic(errors.Errorf("could not copy static files: %v", err))
+	}
+
+	if err := mkdirp(publicDir, "post"); err != nil {
 		return errors.WithMessage(err, "could not create post output directory")
 	}
 	slog.Debug("reading posts")
-	posts, tags, err := readPosts("content", "post", outDir)
+	posts, tags, err := readPosts("content", "post", publicDir)
 	if err != nil {
 		return err
 	}
 
 	for _, post := range posts {
-		if err := mkdirp(outDir, "post", post.Basename); err != nil {
+		if err := mkdirp(publicDir, "post", post.Basename); err != nil {
 			return errors.WithMessage(err, "could not create directory for post")
 		}
 		slog.Debug("rendering post", "post", post.Basename)
@@ -431,7 +449,7 @@ func build(outDir string) error {
 		}
 	}
 
-	if err := mkdirp(outDir, "tags"); err != nil {
+	if err := mkdirp(publicDir, "tags"); err != nil {
 		return errors.WithMessage(err, "could not create directory for tags")
 	}
 	slog.Debug("rendering tags list")
@@ -439,7 +457,7 @@ func build(outDir string) error {
 	if err != nil {
 		return errors.WithMessage(err, "could not render tags")
 	}
-	if err := outputToFile(output, outDir, "tags", "index.html"); err != nil {
+	if err := outputToFile(output, publicDir, "tags", "index.html"); err != nil {
 		return err
 	}
 
@@ -450,7 +468,7 @@ func build(outDir string) error {
 				matchingPosts = append(matchingPosts, post)
 			}
 		}
-		if err := mkdirp(outDir, "tags", tag); err != nil {
+		if err := mkdirp(publicDir, "tags", tag); err != nil {
 			return errors.WithMessage(err, "could not create directory")
 		}
 		slog.Debug("rendering tags page", "tag", tag)
@@ -458,7 +476,7 @@ func build(outDir string) error {
 		if err != nil {
 			return errors.WithMessage(err, "could not render tag page")
 		}
-		if err := outputToFile(output, outDir, "tags", tag, "index.html"); err != nil {
+		if err := outputToFile(output, publicDir, "tags", tag, "index.html"); err != nil {
 			return err
 		}
 
@@ -467,7 +485,7 @@ func build(outDir string) error {
 		if err != nil {
 			return errors.WithMessage(err, "could not render tag feed page")
 		}
-		if err := outputToFile(output, outDir, "tags", tag, "atom.xml"); err != nil {
+		if err := outputToFile(output, publicDir, "tags", tag, "atom.xml"); err != nil {
 			return err
 		}
 	}
@@ -477,7 +495,7 @@ func build(outDir string) error {
 	if err != nil {
 		return errors.WithMessage(err, "could not render list page")
 	}
-	if err := outputToFile(listPage, outDir, "post", "index.html"); err != nil {
+	if err := outputToFile(listPage, publicDir, "post", "index.html"); err != nil {
 		return err
 	}
 
@@ -486,7 +504,7 @@ func build(outDir string) error {
 	if err != nil {
 		return errors.WithMessage(err, "could not render feed")
 	}
-	if err := outputToFile(feed, outDir, "atom.xml"); err != nil {
+	if err := outputToFile(feed, publicDir, "atom.xml"); err != nil {
 		return err
 	}
 
@@ -495,7 +513,7 @@ func build(outDir string) error {
 	if err != nil {
 		return errors.WithMessage(err, "could not render feed styles")
 	}
-	if err := outputToFile(feedStyles, outDir, "feed-styles.xsl"); err != nil {
+	if err := outputToFile(feedStyles, publicDir, "feed-styles.xsl"); err != nil {
 		return err
 	}
 
@@ -504,7 +522,7 @@ func build(outDir string) error {
 	if err != nil {
 		return errors.WithMessage(err, "could not render homepage")
 	}
-	if err := outputToFile(homePage, outDir, "index.html"); err != nil {
+	if err := outputToFile(homePage, publicDir, "index.html"); err != nil {
 		return err
 	}
 
@@ -513,7 +531,7 @@ func build(outDir string) error {
 	if err != nil {
 		return errors.WithMessage(err, "could not render 404 page")
 	}
-	if err := outputToFile(notFound, outDir, "404.html"); err != nil {
+	if err := outputToFile(notFound, privateDir, "404.html"); err != nil {
 		return err
 	}
 
@@ -522,7 +540,7 @@ func build(outDir string) error {
 
 type IOConfig struct {
 	Source      string `conf:"default:.,short:s"`
-	Destination string `conf:"default:public,short:d"`
+	Destination string `conf:"default:website,short:d"`
 }
 
 func main() {
@@ -544,13 +562,6 @@ func main() {
 	if err != nil {
 		log.Panic(errors.Errorf("could not remove public directory: %v", err))
 	}
-	err = cp.Copy(path.Join(ioConfig.Source, "static"), ioConfig.Destination, cp.Options{
-		PreserveTimes:     true,
-		PermissionControl: cp.AddPermission(0755),
-	})
-	if err != nil {
-		log.Panic(errors.Errorf("could not copy static files: %v", err))
-	}
 
 	if err := build(ioConfig.Destination); err != nil {
 		switch cause := errors.Cause(err).(type) {