Skip to content

Commit 38a50ed

Browse files
arteria32Denis Ryabko
andauthored
Fix(Questions): use sanitaze for faq miqrodata (#1358)
* chore(Table): refactor schema definition * chore(Questions): use ld+json in questions block * fix(Questions): add sanitizeHtml to faqMicrodataScript * fix(Questions): add disable no-console rule * fix(Question): use sanitizeMicrodata instead sanitizeHtml --------- Co-authored-by: Denis Ryabko <ryabkodenis@yandex-team.ru>
1 parent 65ed2fc commit 38a50ed

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/blocks/Questions/Questions.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Col, Row} from '../../grid';
44
import {QuestionsProps} from '../../models';
55
import {Content} from '../../sub-blocks';
66
import {block} from '../../utils';
7+
import {sanitizeMicrodata} from '../../utils/microdata';
78

89
import {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 (

0 commit comments

Comments
 (0)