From c546cd47caf19debce3721fbc0382b9aac977cfa Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Sat, 15 Feb 2025 10:23:18 -0500 Subject: [PATCH] Show slug fallback when writing --- src/shared.js | 6 +++++- src/writer.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/shared.js b/src/shared.js index 4e0ae75..38316af 100644 --- a/src/shared.js +++ b/src/shared.js @@ -7,6 +7,10 @@ export function camelCase(str) { return str.replace(/-(.)/g, (match) => match[1].toUpperCase()); } +export function getSlugWithFallback(post) { + return post.slug ? post.slug : 'id-' + post.id; +} + export function buildPostPath(post, overrideConfig) { const pathConfig = overrideConfig ?? config; @@ -35,7 +39,7 @@ export function buildPostPath(post, overrideConfig) { } // get slug with fallback - let slug = post.slug ? post.slug : 'id-' + post.id; + let slug = getSlugWithFallback(post); // prepend date to slug as appropriate if (pathConfig.prefixDate && post.date) { diff --git a/src/writer.js b/src/writer.js index 0c16f46..796a445 100644 --- a/src/writer.js +++ b/src/writer.js @@ -55,7 +55,7 @@ async function writeMarkdownFilesPromise(posts) { const payload = { item: post, type: post.type, - name: post.slug, + name: shared.getSlugWithFallback(post), destinationPath, delay };