From 65112e5cb0379e5588baf6acbe998e59eace90c5 Mon Sep 17 00:00:00 2001 From: Uncle Pi <69907326+UnclePi979@users.noreply.github.com> Date: Tue, 11 Mar 2025 20:59:18 +0800 Subject: [PATCH] feat: add directory creation for post folder - Implement recursive directory creation for post folder - Ensure that parent directories are created if they don't exist --- scripts/new-post.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/new-post.js b/scripts/new-post.js index 41a0569..2531390 100644 --- a/scripts/new-post.js +++ b/scripts/new-post.js @@ -36,6 +36,12 @@ if (fs.existsSync(fullPath)) { process.exit(1) } +// recursive mode creates multi-level directories +const dirPath = path.dirname(fullPath) +if (!fs.existsSync(dirPath)) { + fs.mkdirSync(dirPath, { recursive: true }) +} + const content = `--- title: ${args[0]} published: ${getDate()}