2024-01-07 05:13:40 +00:00
|
|
|
import { fetchScenes } from '#/src/scenes.js';
|
2024-04-02 03:55:53 +00:00
|
|
|
import { curateScenesQuery } from '#/src/web/scenes.js';
|
2024-06-16 23:28:20 +00:00
|
|
|
import { getRandomCampaigns, getCampaignIndex } from '#/src/campaigns.js';
|
2023-12-30 05:29:53 +00:00
|
|
|
|
|
|
|
export async function onBeforeRender(pageContext) {
|
2024-06-02 03:22:08 +00:00
|
|
|
const withQuery = Object.hasOwn(pageContext.urlParsed.search, 'q');
|
|
|
|
|
2024-06-12 15:09:53 +00:00
|
|
|
const [
|
|
|
|
sceneResults,
|
|
|
|
campaigns,
|
|
|
|
] = await Promise.all([
|
|
|
|
fetchScenes(await curateScenesQuery({
|
|
|
|
...pageContext.urlQuery,
|
|
|
|
scope: pageContext.routeParams.scope || 'latest',
|
|
|
|
isShowcased: withQuery ? null : true,
|
|
|
|
tagFilter: pageContext.tagFilter,
|
|
|
|
}), {
|
|
|
|
page: Number(pageContext.routeParams.page) || 1,
|
|
|
|
limit: Number(pageContext.urlParsed.search.limit) || 29,
|
|
|
|
aggregate: withQuery,
|
2024-11-05 03:07:42 +00:00
|
|
|
dedupe: true,
|
2024-06-12 15:09:53 +00:00
|
|
|
}, pageContext.user),
|
|
|
|
getRandomCampaigns([
|
|
|
|
{ minRatio: 1.5 },
|
|
|
|
{ minRatio: 0.75, maxRatio: 1.25 },
|
|
|
|
{ minRatio: 1.5 },
|
2024-06-13 00:26:34 +00:00
|
|
|
], { tagFilter: pageContext.tagFilter }),
|
2024-06-12 15:09:53 +00:00
|
|
|
]);
|
|
|
|
|
2024-06-02 03:22:08 +00:00
|
|
|
const {
|
|
|
|
scenes,
|
2024-06-12 15:09:53 +00:00
|
|
|
} = sceneResults;
|
2023-12-30 05:29:53 +00:00
|
|
|
|
2024-06-16 23:28:20 +00:00
|
|
|
const campaignIndex = getCampaignIndex(scenes.length);
|
2024-06-12 15:09:53 +00:00
|
|
|
const [scopeCampaign, sceneCampaign, paginationCampaign] = campaigns;
|
2024-06-12 00:34:13 +00:00
|
|
|
|
2023-12-30 05:29:53 +00:00
|
|
|
return {
|
|
|
|
pageContext: {
|
|
|
|
title: pageContext.routeParams.scope,
|
|
|
|
pageProps: {
|
2024-08-17 23:36:37 +00:00
|
|
|
...sceneResults,
|
2024-06-12 15:09:53 +00:00
|
|
|
},
|
|
|
|
campaigns: {
|
|
|
|
index: campaignIndex,
|
|
|
|
scope: scopeCampaign,
|
|
|
|
scenes: scenes.length > 5 && sceneCampaign,
|
|
|
|
pagination: paginationCampaign,
|
2023-12-30 05:29:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|