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

30 lines
823 B
TypeScript
Raw Normal View History

2023-02-17 09:21:02 +00:00
import type { PageProps } from './types'
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/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-12-25 06:52:04 +00:00
console.debug(`[author.page] detected author in route: @${slug}`)
2023-11-18 15:20:15 +00:00
const author = await apiClient.getAuthor({ slug })
if (!author) {
throw render(404)
}
2023-11-29 12:37:27 +00:00
const authorShouts = await apiClient.getShouts({
filters: { author: slug, published: false },
limit: PRERENDERED_ARTICLES_COUNT,
2023-11-29 12:37:27 +00:00
})
const pageProps: PageProps = { author, authorShouts, seo: { title: author.name } }
2023-02-17 09:21:02 +00:00
return {
pageContext: {
pageProps,
},
2023-02-17 09:21:02 +00:00
}
}