all repos — website @ aa2ac7ea0c3c72c03cf6df51e04c0f149654777e

My website

wrap os.MkdirAll
Alan Pearce alan@alanpearce.eu
Tue, 16 Apr 2024 19:52:06 +0200
commit

aa2ac7ea0c3c72c03cf6df51e04c0f149654777e

parent

224d1b31b9d37b43b7c9113c2c1e5d9c4394e43c

1 files changed, 9 insertions(+), 6 deletions(-)

jump to
M cmd/build/main.gocmd/build/main.go
@@ -402,6 +402,10 @@ }) 	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 @@ if err != nil { 		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 @@ return err 	}
 
 	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 @@ return err 		}
 	}
 
-	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 @@ if slices.Contains(post.Taxonomies.Tags, tag) { 				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)