fix(pdf): fix Lexical AST text extraction to prevent [object Object] in datasheets
All checks were successful
Build & Deploy / 🔍 Prepare (push) Successful in 10s
Build & Deploy / 🧪 QA (push) Successful in 1m11s
Build & Deploy / 🏗️ Build (push) Successful in 2m17s
Build & Deploy / 🚀 Deploy (push) Successful in 15s
Build & Deploy / 🧪 Post-Deploy Verification (push) Successful in 1m14s
Build & Deploy / 🔔 Notify (push) Successful in 3s
Nightly QA / 💨 Smoke & Health (push) Successful in 1m6s
All checks were successful
Build & Deploy / 🔍 Prepare (push) Successful in 10s
Build & Deploy / 🧪 QA (push) Successful in 1m11s
Build & Deploy / 🏗️ Build (push) Successful in 2m17s
Build & Deploy / 🚀 Deploy (push) Successful in 15s
Build & Deploy / 🧪 Post-Deploy Verification (push) Successful in 1m14s
Build & Deploy / 🔔 Notify (push) Successful in 3s
Nightly QA / 💨 Smoke & Health (push) Successful in 1m6s
This commit is contained in:
@@ -63,9 +63,25 @@ function normalizeExcelKey(value: string): string {
|
||||
.replace(/[^A-Z0-9]+/g, '');
|
||||
}
|
||||
|
||||
function extractDescriptionFromMdxFrontmatter(data: any): string {
|
||||
const description = normalizeValue(String(data?.description || ''));
|
||||
return description;
|
||||
function extractTextFromLexicalOrUnknown(val: unknown): string {
|
||||
if (!val) return '';
|
||||
if (typeof val === 'string') {
|
||||
if (val === '[object Object]') return '';
|
||||
return val.trim();
|
||||
}
|
||||
if (typeof val === 'object') {
|
||||
const obj = val as any;
|
||||
if (obj.text && typeof obj.text === 'string') {
|
||||
return obj.text.trim();
|
||||
}
|
||||
if (Array.isArray(obj.children)) {
|
||||
return obj.children.map(extractTextFromLexicalOrUnknown).filter(Boolean).join(' ').trim();
|
||||
}
|
||||
if (obj.root && typeof obj.root === 'object') {
|
||||
return extractTextFromLexicalOrUnknown(obj.root);
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function parseMdxFileSafely(
|
||||
@@ -94,8 +110,8 @@ function parseMdxFileSafely(
|
||||
title = normalizeValue(String(data.title || ''));
|
||||
sku = normalizeValue(String(data.sku || ''));
|
||||
slug = data.slug || slug;
|
||||
descriptionHtml = extractDescriptionFromMdxFrontmatter(data);
|
||||
applicationHtml = normalizeValue(String(data?.application || ''));
|
||||
descriptionHtml = normalizeValue(extractTextFromLexicalOrUnknown(data?.description));
|
||||
applicationHtml = normalizeValue(extractTextFromLexicalOrUnknown(data?.application));
|
||||
if (Array.isArray(data.categories)) {
|
||||
for (const c of data.categories) {
|
||||
const val = normalizeValue(typeof c === 'string' ? c : String(c?.category || ''));
|
||||
@@ -120,10 +136,15 @@ function parseMdxFileSafely(
|
||||
if (slugMatch) slug = normalizeValue(slugMatch[1]);
|
||||
|
||||
const descMatch = raw.match(
|
||||
/^description:\s*(?:>|>-)?\s*\n([\s\S]*?)(?=\n[a-zA-Z0-9_-]+:|\n---)/,
|
||||
/^description:\s*(?:>|>-)?\s*\n([\s\S]*?)(?=\n[a-zA-Z0-9_-]+:|\n---)/m,
|
||||
);
|
||||
if (descMatch) descriptionHtml = normalizeValue(descMatch[1].replace(/\n\s*/g, ' ').trim());
|
||||
|
||||
const appMatch = raw.match(
|
||||
/^application:\s*(?:>|>-)?\s*\n([\s\S]*?)(?=\n[a-zA-Z0-9_-]+:|\n---)/m,
|
||||
);
|
||||
if (appMatch) applicationHtml = normalizeValue(appMatch[1].replace(/\n\s*/g, ' ').trim());
|
||||
|
||||
const catMatches = Array.from(raw.matchAll(/category:\s*(.+)$/gm));
|
||||
for (const cm of catMatches) {
|
||||
const val = normalizeValue(cm[1]);
|
||||
@@ -137,6 +158,13 @@ function parseMdxFileSafely(
|
||||
}
|
||||
}
|
||||
|
||||
if (!applicationHtml && descriptionHtml) {
|
||||
applicationHtml = descriptionHtml;
|
||||
}
|
||||
if (!descriptionHtml && applicationHtml) {
|
||||
descriptionHtml = applicationHtml;
|
||||
}
|
||||
|
||||
if (!title) {
|
||||
title = path.basename(fileName, '.mdx').toUpperCase();
|
||||
}
|
||||
@@ -146,9 +174,9 @@ function parseMdxFileSafely(
|
||||
|
||||
function buildMdxIndex(locale: 'en' | 'de'): MdxIndex {
|
||||
const candidateDirs = [
|
||||
path.join(process.cwd(), 'content/products'),
|
||||
path.join(process.cwd(), 'data/products', locale),
|
||||
path.join(process.cwd(), 'data/products/de'),
|
||||
path.join(process.cwd(), 'content/products'),
|
||||
];
|
||||
const dir = candidateDirs.find((d) => fs.existsSync(d));
|
||||
const idx: MdxIndex = new Map();
|
||||
|
||||
Reference in New Issue
Block a user