feat(seo): implement sitemap, robots, dynamic metadata, and hreflang using ipal-kit
This commit is contained in:
@@ -13,6 +13,13 @@ type FAQFullBlock = Extract<NonNullable<Page['layout']>[0], { blockType: 'faqFul
|
|||||||
|
|
||||||
import type { Metadata } from 'next'
|
import type { Metadata } from 'next'
|
||||||
|
|
||||||
|
import { createPageMetadata } from '@intecion/ipal-kit'
|
||||||
|
|
||||||
|
const pageMetadata = createPageMetadata({
|
||||||
|
config: i18n,
|
||||||
|
baseUrl: process.env.NEXT_PUBLIC_SERVER_URL || 'https://www.jkedzierski.de'
|
||||||
|
})
|
||||||
|
|
||||||
export async function generateMetadata(
|
export async function generateMetadata(
|
||||||
props: { params: Promise<{ locale: string; slug?: string[] }> }
|
props: { params: Promise<{ locale: string; slug?: string[] }> }
|
||||||
): Promise<Metadata> {
|
): Promise<Metadata> {
|
||||||
@@ -20,46 +27,7 @@ export async function generateMetadata(
|
|||||||
const { locale, slug } = params
|
const { locale, slug } = params
|
||||||
const payload = await getPayload({ config: configPromise })
|
const payload = await getPayload({ config: configPromise })
|
||||||
|
|
||||||
const route = await resolveRoute({ payload, locale, segments: slug || [] })
|
return pageMetadata({ payload, locale, slug })
|
||||||
if (!route) {
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
|
|
||||||
const doc = await payload.findByID({
|
|
||||||
collection: ('collection' in route ? route.collection : 'pages') as 'pages',
|
|
||||||
id: route.doc.id as string,
|
|
||||||
locale: locale as 'all' | 'pl' | 'de' | 'en',
|
|
||||||
})
|
|
||||||
|
|
||||||
// Retrieve meta object injected by @payloadcms/plugin-seo
|
|
||||||
const meta = (doc as any).meta
|
|
||||||
|
|
||||||
const title = meta?.title || doc.title
|
|
||||||
const description = meta?.description || ''
|
|
||||||
|
|
||||||
let imageUrl = ''
|
|
||||||
if (meta?.image && typeof meta.image === 'object' && meta.image.url) {
|
|
||||||
imageUrl = meta.image.url
|
|
||||||
} else if (meta?.image && typeof meta.image === 'string') {
|
|
||||||
// If it's just an ID, we might not have the full URL without a separate fetch,
|
|
||||||
// but usually Payload plugin-seo populates the image relationship.
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
openGraph: {
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
...(imageUrl && { images: [{ url: imageUrl }] }),
|
|
||||||
},
|
|
||||||
twitter: {
|
|
||||||
card: 'summary_large_image',
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
...(imageUrl && { images: [imageUrl] }),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function Page(props: {
|
export default async function Page(props: {
|
||||||
|
|||||||
@@ -20,10 +20,7 @@ const fraunces = Fraunces({
|
|||||||
variable: '--font-heading',
|
variable: '--font-heading',
|
||||||
})
|
})
|
||||||
|
|
||||||
export const metadata = {
|
|
||||||
title: 'Finanz- & Lohnbuchhaltung Dipl.-Ing. Janusz Kędzierski',
|
|
||||||
description: 'Profesjonalne doradztwo podatkowe.',
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async function RootLayout(props: {
|
export default async function RootLayout(props: {
|
||||||
children: React.ReactNode,
|
children: React.ReactNode,
|
||||||
@@ -61,12 +58,12 @@ export default async function RootLayout(props: {
|
|||||||
const schemaOrg = {
|
const schemaOrg = {
|
||||||
"@context": "https://schema.org",
|
"@context": "https://schema.org",
|
||||||
"@type": "AccountingService",
|
"@type": "AccountingService",
|
||||||
"name": "Finanz- & Lohnbuchhaltung Dipl.-Ing. Janusz Kędzierski",
|
"name": siteData?.siteName || "Finanz- & Lohnbuchhaltung Dipl.-Ing. Janusz Kędzierski",
|
||||||
"telephone": companyData?.phone || '',
|
"telephone": companyData?.phone || '',
|
||||||
"email": companyData?.email || '',
|
"email": companyData?.email || '',
|
||||||
"address": companyData?.address || '',
|
"address": companyData?.address || '',
|
||||||
"openingHours": companyData?.hours || '',
|
"openingHours": companyData?.hours || '',
|
||||||
"url": "https://www.jkedzierski.de"
|
"url": process.env.NEXT_PUBLIC_SERVER_URL || "https://www.jkedzierski.de"
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { buildRobots } from '@intecion/ipal-kit'
|
||||||
|
|
||||||
|
export default function robots() {
|
||||||
|
return buildRobots({ baseUrl: process.env.NEXT_PUBLIC_SERVER_URL || '' })
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { getPayload } from 'payload'
|
||||||
|
import configPromise from '@payload-config'
|
||||||
|
import { buildSitemapEntries } from '@intecion/ipal-kit'
|
||||||
|
import { i18n } from '../i18n.config'
|
||||||
|
|
||||||
|
export default async function sitemap() {
|
||||||
|
const payload = await getPayload({ config: configPromise })
|
||||||
|
return buildSitemapEntries({
|
||||||
|
payload,
|
||||||
|
config: i18n,
|
||||||
|
baseUrl: process.env.NEXT_PUBLIC_SERVER_URL || '',
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user