fix feed linking to localhost 🤦🏻
1 file changed, 28 insertions(+), 18 deletions(-)
changed files
M cmd/build/build.go → cmd/build/build.go
@@ -403,12 +403,7 @@ } 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 @@ if err := mkdirp(publicDir); err != nil { 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 @@ 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) - 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 @@ if err := mkdirp(publicDir, "tags"); err != nil { 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 @@ if err := mkdirp(publicDir, "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) + output, err := renderListPage(tag, config, matchingPosts) if err != nil { return errors.WithMessage(err, "could not render tag page") }@@ -481,7 +476,7 @@ return err } 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 @@ } } 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 @@ return err } 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 @@ return err } 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 @@ return err } 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 @@ 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 @@ } 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 @@ if err != nil { 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")