diff options
author | Alan Pearce | 2024-04-16 19:52:06 +0200 |
---|---|---|
committer | Alan Pearce | 2024-04-16 20:49:28 +0200 |
commit | aa2ac7ea0c3c72c03cf6df51e04c0f149654777e (patch) | |
tree | 09f834bf268031c327fe7779e5d6534f4e2e3477 | |
parent | 224d1b31b9d37b43b7c9113c2c1e5d9c4394e43c (diff) | |
download | website-aa2ac7ea0c3c72c03cf6df51e04c0f149654777e.tar.lz website-aa2ac7ea0c3c72c03cf6df51e04c0f149654777e.tar.zst website-aa2ac7ea0c3c72c03cf6df51e04c0f149654777e.zip |
wrap os.MkdirAll
-rw-r--r-- | cmd/build/main.go | 15 |
1 files 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) |