webapp/src/pages/topic.page.server.ts

31 lines
753 B
TypeScript
Raw Normal View History

import type { PageProps } from './types'
2023-02-17 09:21:02 +00:00
import type { PageContext } from '../renderer/types'
2023-11-18 15:20:15 +00:00
import { render } from 'vike/abort'
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)
}
const topicShouts = await apiClient.getShouts({
filters: { topic: topic.slug, featured: true },
limit: PRERENDERED_ARTICLES_COUNT,
})
const pageProps: PageProps = { topic, topicShouts, seo: { title: topic.title } }
2023-02-17 09:21:02 +00:00
return {
pageContext: {
pageProps,
},
2023-02-17 09:21:02 +00:00
}
}