Refactor Open Graph handling by removing unused URL state and updating image source logic
This commit is contained in:
parent
4a6a6f5900
commit
986409b739
2 changed files with 2 additions and 61 deletions
|
|
@ -69,13 +69,6 @@ const AnnuncioDettaglio: NextPage<AnnuncioProps> = ({
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
const { locale } = useTranslation();
|
const { locale } = useTranslation();
|
||||||
|
|
||||||
const [url, setUrl] = useState("");
|
|
||||||
useEffect(() => {
|
|
||||||
if (typeof window !== "undefined") {
|
|
||||||
setUrl(window.location.href);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const { data, isLoading } = api.annunci.getAnnuncio.useQuery(
|
const { data, isLoading } = api.annunci.getAnnuncio.useQuery(
|
||||||
{
|
{
|
||||||
cod: cod,
|
cod: cod,
|
||||||
|
|
@ -112,12 +105,11 @@ const AnnuncioDettaglio: NextPage<AnnuncioProps> = ({
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta property="og:title" content={`${cod} | ${titolo}`} />
|
<meta property="og:title" content={`${cod} | ${titolo}`} />
|
||||||
<meta property="og:description" content={description} />
|
<meta property="og:description" content={description} />
|
||||||
{/* <meta property="og:image" content={data.og_url || ""} /> */}
|
|
||||||
<meta
|
<meta
|
||||||
property="og:image"
|
property="og:image"
|
||||||
content={
|
content={
|
||||||
data.og_url
|
data.url_immagini
|
||||||
? `${env.NEXT_PUBLIC_BASE_URL}/api/og?og=${data.og_url}`
|
? `${env.NEXT_PUBLIC_BASE_URL}${data.url_immagini[0]}`
|
||||||
: ""
|
: ""
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
@ -125,10 +117,6 @@ const AnnuncioDettaglio: NextPage<AnnuncioProps> = ({
|
||||||
property="og:logo"
|
property="og:logo"
|
||||||
content={`${env.NEXT_PUBLIC_BASE_URL}/Infoalloggi.png`}
|
content={`${env.NEXT_PUBLIC_BASE_URL}/Infoalloggi.png`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{typeof window !== "undefined" && (
|
|
||||||
<meta property="og:url" content={url} />
|
|
||||||
)}
|
|
||||||
<meta property="og:site_name" content="Infoalloggi.it" />
|
<meta property="og:site_name" content="Infoalloggi.it" />
|
||||||
</Head>
|
</Head>
|
||||||
<div className="mx-auto w-full px-2 sm:px-8">
|
<div className="mx-auto w-full px-2 sm:px-8">
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
import { ImageResponse } from "@vercel/og";
|
|
||||||
import type { NextRequest } from "next/server";
|
|
||||||
|
|
||||||
export const config = {
|
|
||||||
runtime: "edge",
|
|
||||||
};
|
|
||||||
|
|
||||||
export default async function handler(request: NextRequest) {
|
|
||||||
const { searchParams } = request.nextUrl;
|
|
||||||
|
|
||||||
const og = searchParams.get("og");
|
|
||||||
if (!og) {
|
|
||||||
return new Response("Missing 'cod' parameter", { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ImageResponse(
|
|
||||||
(
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
fontSize: 60,
|
|
||||||
color: "black",
|
|
||||||
background: "#f6f6f6",
|
|
||||||
width: "100%",
|
|
||||||
height: "100%",
|
|
||||||
flexDirection: "column",
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text */}
|
|
||||||
<img
|
|
||||||
src={og}
|
|
||||||
//src={`${env.NEXT_PUBLIC_BASE_URL}/go-api/images/get/${cod}`}
|
|
||||||
style={{
|
|
||||||
height: "100%",
|
|
||||||
objectFit: "cover",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
{
|
|
||||||
width: 1200,
|
|
||||||
height: 630,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue