webapp/src/pages/author.page.server.ts
2023-11-28 16:18:25 +03:00

31 lines
764 B
TypeScript

import type { PageProps } from './types'
import type { PageContext } from '../renderer/types'
import { render } from 'vike/abort'
import { PRERENDERED_ARTICLES_COUNT } from '../components/Views/Author'
import { apiClient } from '../graphql/client/core'
export const onBeforeRender = async (pageContext: PageContext) => {
const { slug } = pageContext.routeParams
const author = await apiClient.getAuthor({ slug })
if (!author) {
throw render(404)
}
const authorShouts = await apiClient.getShouts({
filters: { author: slug, visibility: 'community' },
limit: PRERENDERED_ARTICLES_COUNT,
})
const pageProps: PageProps = { author, authorShouts, seo: { title: author.name } }
return {
pageContext: {
pageProps,
},
}
}