From 5a5259cdff1d39afc194520ed9c36f55dfadcc4f Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Fri, 2 Nov 2018 17:33:17 -0400 Subject: [PATCH] Adjust post content image srcs when using --addcontentimages --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a57a38f..e02f5be 100644 --- a/index.js +++ b/index.js @@ -187,8 +187,15 @@ function getPostDate(post) { } function getPostContent(post, turndownService) { - let encoded = post.encoded[0].trim(); - content = turndownService.turndown(encoded) + let content = post.encoded[0].trim(); + + if (argv.addcontentimages) { + // writeImageFile() will save all content images to a relative /images folder + // so update references in post content to match + content = content.replace(/src=".*?([^\/"]+\.(gif|jpg|png))"/gi, 'src="images/$1"'); + } + + content = turndownService.turndown(content) .replace(/-\s+/g, '- '); // clean up extra spaces return content;