feat: migrate Payload CMS to MDX and harden static infrastructure
This commit is contained in:
26
scripts/fix-media-urls.ts
Normal file
26
scripts/fix-media-urls.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
function walk(dir: string, callback: (filePath: string) => void) {
|
||||
const files = fs.readdirSync(dir);
|
||||
for (const file of files) {
|
||||
const filePath = path.join(dir, file);
|
||||
if (fs.statSync(filePath).isDirectory()) {
|
||||
walk(filePath, callback);
|
||||
} else if (filePath.endsWith('.mdx') || filePath.endsWith('.md')) {
|
||||
callback(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let replacedCount = 0;
|
||||
walk(path.join(process.cwd(), 'content'), (filePath) => {
|
||||
let content = fs.readFileSync(filePath, 'utf8');
|
||||
if (content.includes('/api/media/file/')) {
|
||||
content = content.replace(/\/api\/media\/file\//g, '/media/');
|
||||
fs.writeFileSync(filePath, content, 'utf8');
|
||||
replacedCount++;
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`Successfully fixed media URLs in ${replacedCount} files.`);
|
||||
Reference in New Issue
Block a user