73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import * as path from 'path';
|
|
|
|
import type { ProductData } from './types';
|
|
|
|
export const CONFIG = {
|
|
siteUrl: 'https://klz-cables.com',
|
|
publicDir: path.join(process.cwd(), 'public'),
|
|
assetMapFile: path.join(process.cwd(), 'data/processed/asset-map.json'),
|
|
} as const;
|
|
|
|
export function stripHtml(html: string): string {
|
|
if (!html) return '';
|
|
let text = String(html).replace(/<[^>]*>/g, '').normalize('NFC');
|
|
text = text
|
|
.replace(/[\u00A0\u202F]/g, ' ')
|
|
.replace(/[\u2013\u2014]/g, '-')
|
|
.replace(/[\u2018\u2019]/g, "'")
|
|
.replace(/[\u201C\u201D]/g, '"')
|
|
.replace(/\u2026/g, '...')
|
|
.replace(/[\u2022]/g, '·')
|
|
.replace(/[\u2264]/g, '<=')
|
|
.replace(/[\u2265]/g, '>=')
|
|
.replace(/[\u2248]/g, '~')
|
|
.replace(/[\u03A9\u2126]/g, 'Ohm')
|
|
.replace(/[\u00B5\u03BC]/g, 'u')
|
|
.replace(/[\u2193]/g, 'v')
|
|
.replace(/[\u2191]/g, '^')
|
|
.replace(/[\u00B0]/g, '°');
|
|
// eslint-disable-next-line no-control-regex
|
|
text = text.replace(/[\u0000-\u001F\u007F]/g, '');
|
|
return text.replace(/\s+/g, ' ').trim();
|
|
}
|
|
|
|
export function normalizeValue(value: string): string {
|
|
return stripHtml(value).replace(/\s+/g, ' ').trim();
|
|
}
|
|
|
|
export function getProductUrl(product: ProductData): string {
|
|
if (product.path) return `${CONFIG.siteUrl}${product.path}`;
|
|
return CONFIG.siteUrl;
|
|
}
|
|
|
|
export function generateFileName(product: ProductData, locale: 'en' | 'de'): string {
|
|
const baseName = product.slug || product.translationKey || `product-${product.id}`;
|
|
const cleanSlug = baseName
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9-]/g, '-')
|
|
.replace(/-+/g, '-')
|
|
.replace(/^-|-$/g, '');
|
|
return `${cleanSlug}-${locale}.pdf`;
|
|
}
|
|
|
|
export function getLabels(locale: 'en' | 'de') {
|
|
return {
|
|
en: {
|
|
datasheet: 'PRODUCT DATASHEET',
|
|
description: 'DESCRIPTION',
|
|
technicalData: 'TECHNICAL DATA',
|
|
crossSection: 'CROSS-SECTION DATA',
|
|
sku: 'SKU',
|
|
noImage: 'No image available',
|
|
},
|
|
de: {
|
|
datasheet: 'PRODUKTDATENBLATT',
|
|
description: 'BESCHREIBUNG',
|
|
technicalData: 'TECHNISCHE DATEN',
|
|
crossSection: 'QUERSCHNITTSDATEN',
|
|
sku: 'ARTIKELNUMMER',
|
|
noImage: 'Kein Bild verfügbar',
|
|
},
|
|
}[locale];
|
|
}
|