Files
pawol.nu/app/paroles/[slug]/page.js
T

119 lines
3.4 KiB
JavaScript
Raw Normal View History

2023-07-22 13:28:30 +04:00
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'
2023-07-22 23:38:08 +04:00
import Footer from '../../../components/footer'
2023-07-22 13:28:30 +04:00
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({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)}...`
2024-08-07 12:51:42 +02:00
const url = `${siteUrl}/paroles/${slug}`
2023-07-22 13:28:30 +04:00
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({params}) {
const {slug} = params
const anTeks = await jwennAnTeks(slug)
const {couverture} = anTeks.attributes
const teksKuvetiFormat = formatKuveti(couverture)
2023-07-22 13:28:30 +04:00
const jsonLd = {
'@context': 'http://schema.org',
'@type': 'MusicRecording',
'@id': anTeks.attributes.musicBrainzUrl || undefined,
2023-07-22 13:28:30 +04:00
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
}
}),
2023-07-22 13:28:30 +04:00
datePublished: anTeks.attributes?.annee
}
return (
<>
2023-07-22 23:38:08 +04:00
<Box sx={{display: 'flex', flexDirection: 'column', minHeight: '100vh'}}>
2023-07-22 13:28:30 +04:00
<Box
component='main'
2023-07-22 23:38:08 +04:00
sx={{flexGrow: 1, p: 2, mt: 2}}
2023-07-22 13:28:30 +04:00
>
<AnTeks parole={anTeks.attributes} paroleId={anTeks.id} />
</Box>
2023-07-22 23:38:08 +04:00
<Footer />
2023-07-22 13:28:30 +04:00
</Box>
<section>
<script
type='application/ld+json'
dangerouslySetInnerHTML={{__html: JSON.stringify(jsonLd)}}
/>
</section>
</>
)
}