wip
This commit is contained in:
54
scripts/wrap-products.ts
Normal file
54
scripts/wrap-products.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const locales = ['en', 'de'];
|
||||
|
||||
locales.forEach(locale => {
|
||||
const productsDir = path.join(process.cwd(), 'data', 'products', locale);
|
||||
if (!fs.existsSync(productsDir)) return;
|
||||
const files = fs.readdirSync(productsDir).filter(f => f.endsWith('.mdx'));
|
||||
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(productsDir, file);
|
||||
let content = fs.readFileSync(filePath, 'utf8');
|
||||
|
||||
// Find the end of frontmatter
|
||||
const parts = content.split('---');
|
||||
if (parts.length < 3) return;
|
||||
|
||||
const frontmatter = parts[1];
|
||||
let body = parts.slice(2).join('---').trim();
|
||||
|
||||
// Find the ProductTechnicalData component
|
||||
const techDataMatch = body.match(/<ProductTechnicalData[\s\S]*?\/>/);
|
||||
if (!techDataMatch) {
|
||||
console.log(`No ProductTechnicalData found in ${locale}/${file}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const techData = techDataMatch[0];
|
||||
// Remove techData from body
|
||||
let description = body.replace(techData, '').trim();
|
||||
|
||||
// Clean up description from ProductTabs if it was already there
|
||||
description = description.replace(/<ProductTabs[^>]*>/, '').replace('</ProductTabs>', '').trim();
|
||||
|
||||
// Remove the title from description if it's there (it's usually # Title)
|
||||
description = description.replace(/^# .*\n/, '').trim();
|
||||
|
||||
// Remove any trailing "## Technical Data" or similar
|
||||
description = description.replace(/## Technical Data\s*$/, '').trim();
|
||||
description = description.replace(/## Technische Daten\s*$/, '').trim();
|
||||
|
||||
const newContent = `---${frontmatter}---
|
||||
<ProductTabs technicalData={${techData}}>
|
||||
|
||||
${description}
|
||||
|
||||
</ProductTabs>
|
||||
`;
|
||||
|
||||
fs.writeFileSync(filePath, newContent);
|
||||
console.log(`Updated ${locale}/${file}`);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user