Support pluses in lens makes

This commit is contained in:
Sam Becker 2025-04-20 12:33:51 -05:00
parent b3dba5f676
commit f8c0a46f2f
2 changed files with 15 additions and 11 deletions

View File

@ -7,13 +7,17 @@ import { Lens } from '@/lens';
export const GENERATE_STATIC_PARAMS_LIMIT = 1000; export const GENERATE_STATIC_PARAMS_LIMIT = 1000;
export const PHOTO_DEFAULT_LIMIT = 100; export const PHOTO_DEFAULT_LIMIT = 100;
// Trim whitespace const DB_PARAMETERIZE_REPLACEMENTS = [
// Make lowercase [',', ''],
// Remove commas, slashes ['/', ''],
// Replace spaces with dashes ['+', '-'],
[' ', '-'],
];
const parameterizeForDb = (field: string) => const parameterizeForDb = (field: string) =>
// eslint-disable-next-line max-len DB_PARAMETERIZE_REPLACEMENTS.reduce((acc, [from, to]) =>
`REPLACE(REPLACE(REPLACE(LOWER(TRIM(${field})), ',', ''), '/', ''), ' ', '-')`; `REPLACE(${acc}, '${from}', '${to}')`
, `LOWER(TRIM(${field}))`);
export type GetPhotosOptions = { export type GetPhotosOptions = {
sortBy?: 'createdAt' | 'createdAtAsc' | 'takenAt' | 'priority' sortBy?: 'createdAt' | 'createdAtAsc' | 'takenAt' | 'priority'

View File

@ -22,11 +22,11 @@ export const parameterize = (
) => ) =>
string string
.trim() .trim()
// Replaces spaces, underscores, slashes,and dashes with dashes // Replace spaces, underscores, slashes, pluses, dashes with dashes
.replaceAll(/[\s_]/gi, '-') .replaceAll(/[\s_+]/gi, '-')
// Removes punctuation // Remove punctuation
.replaceAll(/['"!@#$%^&*()_+=[\]{};:/?,<>\\/|`~]/gi, '') .replaceAll(/['"!@#$%^&*()=[\]{};:/?,<>\\/|`~]/gi, '')
// Removes all non-alphanumeric characters // Removes non-alphanumeric characters, if configured
.replaceAll( .replaceAll(
shouldRemoveNonAlphanumeric shouldRemoveNonAlphanumeric
? /([^a-z0-9-])/gi ? /([^a-z0-9-])/gi