Skip to content

Commit

Permalink
feat(SEO): 🚧 add JSON LD example to DoctorPage
Browse files Browse the repository at this point in the history
POSSIBLE FIX: #71
  • Loading branch information
jalezi committed Dec 16, 2021
1 parent 78e8898 commit c756036
Showing 1 changed file with 48 additions and 14 deletions.
62 changes: 48 additions & 14 deletions src/pages/Doctor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react';
import { useParams, Navigate } from 'react-router-dom';
import slugify from 'slugify';
import { useTranslation } from 'react-i18next';
import Box from '@mui/material/Box';

import DoctorCard from 'components/DoctorCard';
Expand All @@ -9,12 +10,27 @@ import { Loader } from 'components/Shared';
import { leafletContext } from 'context';
import { useDoctors } from 'context/doctorsContext';

import * as SEO from 'components/SEO';

const TypeTranslate = {
gp: 'generalPractitioner',
den: 'dentist',
gyn: 'gynecologist',
};

export const AgeGroupTranslate = {
a: 'adults',
y: 'youth',
s: 'students',
};

const Doctor = function Doctor() {
const { doctors } = useDoctors();
const { priimekIme } = useParams();
const [doctor, setDoctor] = useState();
const [loading, setLoading] = useState(true);
const lng = localStorage.getItem('i18nextLng') || 'sl';
const { t } = useTranslation();

useEffect(() => {
setDoctor(doctors?.all.find(d => slugify(d.name.toLowerCase()) === priimekIme));
Expand All @@ -28,22 +44,40 @@ const Doctor = function Doctor() {
}
}, [loading]);

const [doctorType, ageGroup = 'a'] = doctor?.name?.split('-') || [];
const jobTitle = `${t(TypeTranslate[doctorType])} - ${t(AgeGroupTranslate[ageGroup])}`;

const jsonLd = {
'@context': 'https://schema.org/',
'@type': 'Person',
name: doctor?.name,
jobTitle,
address: {
'@type': 'Text',
address: doctor?.fullAddress,
},
};

if (doctor) {
return (
<Box
id="main-content"
component="main"
sx={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: { md: 'calc(100vh - 64px)' },
}}
>
<leafletContext.LeafletProvider>
<DoctorCard doctor={doctor} isPage />
</leafletContext.LeafletProvider>
</Box>
<>
<SEO.Dynamic title={doctor?.name} lang={lng} />
<SEO.LdJson json={jsonLd} />
<Box
id="main-content"
component="main"
sx={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: { md: 'calc(100vh - 64px)' },
}}
>
<leafletContext.LeafletProvider>
<DoctorCard doctor={doctor} isPage />
</leafletContext.LeafletProvider>
</Box>
</>
);
}
if (loading) {
Expand Down

0 comments on commit c756036

Please sign in to comment.