33 lines
888 B
JavaScript
33 lines
888 B
JavaScript
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}`);
|
|
}
|
|
});
|