Scene actors prioritized if found in title.
This commit is contained in:
@@ -7,6 +7,7 @@ import { utilsApi } from './manticore.js';
|
||||
import { HttpError } from './errors.js';
|
||||
import { fetchCountriesByAlpha2 } from './countries.js';
|
||||
import { curateStash } from './stashes.js';
|
||||
import slugify from '../utils/slugify.js';
|
||||
|
||||
export function curateActor(actor, context = {}) {
|
||||
return {
|
||||
@@ -64,7 +65,7 @@ export function curateActor(actor, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
export function sortActorsByGender(actors) {
|
||||
export function sortActorsByGender(actors, context = {}) {
|
||||
if (!actors) {
|
||||
return actors;
|
||||
}
|
||||
@@ -72,7 +73,20 @@ export function sortActorsByGender(actors) {
|
||||
const alphaActors = actors.sort((actorA, actorB) => actorA.name.localeCompare(actorB.name, 'en'));
|
||||
const genderActors = ['transsexual', 'female', 'male', undefined, null].flatMap((gender) => alphaActors.filter((actor) => actor.gender === gender));
|
||||
|
||||
return genderActors;
|
||||
const titleSlug = slugify(context.title);
|
||||
const titleActors = titleSlug ? genderActors.sort((actorA, actorB) => {
|
||||
if (titleSlug.includes(actorA.slug) && !titleSlug.includes(actorB.slug)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (titleSlug.includes(actorB.slug) && !titleSlug.includes(actorA.slug)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}) : alphaActors;
|
||||
|
||||
return titleActors;
|
||||
}
|
||||
|
||||
export async function fetchActorsById(actorIds, options = {}, reqUser) {
|
||||
|
||||
@@ -58,7 +58,7 @@ function curateScene(rawScene, assets) {
|
||||
actors: sortActorsByGender(assets.actors.map((actor) => curateActor(actor, {
|
||||
sceneDate: rawScene.effective_date,
|
||||
stashes: assets.actorStashes,
|
||||
}))),
|
||||
})), { title: rawScene.title }),
|
||||
directors: assets.directors.map((director) => ({
|
||||
id: director.id,
|
||||
slug: director.slug,
|
||||
|
||||
Reference in New Issue
Block a user