diff --git a/scripts/uploadImage.js b/scripts/uploadImage.js new file mode 100644 index 0000000..f9c8e3c --- /dev/null +++ b/scripts/uploadImage.js @@ -0,0 +1,25 @@ +// updateMarkdownImages.js +import fs from 'fs'; +import path from 'path'; +import { getCloudinaryImageUrl } from './imageUtils'; + + +const postsDir = './posts'; + +fs.readdirSync(postsDir).forEach((folder) => { + const markdownFiles = fs.readdirSync(path.join(postsDir, folder)).filter((file) => file.endsWith('.md')); + + markdownFiles.forEach((file) => { + const filePath = path.join(postsDir, folder, file); + let content = fs.readFileSync(filePath, 'utf8'); + + // Regex to find image references in markdown + const imageRegex = /!\[.*?\]\((.*?)\)/g; + content = content.replace(imageRegex, (match, p1) => { + const imageUrl = getCloudinaryImageUrl(p1, 300, 300); // Example width and height + return `![${p1}](${imageUrl})`; + }); + + fs.writeFileSync(filePath, content); + }); +});