diff --git a/build/utils.ts b/build/utils.ts index f1d6151bfc53..0c803a5bf011 100644 --- a/build/utils.ts +++ b/build/utils.ts @@ -311,6 +311,11 @@ export function makeTOC(doc) { } export function findPostFileBySlug(slug: string): string | null { + if (!BLOG_ROOT) { + console.warn("'BLOG_ROOT' not set in .env file"); + return null; + } + try { const { stdout, stderr, status } = spawnSync(rgPath, [ "-il", @@ -320,8 +325,12 @@ export function findPostFileBySlug(slug: string): string | null { if (status === 0) { const file = stdout.toString("utf-8").split("\n")[0]; return file; + } + const message = stderr.toString(); + if (message) { + console.error(`error running rg: ${message}`); } else { - console.error(`error running rg: ${stderr}`); + console.error(`Post ${slug} not found in ${BLOG_ROOT}`); } } catch { console.error("rg failed");