Files
pawol.nu/app/paroles/[slug]/page.js
T
2026-04-16 12:52:51 +04:00

121 lines
3.5 KiB
JavaScript

import {notFound} from 'next/navigation'
import Box from '@mui/material/Box'
import {jwennTeksEpiSlug} from '../../../lib/oki-api'
import AnTeks from '../../../components/teks/an-teks'
import {getAlias} from '../../../lib/utils/format'
import {formatKuveti} from '../../../lib/kuveti'
import Footer from '../../../components/footer'
const apiUrl = process.env.NEXT_PUBLIC_API_URL_ROOT || 'http://localhost:1337'
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000'
async function jwennAnTeks(slug) {
const teks = await jwennTeksEpiSlug(slug)
if (!teks) {
notFound()
}
return teks
}
export async function generateMetadata(props) {
const params = await props.params;
const {slug} = params
const anTeks = await jwennAnTeks(slug)
const awtis = anTeks.attributes.artistes.length === 1 ? anTeks.attributes.artistes[0].data.attributes.alias : getAlias(anTeks.attributes.artistes, anTeks.attributes.prioriteArtistes)
const title = `OKI | ${awtis} - ${anTeks.attributes.titre} | Paroles et Traductions`
const description = `Paroles de « ${anTeks?.attributes?.titre} » : ${anTeks?.attributes?.transcription.slice(0, 100)}...`
const url = `${siteUrl}/paroles/${slug}`
const {couverture} = anTeks.attributes
const kuvetiFormat = formatKuveti(couverture)
return {
title,
description,
openGraph: {
title,
description,
url,
siteName: title,
images: [
{
url: `${apiUrl}${kuvetiFormat?.url}`,
width: kuvetiFormat?.width,
height: kuvetiFormat?.height
}
],
locale: 'fr_FR',
type: 'website'
},
twitter: {
site: '@OrganisationKA',
card: 'summary_large_image',
title,
description,
creator: '@OrganisationKA',
images: {
url: `${apiUrl}${kuvetiFormat?.url}`,
alt: `Couverture ${title}`,
}
}
}
}
export default async function AnPawolPaj(props) {
const params = await props.params;
const {slug} = params
const anTeks = await jwennAnTeks(slug)
const {couverture} = anTeks.attributes
const teksKuvetiFormat = formatKuveti(couverture)
const jsonLd = {
'@context': 'http://schema.org',
'@type': 'MusicRecording',
'@id': anTeks.attributes.musicBrainzUrl || undefined,
name: anTeks.attributes.titre,
url: `${siteUrl}/paroles/${slug}`,
image: teksKuvetiFormat?.url ? `${apiUrl}${teksKuvetiFormat?.url}` : undefined,
thumbnailUrl: couverture?.data?.attributes?.formats?.thumbnail?.url ? `${apiUrl}${couverture.data.attributes.formats.thumbnail.url}` : undefined,
byArtist: anTeks.attributes.artistes.data.map(({attributes}) => {
const {photo} = attributes
const kuvetiFormat = formatKuveti(photo)
return {
'@type': 'Person',
'@id': attributes.musicBrainzUrl || undefined,
name: attributes.alias,
url: `${siteUrl}/awtis/${attributes.slug}`,
image: kuvetiFormat?.url ? `${apiUrl}${kuvetiFormat?.url}` : undefined
}
}),
datePublished: anTeks.attributes?.annee
}
return (
<>
<Box sx={{display: 'flex', flexDirection: 'column', minHeight: '100vh'}}>
<Box
component='main'
sx={{flexGrow: 1, p: 2, mt: 2}}
>
<AnTeks parole={anTeks.attributes} paroleId={anTeks.id} />
</Box>
<Footer />
</Box>
<section>
<script
type='application/ld+json'
dangerouslySetInnerHTML={{__html: JSON.stringify(jsonLd)}}
/>
</section>
</>
)
}