2023-02-17 09:21:02 +00:00
|
|
|
import type { PageContext } from '../renderer/types'
|
|
|
|
import type { PageProps } from './types'
|
|
|
|
import { apiClient } from '../utils/apiClient'
|
2023-11-04 13:09:15 +00:00
|
|
|
import { render } from 'vike/abort'
|
2023-02-17 09:21:02 +00:00
|
|
|
|
|
|
|
export const onBeforeRender = async (pageContext: PageContext) => {
|
|
|
|
const { slug } = pageContext.routeParams
|
2023-05-08 17:21:06 +00:00
|
|
|
const article = await apiClient.getShoutBySlug(slug)
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2023-07-31 20:19:08 +00:00
|
|
|
if (!article) {
|
2023-11-04 13:09:15 +00:00
|
|
|
throw render(404, '/404')
|
2023-07-31 20:19:08 +00:00
|
|
|
}
|
|
|
|
|
2023-11-14 10:45:44 +00:00
|
|
|
const pageProps: PageProps = { article, seo: { title: article.title } }
|
2023-02-17 09:21:02 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
pageContext: {
|
|
|
|
pageProps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|