File tree Expand file tree Collapse file tree 1 file changed +20
-13
lines changed
Expand file tree Collapse file tree 1 file changed +20
-13
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import {Col, Row} from '../../grid';
44import { QuestionsProps } from '../../models' ;
55import { Content } from '../../sub-blocks' ;
66import { block } from '../../utils' ;
7+ import { sanitizeMicrodata } from '../../utils/microdata' ;
78
89import { QuestionBlockItem } from './QuestionBlockItem/QuestionBlockItem' ;
910
@@ -28,19 +29,25 @@ const QuestionsBlock = (props: QuestionsProps) => {
2829 } ;
2930
3031 const faqMicrodataScript = React . useMemo ( ( ) => {
31- const json = JSON . stringify ( {
32- '@context' : 'https://schema.org' ,
33- '@type' : 'FAQPage' ,
34- mainEntity : items . map ( ( item ) => ( {
35- '@type' : 'Question' ,
36- name : item . title ,
37- acceptedAnswer : {
38- '@type' : 'Answer' ,
39- text : item . text ,
40- } ,
41- } ) ) ,
42- } ) ;
43- return < script type = "application/ld+json" dangerouslySetInnerHTML = { { __html : json } } /> ;
32+ try {
33+ const json = JSON . stringify ( {
34+ '@context' : 'https://schema.org' ,
35+ '@type' : 'FAQPage' ,
36+ mainEntity : items . map ( ( item ) => ( {
37+ '@type' : 'Question' ,
38+ name : sanitizeMicrodata ( item . title ) ,
39+ acceptedAnswer : {
40+ '@type' : 'Answer' ,
41+ text : sanitizeMicrodata ( item . text ) ,
42+ } ,
43+ } ) ) ,
44+ } ) ;
45+ return < script type = "application/ld+json" dangerouslySetInnerHTML = { { __html : json } } /> ;
46+ } catch ( error ) {
47+ /*eslint-disable no-console */
48+ console . warn ( 'Problem with FAQ microdata' , error ) ;
49+ return null ;
50+ }
4451 } , [ items ] ) ;
4552
4653 return (
You can’t perform that action at this time.
0 commit comments