sheets
This commit is contained in:
@@ -25,11 +25,11 @@ const CONFIG = {
|
||||
} as const;
|
||||
|
||||
const EXCEL_FILES = [
|
||||
path.join(process.cwd(), 'data/excel/high-voltage.xlsx'),
|
||||
path.join(process.cwd(), 'data/excel/medium-voltage-KM.xlsx'),
|
||||
path.join(process.cwd(), 'data/excel/medium-voltage-KM 170126.xlsx'),
|
||||
path.join(process.cwd(), 'data/excel/low-voltage-KM.xlsx'),
|
||||
path.join(process.cwd(), 'data/excel/solar-cables.xlsx'),
|
||||
{ path: path.join(process.cwd(), 'data/excel/high-voltage.xlsx'), voltageType: 'high-voltage' },
|
||||
{ path: path.join(process.cwd(), 'data/excel/medium-voltage-KM.xlsx'), voltageType: 'medium-voltage' },
|
||||
{ path: path.join(process.cwd(), 'data/excel/medium-voltage-KM 170126.xlsx'), voltageType: 'medium-voltage' },
|
||||
{ path: path.join(process.cwd(), 'data/excel/low-voltage-KM.xlsx'), voltageType: 'low-voltage' },
|
||||
{ path: path.join(process.cwd(), 'data/excel/solar-cables.xlsx'), voltageType: 'solar' },
|
||||
] as const;
|
||||
|
||||
type MdxProduct = {
|
||||
@@ -144,12 +144,12 @@ function readDesignationsFromExcelFile(filePath: string): Map<string, string> {
|
||||
return out;
|
||||
}
|
||||
|
||||
function loadAllExcelDesignations(): Map<string, string> {
|
||||
const out = new Map<string, string>();
|
||||
for (const filePath of EXCEL_FILES) {
|
||||
const m = readDesignationsFromExcelFile(filePath);
|
||||
function loadAllExcelDesignations(): Map<string, { designation: string; voltageType: string }> {
|
||||
const out = new Map<string, { designation: string; voltageType: string }>();
|
||||
for (const file of EXCEL_FILES) {
|
||||
const m = readDesignationsFromExcelFile(file.path);
|
||||
Array.from(m.entries()).forEach(([k, v]) => {
|
||||
if (!out.has(k)) out.set(k, v);
|
||||
if (!out.has(k)) out.set(k, { designation: v, voltageType: file.voltageType });
|
||||
});
|
||||
}
|
||||
return out;
|
||||
@@ -162,10 +162,10 @@ async function loadProductsFromExcelAndMdx(locale: 'en' | 'de'): Promise<Product
|
||||
const products: ProductData[] = [];
|
||||
let id = 1;
|
||||
|
||||
Array.from(excelDesignations.entries()).forEach(([key, designation]) => {
|
||||
Array.from(excelDesignations.entries()).forEach(([key, data]) => {
|
||||
const mdx = mdxIndex.get(key) || null;
|
||||
|
||||
const title = mdx?.title || designation;
|
||||
const title = mdx?.title || data.designation;
|
||||
const slug =
|
||||
mdx?.slug ||
|
||||
title
|
||||
@@ -191,6 +191,7 @@ async function loadProductsFromExcelAndMdx(locale: 'en' | 'de'): Promise<Product
|
||||
locale,
|
||||
categories: (mdx?.categories || []).map(name => ({ name })),
|
||||
attributes: [],
|
||||
voltageType: data.voltageType,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -209,8 +210,18 @@ async function processChunk(products: ProductData[], chunkIndex: number, totalCh
|
||||
const locale = (product.locale || 'en') as 'en' | 'de';
|
||||
const buffer = await generateDatasheetPdfBuffer({ product, locale });
|
||||
const fileName = generateFileName(product, locale);
|
||||
fs.writeFileSync(path.join(CONFIG.outputDir, fileName), buffer);
|
||||
console.log(`✓ ${locale.toUpperCase()}: ${fileName}`);
|
||||
|
||||
// Determine subfolder based on voltage type
|
||||
const voltageType = (product as any).voltageType || 'other';
|
||||
const subfolder = path.join(CONFIG.outputDir, voltageType);
|
||||
|
||||
// Create subfolder if it doesn't exist
|
||||
if (!fs.existsSync(subfolder)) {
|
||||
fs.mkdirSync(subfolder, { recursive: true });
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.join(subfolder, fileName), buffer);
|
||||
console.log(`✓ ${locale.toUpperCase()}: ${voltageType}/${fileName}`);
|
||||
await new Promise(resolve => setTimeout(resolve, 25));
|
||||
} catch (error) {
|
||||
console.error(`✗ Failed to process product ${product.id}:`, error);
|
||||
|
||||
Reference in New Issue
Block a user