diff options
author | Alan Pearce | 2024-04-21 21:55:23 +0200 |
---|---|---|
committer | Alan Pearce | 2024-04-21 21:55:23 +0200 |
commit | 1573550c7792a0403c2b4fa0959bd349c5f945df (patch) | |
tree | 19592c3f7b6ec438eac7a50adb174dfc987b10d6 /cmd/build | |
parent | a10c8466b4bf81f9ddd356a2da90e8e5e9b360a5 (diff) | |
download | website-1573550c7792a0403c2b4fa0959bd349c5f945df.tar.lz website-1573550c7792a0403c2b4fa0959bd349c5f945df.tar.zst website-1573550c7792a0403c2b4fa0959bd349c5f945df.zip |
fix feed linking to localhost 🤦🏻
Diffstat (limited to 'cmd/build')
-rw-r--r-- | cmd/build/build.go | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/cmd/build/build.go b/cmd/build/build.go index 121d5aa..254eff2 100644 --- a/cmd/build/build.go +++ b/cmd/build/build.go @@ -403,12 +403,7 @@ func outputToFile(output io.Reader, filename ...string) error { return nil } -func build(outDir string) error { - config, err := config.GetConfig() - if err != nil { - return err - } - +func build(outDir string, config config.Config) error { privateDir := path.Join(outDir, "private") if err := mkdirp(privateDir); err != nil { return errors.Errorf("could not create private directory: %w", err) @@ -418,7 +413,7 @@ func build(outDir string) error { return errors.Errorf("could not create public directory: %w", err) } - err = cp.Copy("static", publicDir, cp.Options{ + err := cp.Copy("static", publicDir, cp.Options{ PreserveTimes: true, PermissionControl: cp.AddPermission(0755), }) @@ -440,7 +435,7 @@ func build(outDir string) error { return errors.WithMessage(err, "could not create directory for post") } slog.Debug("rendering post", "post", post.Basename) - output, err := renderPost(post, *config) + output, err := renderPost(post, config) if err != nil { return errors.WithMessagef(err, "could not render post %s", post.Input) } @@ -453,7 +448,7 @@ func build(outDir string) error { return errors.WithMessage(err, "could not create directory for tags") } slog.Debug("rendering tags list") - output, err := renderTags(tags, *config) + output, err := renderTags(tags, config) if err != nil { return errors.WithMessage(err, "could not render tags") } @@ -472,7 +467,7 @@ func build(outDir string) error { return errors.WithMessage(err, "could not create directory") } slog.Debug("rendering tags page", "tag", tag) - output, err := renderListPage(tag, *config, matchingPosts) + output, err := renderListPage(tag, config, matchingPosts) if err != nil { return errors.WithMessage(err, "could not render tag page") } @@ -481,7 +476,7 @@ func build(outDir string) error { } slog.Debug("rendering tags feed", "tag", tag) - output, err = renderFeed(fmt.Sprintf("%s - %s", config.Title, tag), *config, matchingPosts, 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") } @@ -491,7 +486,7 @@ func build(outDir string) error { } slog.Debug("rendering list page") - listPage, err := renderListPage("", *config, posts) + listPage, err := renderListPage("", config, posts) if err != nil { return errors.WithMessage(err, "could not render list page") } @@ -500,7 +495,7 @@ func build(outDir string) error { } slog.Debug("rendering feed") - feed, err := renderFeed(config.Title, *config, posts, "feed") + feed, err := renderFeed(config.Title, config, posts, "feed") if err != nil { return errors.WithMessage(err, "could not render feed") } @@ -518,7 +513,7 @@ func build(outDir string) error { } slog.Debug("rendering homepage") - homePage, err := renderHomepage(*config, posts) + homePage, err := renderHomepage(config, posts) if err != nil { return errors.WithMessage(err, "could not render homepage") } @@ -527,7 +522,7 @@ func build(outDir string) error { } slog.Debug("rendering 404 page") - notFound, err := render404(*config) + notFound, err := render404(config) if err != nil { return errors.WithMessage(err, "could not render 404 page") } @@ -541,6 +536,7 @@ func build(outDir string) error { type IOConfig struct { Source string `conf:"default:.,short:s"` Destination string `conf:"default:website,short:d"` + BaseURL config.URL } func main() { @@ -550,7 +546,13 @@ func main() { slog.Debug("starting build process") ioConfig := IOConfig{} - conf.Parse("", &ioConfig) + if help, err := conf.Parse("", &ioConfig); err != nil { + if errors.Is(err, conf.ErrHelpWanted) { + fmt.Println(help) + os.Exit(1) + } + log.Panicf("parsing I/O configuration: %v", err) + } if ioConfig.Source != "." { err := os.Chdir(ioConfig.Source) @@ -558,12 +560,20 @@ func main() { log.Panic("could not change to source directory") } } - err := os.RemoveAll(ioConfig.Destination) + + config, err := config.GetConfig() + if err != nil { + log.Panic(errors.Errorf("could not get config: %v", err)) + } + + config.BaseURL = ioConfig.BaseURL + + err = os.RemoveAll(ioConfig.Destination) if err != nil { log.Panic(errors.Errorf("could not remove public directory: %v", err)) } - if err := build(ioConfig.Destination); err != nil { + if err := build(ioConfig.Destination, *config); err != nil { switch cause := errors.Cause(err).(type) { case *fs.PathError: slog.Info("pathError") |