seo check
This commit is contained in:
@@ -1,15 +1,54 @@
|
||||
import DoctorPage from "@/components/doctor";
|
||||
import Layout from "@/components/layout/StLayout";
|
||||
import { getStateInfo } from "@/lib/getStateInfo";
|
||||
import axios from "axios";
|
||||
|
||||
async function Doctor({ params: { slug } }) {
|
||||
export async function generateMetadata({ params }) {
|
||||
const { slug } = await params;
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
const { matchedCity } = await getStateInfo();
|
||||
const siteName = matchedCity?.site_name || "نوبت 724";
|
||||
|
||||
try {
|
||||
const res = await axios.get(`${API_URL}/api/v1/doctor/${slug}`);
|
||||
const doctor = res.data;
|
||||
if (!doctor) return {};
|
||||
|
||||
const specialtyNames = doctor.specialties?.map((s) => s.name).join(" و ") || "";
|
||||
const title = `دکتر ${doctor.name}${specialtyNames ? " | " + specialtyNames : ""} | ${siteName}`;
|
||||
const description =
|
||||
doctor.detail ||
|
||||
`رزرو نوبت آنلاین دکتر ${doctor.name}${specialtyNames ? " متخصص " + specialtyNames : ""}${doctor.address ? " | " + doctor.address : ""}`.trim();
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
openGraph: {
|
||||
title,
|
||||
description,
|
||||
type: "profile",
|
||||
images: doctor.img ? [doctor.img] : ["https://www.nobat724.com/assets/images/logo.png"],
|
||||
},
|
||||
twitter: {
|
||||
card: "summary",
|
||||
title,
|
||||
description,
|
||||
images: doctor.img ? [doctor.img] : ["https://www.nobat724.com/assets/images/logo.png"],
|
||||
},
|
||||
};
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async function Doctor({ params }) {
|
||||
const { slug } = await params;
|
||||
let doctor = null;
|
||||
let comments = null;
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
|
||||
try {
|
||||
const resDoctor = await axios.get(`${API_URL}/api/v1/doctor/${slug}`);
|
||||
|
||||
doctor = resDoctor.data;
|
||||
if (doctor) {
|
||||
const resComments = await axios.get(
|
||||
@@ -17,15 +56,37 @@ async function Doctor({ params: { slug } }) {
|
||||
);
|
||||
comments = resComments?.data?.data;
|
||||
}
|
||||
} catch (error) {
|
||||
// console.error("problem with req:", error.message);
|
||||
// return redirect("/unauthorized");
|
||||
}
|
||||
} catch (error) {}
|
||||
|
||||
const specialtyNames = doctor?.specialties?.map((s) => s.name).join(" و ") || "";
|
||||
const jsonLd = doctor
|
||||
? {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Physician",
|
||||
name: `دکتر ${doctor.name}`,
|
||||
...(specialtyNames && { medicalSpecialty: specialtyNames }),
|
||||
...(doctor.img && { image: doctor.img }),
|
||||
...(doctor.address && {
|
||||
address: {
|
||||
"@type": "PostalAddress",
|
||||
streetAddress: doctor.address,
|
||||
},
|
||||
}),
|
||||
}
|
||||
: null;
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<DoctorPage doctor={doctor} comments={comments} slug={slug} />
|
||||
</Layout>
|
||||
<>
|
||||
{jsonLd && (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
|
||||
/>
|
||||
)}
|
||||
<Layout>
|
||||
<DoctorPage doctor={doctor} comments={comments} slug={slug} />
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user