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

View File

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