Scene actors prioritized if found in title.
This commit is contained in:
parent
899873d651
commit
2f52db192b
|
@ -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,
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
const substitutes = {
|
||||
à: 'a',
|
||||
á: 'a',
|
||||
ä: 'a',
|
||||
å: 'a',
|
||||
ã: 'a',
|
||||
æ: 'ae',
|
||||
ç: 'c',
|
||||
è: 'e',
|
||||
é: 'e',
|
||||
ë: 'e',
|
||||
ẽ: 'e',
|
||||
ì: 'i',
|
||||
í: 'i',
|
||||
ï: 'i',
|
||||
ĩ: 'i',
|
||||
ǹ: 'n',
|
||||
ń: 'n',
|
||||
ñ: 'n',
|
||||
ò: 'o',
|
||||
ó: 'o',
|
||||
ö: 'o',
|
||||
õ: 'o',
|
||||
ø: 'o',
|
||||
œ: 'oe',
|
||||
ß: 'ss',
|
||||
ù: 'u',
|
||||
ú: 'u',
|
||||
ü: 'u',
|
||||
ũ: 'u',
|
||||
ỳ: 'y',
|
||||
ý: 'y',
|
||||
ÿ: 'y',
|
||||
ỹ: 'y',
|
||||
};
|
||||
|
||||
export default function slugify(strings, delimiter = '-', {
|
||||
encode = false,
|
||||
removeAccents = true,
|
||||
removePunctuation = false,
|
||||
limit = 1000,
|
||||
} = {}) {
|
||||
if (!strings || (typeof strings !== 'string' && !Array.isArray(strings))) {
|
||||
return strings;
|
||||
}
|
||||
|
||||
const slugComponents = []
|
||||
.concat(strings)
|
||||
.filter(Boolean)
|
||||
.flatMap((string) => string
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(removePunctuation && /[.,:;'"_-]/g, '')
|
||||
.match(/[A-Za-zÀ-ÖØ-öø-ÿ0-9]+/g));
|
||||
|
||||
if (!slugComponents) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const slug = slugComponents.reduce((acc, component, index) => {
|
||||
const accSlug = `${acc}${index > 0 ? delimiter : ''}${component}`;
|
||||
|
||||
if (accSlug.length < limit) {
|
||||
if (removeAccents) {
|
||||
return accSlug.replace(/[à-ÿ]/g, (match) => substitutes[match] || '');
|
||||
}
|
||||
|
||||
return accSlug;
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, '');
|
||||
|
||||
return encode ? encodeURI(slug) : slug;
|
||||
}
|
Loading…
Reference in New Issue