Compare commits

...

2 Commits

Author SHA1 Message Date
DebaucheryLibrarian 687964cb26 0.11.3 2024-03-21 03:49:08 +01:00
DebaucheryLibrarian 2f52db192b Scene actors prioritized if found in title. 2024-03-21 03:49:03 +01:00
5 changed files with 95 additions and 6 deletions

4
package-lock.json generated
View File

@ -1,11 +1,11 @@
{
"name": "traxxx-web",
"version": "0.11.2",
"version": "0.11.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "0.11.2",
"version": "0.11.3",
"dependencies": {
"@brillout/json-serializer": "^0.5.8",
"@dicebear/collection": "^7.0.5",

View File

@ -70,5 +70,5 @@
"postcss-custom-media": "^10.0.2",
"postcss-nesting": "^12.0.2"
},
"version": "0.11.2"
"version": "0.11.3"
}

View File

@ -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) {

View File

@ -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,

75
utils/slugify.js Executable file
View File

@ -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;
}