You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

52 lines
1.5 KiB

import { getPublicPostsPreviewBySlug } from "#server/service/posts";
import { getPublicTimelinePreviewBySlug } from "#server/service/timeline";
import { getPublicRssPreviewBySlug } from "#server/service/rss";
const PUBLIC_HUB_PREVIEW_LIMIT = 2;
type PublicPostsPreview = Awaited<ReturnType<typeof getPublicPostsPreviewBySlug>>;
type PublicTimelinePreview = Awaited<
ReturnType<typeof getPublicTimelinePreviewBySlug>
>;
type PublicRssPreview = Awaited<ReturnType<typeof getPublicRssPreviewBySlug>>;
export type PublicHubPayload = {
modules: {
posts: PublicPostsPreview;
timeline: PublicTimelinePreview;
reading: PublicRssPreview;
};
posts: PublicPostsPreview;
timeline: PublicTimelinePreview;
rssItems: PublicRssPreview;
};
export async function getPublicHubBySlug(
publicSlug: string,
): Promise<PublicHubPayload> {
const [posts, timeline, reading] = await Promise.all([
getPublicPostsPreviewBySlug(publicSlug),
getPublicTimelinePreviewBySlug(publicSlug),
getPublicRssPreviewBySlug(publicSlug),
]);
return {
modules: {
posts: {
items: posts.items.slice(0, PUBLIC_HUB_PREVIEW_LIMIT),
total: posts.total,
},
timeline: {
items: timeline.items.slice(0, PUBLIC_HUB_PREVIEW_LIMIT),
total: timeline.total,
},
reading: {
items: reading.items.slice(0, PUBLIC_HUB_PREVIEW_LIMIT),
total: reading.total,
},
},
posts,
timeline,
rssItems: reading,
};
}