// 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); }); });