shack/pages/shelves/shelf.page.server.js

26 lines
592 B
JavaScript
Raw Normal View History

2023-06-05 23:30:46 +00:00
import { RenderErrorPage } from 'vite-plugin-ssr/RenderErrorPage';
2023-06-25 17:52:00 +00:00
import { fetchShelf } from '../../src/shelves';
import { fetchShelfPosts } from '../../src/posts';
2023-06-05 23:30:46 +00:00
2023-06-11 03:32:02 +00:00
async function getPageData(pageContext) {
2023-06-05 23:30:46 +00:00
const shelf = await fetchShelf(pageContext.routeParams.id);
2023-06-25 17:52:00 +00:00
const posts = await fetchShelfPosts(pageContext.routeParams.id, { user: pageContext.session.user, limit: 50 });
2023-06-05 23:30:46 +00:00
if (!shelf) {
throw RenderErrorPage({
pageContext: {
pageProps: {
errorInfo: 'No shelf with this name exists',
},
},
});
}
return {
2023-06-11 03:32:02 +00:00
shelf,
posts,
2023-06-05 23:30:46 +00:00
};
}
2023-06-11 03:32:02 +00:00
export { getPageData };