Enhance Open Graph support by adding meta data retrieval and updating robots.txt for better SEO
This commit is contained in:
parent
a6fa1b960b
commit
7bfef22f80
4 changed files with 72 additions and 18 deletions
|
|
@ -1,4 +1,7 @@
|
|||
User-agent: *
|
||||
Allow: /api/og/*
|
||||
Disallow:
|
||||
Allow: /
|
||||
Disallow: /api/
|
||||
Disallow: /area-riservata/
|
||||
|
||||
# Crawl delay (optional - adjust based on your server capacity)
|
||||
Crawl-delay: 1
|
||||
|
|
@ -61,10 +61,17 @@ import type { Annunci } from "~/schemas/public/Annunci";
|
|||
type AnnuncioProps = {
|
||||
cod: string;
|
||||
flag: string;
|
||||
meta: {
|
||||
ogImage: string;
|
||||
title: string;
|
||||
description: string;
|
||||
ogUrl: string;
|
||||
};
|
||||
};
|
||||
const AnnuncioDettaglio: NextPage<AnnuncioProps> = ({
|
||||
cod,
|
||||
flag,
|
||||
meta,
|
||||
}: AnnuncioProps) => {
|
||||
const session = useSession();
|
||||
const { locale } = useTranslation();
|
||||
|
|
@ -99,21 +106,15 @@ const AnnuncioDettaglio: NextPage<AnnuncioProps> = ({
|
|||
<TouchProvider>
|
||||
<main>
|
||||
<Head>
|
||||
<title>{`${cod} | ${titolo}`}</title>
|
||||
<meta property="description" content={description} />
|
||||
<meta property="og:url" content={window.location.href} />
|
||||
<title>{`${cod} | ${meta.title}`}</title>
|
||||
<meta property="description" content={meta.description} />
|
||||
<meta property="og:url" content={meta.ogUrl} />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:title" content={`${cod} | ${titolo}`} />
|
||||
<meta property="og:description" content={description} />
|
||||
{/* <meta
|
||||
property="og:image"
|
||||
content={
|
||||
data.url_immagini
|
||||
? `${env.NEXT_PUBLIC_BASE_URL}${data.url_immagini[0]}`
|
||||
: ""
|
||||
}
|
||||
/> */}
|
||||
<meta property="og:image" content={data.og_url || ""} />
|
||||
<meta property="og:title" content={`${cod} | ${meta.title}`} />
|
||||
<meta property="og:description" content={meta.description} />
|
||||
<meta property="og:image" content={meta.ogImage} />
|
||||
<meta property="og:image:width" content="1200" />
|
||||
<meta property="og:image:height" content="630" />
|
||||
<meta
|
||||
property="og:logo"
|
||||
content={`${env.NEXT_PUBLIC_BASE_URL}/Infoalloggi.png`}
|
||||
|
|
@ -192,8 +193,15 @@ export async function getStaticProps(
|
|||
) {
|
||||
const ssg = generateSSGHelper();
|
||||
const cod = context.params?.cod;
|
||||
if (typeof cod !== "string") throw new Error("no cod");
|
||||
if (typeof cod !== "string") {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
await ssg.annunci.getAnnuncio.prefetch({ cod: cod });
|
||||
|
||||
const meta = await ssg.annunci.getAnnuncioMeta.fetch({ cod: cod });
|
||||
|
||||
const flag = await ssg.settings.GetFlagValue.fetch({
|
||||
id: "ANNUNCIO_INTERACTIONS_DISABLED",
|
||||
});
|
||||
|
|
@ -202,6 +210,7 @@ export async function getStaticProps(
|
|||
trpcState: ssg.dehydrate(),
|
||||
cod,
|
||||
flag,
|
||||
meta,
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import {
|
|||
getCursor_AnnunciHandler,
|
||||
get_AnnunciPositionsHandler,
|
||||
getAnnunciById,
|
||||
getAnnunciMetaByCod,
|
||||
} from "~/server/controllers/annunci.controller";
|
||||
import { zAnnuncioId, zServizioId } from "~/server/utils/zod_types";
|
||||
|
||||
|
|
@ -35,6 +36,15 @@ export const annunciRouter = createTRPCRouter({
|
|||
.query(async ({ input }) => {
|
||||
return await getAnnunciByCod({ ...input });
|
||||
}),
|
||||
getAnnuncioMeta: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
cod: z.string(),
|
||||
}),
|
||||
)
|
||||
.query(async ({ input }) => {
|
||||
return await getAnnunciMetaByCod({ ...input });
|
||||
}),
|
||||
getAnnuncioById: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import type { Annunci, AnnunciId } from "~/schemas/public/Annunci";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { createSrcset } from "~/server/services/imageServer";
|
||||
import { createSrc, createSrcset } from "~/server/services/imageServer";
|
||||
import { AnnuncioObjectWithImages } from "~/server/services/annunci.service";
|
||||
import { zAnnuncioId } from "~/server/utils/zod_types";
|
||||
import { z } from "zod/v4";
|
||||
import { db } from "~/server/db";
|
||||
import type { ServizioServizioId } from "~/schemas/public/Servizio";
|
||||
import { env } from "~/env.mjs";
|
||||
|
||||
// const ratelimit = new RateLimiterHandler({
|
||||
// windowSize: 10,
|
||||
|
|
@ -88,6 +89,37 @@ export const getAnnunciByCod = async ({
|
|||
});
|
||||
}
|
||||
};
|
||||
export const getAnnunciMetaByCod = async ({ cod }: { cod: string }) => {
|
||||
try {
|
||||
const annuncio = await db
|
||||
.selectFrom("annunci")
|
||||
.select(["titolo_it", "desc_it", "url_immagini", "og_url"])
|
||||
.where("annunci.web", "=", true)
|
||||
.where("codice", "=", cod)
|
||||
.executeTakeFirst();
|
||||
if (!annuncio) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Annuncio non trovato",
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
ogImage:
|
||||
annuncio.url_immagini && annuncio.url_immagini[0]
|
||||
? createSrc(annuncio.url_immagini[0])
|
||||
: annuncio.og_url || "",
|
||||
title: annuncio.titolo_it || "",
|
||||
description: annuncio.desc_it || "",
|
||||
ogUrl: env.NEXT_PUBLIC_BASE_URL + "/annuncio/" + cod,
|
||||
};
|
||||
} catch {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
message: "Errore query getAnnuncio",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getAnnunciById = async ({
|
||||
id,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue