File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 1+ import { JSDOM } from 'jsdom' ;
12import type {
23 FEElement ,
34 ProductBlockElement ,
@@ -13,6 +14,7 @@ const enhanceProductBlockElement = (
1314 ...element ,
1415 content : elementsEnhancer ( element . content ) ,
1516 lowestPrice : getLowestPrice ( element . productCtas ) ,
17+ primaryHeadingText : getHeadingText ( element . primaryHeadingHtml ) ,
1618} ) ;
1719
1820/**
@@ -72,3 +74,15 @@ export const enhanceProductElement =
7274 ( elementsEnhancer : ElementsEnhancer ) =>
7375 ( elements : FEElement [ ] ) : FEElement [ ] =>
7476 elements . flatMap ( enhance ( elementsEnhancer ) ) ;
77+
78+ const getHeadingText = ( headingHtml : string ) : string => {
79+ return removeTrailingColon ( extractText ( headingHtml ) ) ;
80+ } ;
81+
82+ const removeTrailingColon = ( text : string ) : string => {
83+ return text . replace ( / \s * : \s * $ / , '' ) ;
84+ } ;
85+
86+ const extractText = ( html : string ) : string => {
87+ return JSDOM . fragment ( html ) . textContent ?. trim ( ) ?? '' ;
88+ } ;
Original file line number Diff line number Diff line change @@ -480,6 +480,7 @@ export interface ProductBlockElement {
480480 image ?: ProductImage ;
481481 secondaryHeadingHtml : string ;
482482 primaryHeadingHtml : string ;
483+ primaryHeadingText ?: string ;
483484 customAttributes : ProductCustomAttribute [ ] ;
484485 content : FEElement [ ] ;
485486 h2Id ?: string ;
You can’t perform that action at this time.
0 commit comments