From aa2ac7ea0c3c72c03cf6df51e04c0f149654777e Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Tue, 16 Apr 2024 19:52:06 +0200 Subject: wrap os.MkdirAll --- cmd/build/main.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cmd/build/main.go b/cmd/build/main.go index 81d31e9..ad905fd 100644 --- a/cmd/build/main.go +++ b/cmd/build/main.go @@ -402,6 +402,10 @@ func renderFeedStyles() (io.Reader, error) { return strings.NewReader(doc.OutputXML(true)), nil } +func mkdirp(dirs ...string) error { + return os.MkdirAll(path.Join(dirs...), 0755) +} + func outputToFile(output io.Reader, filename ...string) error { file, err := os.OpenFile(path.Join(filename...), os.O_WRONLY|os.O_CREATE, 00644) if err != nil { @@ -421,7 +425,7 @@ func build() error { return err } outDir := "new" - if err := os.MkdirAll(path.Join(outDir, "post"), 0755); err != nil { + if err := mkdirp(outDir, "post"); err != nil { return errors.WithMessage(err, "could not create post output directory") } posts, tags, err := readPosts("content", "post", outDir) @@ -430,9 +434,8 @@ func build() error { } for _, post := range posts { - dst := path.Join(outDir, "post", post.Basename) - if err := os.MkdirAll(dst, 0755); err != nil { - return errors.WithMessagef(err, "could not create directory for post %s", dst) + if err := mkdirp(outDir, "post", post.Basename); err != nil { + return errors.WithMessage(err, "could not create directory for post") } output, err := renderPost(post, *config) if err != nil { @@ -443,7 +446,7 @@ func build() error { } } - if err := os.MkdirAll(path.Join(outDir, "tags"), 0755); err != nil { + if err := mkdirp(outDir, "tags"); err != nil { return errors.WithMessage(err, "could not create directory for tags") } output, err := renderTags(tags, *config) @@ -461,7 +464,7 @@ func build() error { matchingPosts = append(matchingPosts, post) } } - if err := os.MkdirAll(path.Join(outDir, "tags", tag), 0755); err != nil { + if err := mkdirp(outDir, "tags", tag); err != nil { return errors.WithMessage(err, "could not create directory") } output, err := renderListPage(tag, *config, matchingPosts) -- cgit 1.4.1