Skip to content

Commit cfca14a

Browse files
authored
feat(QuestionBlock): add schema.org FAQ microdata (#308)
1 parent 21b2f90 commit cfca14a

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

src/blocks/Questions/Questions.tsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ import './Questions.scss';
1111

1212
const b = block('QuestionsBlock');
1313

14+
const FaqMicrodataValues = {
15+
PageType: 'https://schema.org/FAQPage',
16+
QuestionType: 'https://schema.org/Question',
17+
QuestionProp: 'mainEntity',
18+
QuestionTextProp: 'name',
19+
AnswerType: 'https://schema.org/Answer',
20+
AnswerProp: 'acceptedAnswer',
21+
AnswerTextProp: 'text',
22+
} as const;
23+
1424
const QuestionsBlock = (props: QuestionsProps) => {
1525
const {title, text, additionalInfo, links, buttons, items} = props;
1626
const [opened, setOpened] = useState<number[]>([0]);
@@ -28,7 +38,7 @@ const QuestionsBlock = (props: QuestionsProps) => {
2838
};
2939

3040
return (
31-
<div className={b()}>
41+
<div className={b()} itemScope itemType={FaqMicrodataValues.PageType}>
3242
<Row>
3343
<Col sizes={{all: 12, md: 4}}>
3444
<div className={b('title')}>
@@ -48,12 +58,20 @@ const QuestionsBlock = (props: QuestionsProps) => {
4858
const isOpened = opened.includes(index);
4959

5060
return (
51-
<div key={itemTitle} className={b('item')}>
61+
<div
62+
key={itemTitle}
63+
className={b('item')}
64+
itemScope
65+
itemProp={FaqMicrodataValues.QuestionProp}
66+
itemType={FaqMicrodataValues.QuestionType}
67+
>
5268
<h4
5369
className={b('item-title')}
5470
onClick={() => toggleItem(index)}
5571
>
56-
<HTML>{itemTitle}</HTML>
72+
<HTML itemProp={FaqMicrodataValues.QuestionTextProp}>
73+
{itemTitle}
74+
</HTML>
5775
<ToggleArrow
5876
open={isOpened}
5977
size={16}
@@ -63,14 +81,20 @@ const QuestionsBlock = (props: QuestionsProps) => {
6381
/>
6482
</h4>
6583
<Foldable isOpened={isOpened}>
66-
<div className={b('text')}>
84+
<div
85+
className={b('text')}
86+
itemScope
87+
itemProp={FaqMicrodataValues.AnswerProp}
88+
itemType={FaqMicrodataValues.AnswerType}
89+
>
6790
<YFMWrapper
6891
content={itemText}
6992
modifiers={{
7093
constructor: true,
7194
constructorListStyle: true,
7295
constructorListStyleDash: listStyle === 'dash',
7396
}}
97+
itemProp={FaqMicrodataValues.QuestionTextProp}
7498
/>
7599
{link && <Link {...link} className={b('link')} />}
76100
</div>

src/components/HTML/HTML.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ export interface HTMLProps {
66
children?: string;
77
block?: boolean;
88
className?: string;
9+
itemProp?: string;
910
}
1011

11-
const HTML = ({children, block = false, className}: WithChildren<HTMLProps>) => {
12+
const HTML = ({children, block = false, className, itemProp}: WithChildren<HTMLProps>) => {
1213
if (!children) {
1314
return null;
1415
}
1516

1617
return React.createElement(block ? 'div' : 'span', {
1718
dangerouslySetInnerHTML: {__html: children},
1819
className,
20+
itemProp,
1921
});
2022
};
2123

src/components/YFMWrapper/YFMWrapper.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@ export interface YFMWrapperProps {
1414
className?: string;
1515
content: string;
1616
modifiers?: Modifiers;
17+
itemProp?: string;
1718
}
1819

19-
const YFMWrapper = ({content, modifiers, className}: YFMWrapperProps & ClassNameProps) => (
20-
<HTML className={yfm(modifiers ? toSnakeCase(modifiers) : {}, className)}>{content}</HTML>
20+
const YFMWrapper = ({
21+
content,
22+
modifiers,
23+
className,
24+
itemProp,
25+
}: YFMWrapperProps & ClassNameProps) => (
26+
<HTML className={yfm(modifiers ? toSnakeCase(modifiers) : {}, className)} itemProp={itemProp}>
27+
{content}
28+
</HTML>
2129
);
2230

2331
export default YFMWrapper;

0 commit comments

Comments
 (0)