Showing curated campaigns on tags page.
This commit is contained in:
@@ -34,16 +34,19 @@ export async function onBeforeRender(pageContext) {
|
||||
{
|
||||
entityIds: [entity.id, entity.parent?.id].filter(Boolean),
|
||||
minRatio: 1.5,
|
||||
allowRandomFallback: false,
|
||||
},
|
||||
{
|
||||
entityIds: [entity.id, entity.parent?.id].filter(Boolean),
|
||||
minRatio: 0.75,
|
||||
maxRatio: 1.25,
|
||||
allowRandomFallback: false,
|
||||
},
|
||||
{
|
||||
entityIds: [entity.id, entity.parent?.id].filter(Boolean),
|
||||
parentEntityId: entity.parent?.id,
|
||||
minRatio: 1.5,
|
||||
allowRandomFallback: false,
|
||||
},
|
||||
], { tagFilter: pageContext.tagFilter });
|
||||
|
||||
|
||||
@@ -4,12 +4,15 @@ import markdownItClass from '@toycode/markdown-it-class';
|
||||
import { fetchTagsById } from '#/src/tags.js';
|
||||
import { fetchScenes } from '#/src/scenes.js';
|
||||
import { curateScenesQuery } from '#/src/web/scenes.js';
|
||||
import { getRandomCampaigns, getCampaignIndex } from '#/src/campaigns.js';
|
||||
|
||||
const md = markdownIt().use(markdownItClass, { a: 'link' });
|
||||
|
||||
export async function onBeforeRender(pageContext) {
|
||||
const [[tag], tagScenes] = await Promise.all([
|
||||
fetchTagsById([pageContext.routeParams.tagSlug]),
|
||||
const tagSlug = pageContext.routeParams.tagSlug;
|
||||
|
||||
const [[tag], tagScenes, campaigns] = await Promise.all([
|
||||
fetchTagsById([tagSlug]),
|
||||
fetchScenes(await curateScenesQuery({
|
||||
...pageContext.urlQuery,
|
||||
scope: pageContext.routeParams.scope || 'latest',
|
||||
@@ -20,6 +23,11 @@ export async function onBeforeRender(pageContext) {
|
||||
limit: Number(pageContext.urlParsed.search.limit) || 30,
|
||||
aggregate: true,
|
||||
}, pageContext.user),
|
||||
getRandomCampaigns([
|
||||
{ tagSlugs: [tagSlug], minRatio: 1.5 },
|
||||
{ tagSlugs: [tagSlug], minRatio: 0.75, maxRatio: 1.25 },
|
||||
{ tagSlugs: [tagSlug], minRatio: 1.5 },
|
||||
], { tagFilter: pageContext.tagFilter }),
|
||||
]);
|
||||
|
||||
const {
|
||||
@@ -33,6 +41,9 @@ export async function onBeforeRender(pageContext) {
|
||||
|
||||
const description = tag.description && md.renderInline(tag.description);
|
||||
|
||||
const campaignIndex = getCampaignIndex(scenes.length);
|
||||
const [metaCampaign, sceneCampaign, paginationCampaign] = campaigns;
|
||||
|
||||
return {
|
||||
pageContext: {
|
||||
title: tag.name,
|
||||
@@ -46,6 +57,12 @@ export async function onBeforeRender(pageContext) {
|
||||
total,
|
||||
limit,
|
||||
},
|
||||
campaigns: {
|
||||
index: campaignIndex,
|
||||
meta: metaCampaign,
|
||||
scenes: scenes.length > 5 && sceneCampaign,
|
||||
pagination: paginationCampaign,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { fetchScenes } from '#/src/scenes.js';
|
||||
import { curateScenesQuery } from '#/src/web/scenes.js';
|
||||
import { getRandomCampaigns } from '#/src/campaigns.js';
|
||||
import { getRandomCampaigns, getCampaignIndex } from '#/src/campaigns.js';
|
||||
|
||||
export async function onBeforeRender(pageContext) {
|
||||
const withQuery = Object.hasOwn(pageContext.urlParsed.search, 'q');
|
||||
@@ -35,7 +35,7 @@ export async function onBeforeRender(pageContext) {
|
||||
total,
|
||||
} = sceneResults;
|
||||
|
||||
const campaignIndex = Math.floor((Math.random() * (0.5 - 0.2) + 0.2) * scenes.length);
|
||||
const campaignIndex = getCampaignIndex(scenes.length);
|
||||
const [scopeCampaign, sceneCampaign, paginationCampaign] = campaigns;
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user