2023-02-17 09:21:02 +00:00
|
|
|
import type { PageProps } from './types'
|
2023-11-14 15:10:00 +00:00
|
|
|
import type { PageContext } from '../renderer/types'
|
|
|
|
|
2023-11-18 15:20:15 +00:00
|
|
|
import { render } from 'vike/abort'
|
|
|
|
|
2023-09-16 06:26:19 +00:00
|
|
|
import { PRERENDERED_ARTICLES_COUNT } from '../components/Views/Author'
|
2023-11-28 13:18:25 +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
|
|
|
|
|
2023-11-18 15:20:15 +00:00
|
|
|
const author = await apiClient.getAuthor({ slug })
|
|
|
|
|
|
|
|
if (!author) {
|
|
|
|
throw render(404)
|
|
|
|
}
|
2023-11-29 08:23:08 +00:00
|
|
|
const options = {
|
2023-10-25 13:57:21 +00:00
|
|
|
filters: { author: slug, visibility: 'community' },
|
2023-11-14 15:10:00 +00:00
|
|
|
limit: PRERENDERED_ARTICLES_COUNT,
|
2023-11-29 08:23:08 +00:00
|
|
|
}
|
|
|
|
const authorShouts = await apiClient.getShouts({ options })
|
2023-11-14 10:45:44 +00:00
|
|
|
const pageProps: PageProps = { author, authorShouts, seo: { title: author.name } }
|
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
|
|
|
}
|
|
|
|
}
|