fix: add functions to handle and strip Deep Seek link icon nodes
Frontend CI / Frontend (push) Successful in 2m50s
Frontend CI / Frontend (push) Successful in 2m50s
This commit is contained in:
@@ -647,6 +647,35 @@ function shouldStripDeepSeekOrphanAnchor(anchor: HTMLAnchorElement): boolean {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDeepSeekLinkIconSvg(svg: SVGElement): boolean {
|
||||||
|
const viewBox = svg.getAttribute('viewBox')?.trim() ?? ''
|
||||||
|
const width = svg.getAttribute('width')?.trim() ?? ''
|
||||||
|
const height = svg.getAttribute('height')?.trim() ?? ''
|
||||||
|
const paths = Array.from(svg.querySelectorAll('path'))
|
||||||
|
return (
|
||||||
|
viewBox === '0 0 14 14' &&
|
||||||
|
width === '14' &&
|
||||||
|
height === '14' &&
|
||||||
|
paths.length === 2 &&
|
||||||
|
paths.every((path) => path.getAttribute('fill') === 'currentColor')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function stripDeepSeekLinkIconNodes(root: HTMLElement): void {
|
||||||
|
for (const svg of Array.from(root.querySelectorAll<SVGElement>('svg'))) {
|
||||||
|
if (!isDeepSeekLinkIconSvg(svg)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const parent = svg.parentElement
|
||||||
|
const parentText = parent?.textContent?.trim() ?? ''
|
||||||
|
if (parent && parent !== root && parent.children.length === 1 && parentText === '') {
|
||||||
|
parent.remove()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
svg.remove()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function collectDeepSeekCitationReferenceLabels(
|
function collectDeepSeekCitationReferenceLabels(
|
||||||
platform: MonitoringQuestionDetailPlatform | null,
|
platform: MonitoringQuestionDetailPlatform | null,
|
||||||
): string[][] {
|
): string[][] {
|
||||||
@@ -970,6 +999,8 @@ function renderDeepSeekAnswerContent(
|
|||||||
const fallbackLabels = new Map<string, string>()
|
const fallbackLabels = new Map<string, string>()
|
||||||
const fallbackState = { nextIndex: 1 }
|
const fallbackState = { nextIndex: 1 }
|
||||||
|
|
||||||
|
stripDeepSeekLinkIconNodes(root)
|
||||||
|
|
||||||
for (const anchor of Array.from(root.querySelectorAll<HTMLAnchorElement>('a[href], a'))) {
|
for (const anchor of Array.from(root.querySelectorAll<HTMLAnchorElement>('a[href], a'))) {
|
||||||
const rawHref = anchor.hasAttribute('href')
|
const rawHref = anchor.hasAttribute('href')
|
||||||
? anchor.getAttribute('href') || anchor.href || ''
|
? anchor.getAttribute('href') || anchor.href || ''
|
||||||
|
|||||||
Reference in New Issue
Block a user