feat(edit): 采集插件、编辑页SKU 属性动态展示、颜色展示开发
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
type OzonPageJsonFetcher,
|
||||
} from './ozon-parser.js';
|
||||
import { collectPlatformDomAssets } from './product-media.js';
|
||||
import { formatCollectedDescription } from './description-format.js';
|
||||
|
||||
type SourcePlatform = '1688' | 'taobao' | 'tmall' | 'ozon';
|
||||
type Json = Record<string, unknown>;
|
||||
@@ -112,7 +113,7 @@ function collect1688(root: Document, pageUrl: string, bridgedState?: unknown): C
|
||||
axes,
|
||||
uniqueVariants(variants),
|
||||
evidence,
|
||||
'1688-structured-2.0.0',
|
||||
'1688-structured-2.0.1',
|
||||
state,
|
||||
);
|
||||
}
|
||||
@@ -187,7 +188,7 @@ function collectTaobao(
|
||||
axes,
|
||||
uniqueVariants(variants),
|
||||
evidence,
|
||||
`${platform}-structured-2.0.0`,
|
||||
`${platform}-structured-2.0.1`,
|
||||
state,
|
||||
);
|
||||
}
|
||||
@@ -357,7 +358,11 @@ function extractMarketplaceFacts(root: Document, states: unknown[], platform: Ex
|
||||
return {
|
||||
title: (isRecord(item) ? stringAt(item, ['title', 'name']) : undefined) ?? (isRecord(temp) ? stringAt(temp, ['offerTitle']) : undefined) ?? (product ? stringAt(product, ['name']) : undefined),
|
||||
price,
|
||||
description: (product ? stringAt(product, ['description']) : undefined) ?? scopedDescription(root, platform),
|
||||
description: formatCollectedDescription(
|
||||
(product ? stringAt(product, ['description']) : undefined) ??
|
||||
scopedDescription(root, platform) ??
|
||||
'',
|
||||
) || undefined,
|
||||
attributes,
|
||||
categories: [...new Set(categoryNames)].map((name) => ({ key: `${platform}:category:${name.toLowerCase()}`.slice(0, 300), name })),
|
||||
};
|
||||
@@ -368,7 +373,10 @@ function scopedDescription(root: Document, platform: Exclude<SourcePlatform, 'oz
|
||||
? ['.de-description-detail', '#detailContentContainer', '.html-description']
|
||||
: ['[class*="tabDetailWrap--"]', '[class*="detailInfo--"]'];
|
||||
for (const selector of selectors) {
|
||||
const value = root.querySelector(selector)?.textContent?.replace(/\s+/g, ' ').trim();
|
||||
const element = root.querySelector<HTMLElement>(selector);
|
||||
const value = formatCollectedDescription(
|
||||
element?.innerText ?? element?.textContent ?? '',
|
||||
);
|
||||
if (value && value.length >= 10) return value.slice(0, 100_000);
|
||||
}
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user