FOR REFERENCE unfinished imageuploader script for automating image upload, may ditch that in the future
This commit is contained in:
parent
d73bac59a8
commit
8291443c80
|
@ -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);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue