|
1 | 1 | import React, { useRef } from "react" |
2 | 2 | import { graphql } from "gatsby" |
| 3 | +import PropTypes from "prop-types" |
| 4 | +import { Helmet } from "react-helmet" |
3 | 5 | import Layout from "../components/layout" |
4 | 6 | import { CustomSection, Seo, Navigation } from "../components/index" |
5 | | -import PropTypes from "prop-types" |
| 7 | + |
6 | 8 |
|
7 | 9 | const LandingPage = ({ data, location }) => { |
8 | 10 | const { name, slug, parent_page, seo, body, navigation } = |
9 | 11 | data?.allStrapiLandingPage?.nodes[0] || {} |
10 | | - |
11 | 12 | const wrapperRef = useRef(null) |
| 13 | + const faqs = (body || []) |
| 14 | + .filter(block => block.strapi_component === "components.banner-list") |
| 15 | + .flatMap(block => |
| 16 | + (block.Card || []) |
| 17 | + .filter(card => card.description && card.description.trim() !== "") |
| 18 | + .map(({ id, title, description }) => ({ |
| 19 | + "@type": "Question", |
| 20 | + name: title, |
| 21 | + acceptedAnswer: { |
| 22 | + "@type": "Answer", |
| 23 | + text: description, |
| 24 | + }, |
| 25 | + "@id": `#faq-${id}`, |
| 26 | + })) |
| 27 | + ) |
| 28 | + |
| 29 | + const pageLd = { |
| 30 | + "@context": "https://schema.org", |
| 31 | + "@type": "WebPage", |
| 32 | + name: seo?.pageTitle || name, |
| 33 | + description: seo?.pageDescription, |
| 34 | + url: `https://en.bitlogic.io/${slug}`, |
| 35 | + } |
| 36 | + |
| 37 | + const faqLd = |
| 38 | + faqs.length > 0 |
| 39 | + ? { |
| 40 | + "@context": "https://schema.org", |
| 41 | + "@type": "FAQPage", |
| 42 | + mainEntity: faqs, |
| 43 | + } |
| 44 | + : null |
| 45 | + |
12 | 46 | const landing = { |
13 | 47 | name, |
14 | 48 | slug, |
15 | 49 | parent_page, |
16 | 50 | ref: wrapperRef, |
17 | 51 | } |
18 | 52 |
|
19 | | - const {pageTitle, pageKeywords, pageDescription } = seo || {} |
20 | | - |
21 | 53 | return ( |
22 | 54 | <Layout location={location} options={{ hasHeader: true }}> |
23 | | - <Seo title={pageTitle} description={pageDescription} keywords={pageKeywords} location={location} /> |
| 55 | + <Seo |
| 56 | + title={seo?.pageTitle || name} |
| 57 | + description={seo?.pageDescription} |
| 58 | + keywords={seo?.pageKeywords} |
| 59 | + /> |
| 60 | + <Helmet> |
| 61 | + <script type="application/ld+json"> |
| 62 | + {JSON.stringify(pageLd)} |
| 63 | + </script> |
| 64 | + {faqLd && ( |
| 65 | + <script type="application/ld+json"> |
| 66 | + {JSON.stringify(faqLd)} |
| 67 | + </script> |
| 68 | + )} |
| 69 | + </Helmet> |
| 70 | + |
24 | 71 | {body?.length > 0 && navigation ? ( |
25 | 72 | <> |
26 | 73 | <CustomSection sections={body.slice(0, 1)} /> |
@@ -49,7 +96,7 @@ LandingPage.propTypes = { |
49 | 96 | name: PropTypes.string.isRequired, |
50 | 97 | body: PropTypes.arrayOf(PropTypes.object), |
51 | 98 | seo: PropTypes.shape({ |
52 | | - pageTitle: PropTypes.string, |
| 99 | + pageTitle: PropTypes.string.isRequired, |
53 | 100 | pageDescription: PropTypes.string.isRequired, |
54 | 101 | pageKeywords: PropTypes.string, |
55 | 102 | }), |
@@ -234,14 +281,13 @@ export const query = graphql` |
234 | 281 | slug |
235 | 282 | } |
236 | 283 | } |
237 | | - arrayButtons { |
238 | | - content |
239 | | - |
240 | | - english_landing_page { |
241 | | - id |
242 | | - slug |
243 | | - } |
| 284 | + arrayButtons { |
| 285 | + content |
| 286 | + english_landing_page { |
| 287 | + id |
| 288 | + slug |
244 | 289 | } |
| 290 | + } |
245 | 291 | backgroundImageDark { |
246 | 292 | url |
247 | 293 | } |
|
0 commit comments