2023-11-14 15:10:00 +00:00
|
|
|
import type { PageProps } from './types'
|
2023-02-17 09:21:02 +00:00
|
|
|
import type { PageContext } from '../renderer/types'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2023-11-18 15:20:15 +00:00
|
|
|
import { render } from 'vike/abort'
|
|
|
|
|
2023-12-21 12:48:13 +00:00
|
|
|
import { PRERENDERED_ARTICLES_COUNT } from '../components/Views/Topic'
|
2023-12-24 12:56:30 +00:00
|
|
|
import { apiClient } from '../graphql/client/core'
|
2023-02-17 09:21:02 +00:00
|
|
|
|
|
|
|
export const onBeforeRender = async (pageContext: PageContext) => {
|
|
|
|
const { slug } = pageContext.routeParams
|
|
|
|
|
|
|
|
const topic = await apiClient.getTopic({ slug })
|
|
|
|
|
2023-11-18 15:20:15 +00:00
|
|
|
if (!topic) {
|
|
|
|
throw render(404)
|
|
|
|
}
|
|
|
|
|
2023-12-21 12:48:13 +00:00
|
|
|
const topicShouts = await apiClient.getShouts({
|
2024-02-02 17:29:53 +00:00
|
|
|
filters: { topic: topic.slug, featured: true },
|
2023-12-21 12:48:13 +00:00
|
|
|
limit: PRERENDERED_ARTICLES_COUNT,
|
|
|
|
})
|
|
|
|
|
|
|
|
const pageProps: PageProps = { topic, topicShouts, seo: { title: topic.title } }
|
2023-02-17 09:21:02 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
pageContext: {
|
2023-11-14 15:10:00 +00:00
|
|
|
pageProps,
|
|
|
|
},
|
2023-02-17 09:21:02 +00:00
|
|
|
}
|
|
|
|
}
|