wip
This commit is contained in:
32
scripts/fetch-all-posts.js
Normal file
32
scripts/fetch-all-posts.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
const blogDir = path.join(process.cwd(), 'data', 'blog', 'en');
|
||||
const outputDir = path.join(process.cwd(), 'reference', 'klz-cables-clone', 'posts');
|
||||
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(blogDir);
|
||||
|
||||
files.forEach(file => {
|
||||
if (!file.endsWith('.mdx')) return;
|
||||
|
||||
const slug = file.replace('.mdx', '');
|
||||
const url = `https://klz-cables.com/${slug}/`;
|
||||
const outputPath = path.join(outputDir, `${slug}.html`);
|
||||
|
||||
if (fs.existsSync(outputPath)) {
|
||||
console.log(`Skipping ${slug}, already exists.`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Fetching ${slug}...`);
|
||||
try {
|
||||
execSync(`curl -L -s "${url}" -o "${outputPath}"`);
|
||||
} catch (e) {
|
||||
console.error(`Failed to fetch ${slug}: ${e.message}`);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user