FOR REFERENCE unfinished imageuploader script for automating image upload, may ditch that in the future

This commit is contained in:
matthieu42morin 2024-03-31 05:40:43 +02:00
parent d73bac59a8
commit 8291443c80
1 changed files with 25 additions and 0 deletions

25
scripts/uploadImage.js Normal file
View File

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