split output directories into website/{public,private}
1 file changed, 32 insertions(+), 21 deletions(-)
changed files
M cmd/build/build.go → cmd/build/build.go
@@ -408,17 +408,35 @@ config, err := config.GetConfig() 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 @@ return err } } - 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 @@ output, err := renderTags(tags, *config) 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 @@ if slices.Contains(post.Taxonomies.Tags, tag) { 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 @@ output, err := renderListPage(tag, *config, matchingPosts) 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 @@ 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") } - 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 @@ listPage, err := renderListPage("", *config, posts) 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 @@ feed, err := renderFeed(config.Title, *config, posts, "feed") 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 @@ feedStyles, err := renderFeedStyles() 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 @@ homePage, err := renderHomepage(*config, posts) 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 @@ notFound, err := render404(*config) 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 @@ } 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() {@@ -543,13 +561,6 @@ } err := os.RemoveAll(ioConfig.Destination) 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 {