webapp/src/pages/author.page.server.ts
Tony 829e523d36
Hotfix/featured (#391)
add: Shout.featured_at
remove: Shout.visibility
2024-02-02 20:29:53 +03:00

30 lines
822 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
console.debug(`[author.page] detected author in route: @${slug}`)
const author = await apiClient.getAuthor({ slug })
if (!author) {
throw render(404)
}
const authorShouts = await apiClient.getShouts({
filters: { author: slug, featured: false },
limit: PRERENDERED_ARTICLES_COUNT,
})
const pageProps: PageProps = { author, authorShouts, seo: { title: author.name } }
return {
pageContext: {
pageProps,
},
}
}