Переглянути джерело

Test and remove user prefixes using regex

arvid-e 1 місяць тому
батько
коміт
b95c44fee9

+ 4 - 2
apps/app/src/features/search/utils/disable-user-pages.ts

@@ -1,8 +1,10 @@
 import type { QueryTerms } from '~/server/interfaces/search';
 import type { QueryTerms } from '~/server/interfaces/search';
 
 
 export function excludeUserPagesFromQuery(terms: QueryTerms): void {
 export function excludeUserPagesFromQuery(terms: QueryTerms): void {
-  terms.prefix = terms.prefix.filter((p) => !p.startsWith('/user'));
-  terms.not_prefix = terms.not_prefix.filter((p) => !p.startsWith('/user'));
+  const userRegex: RegExp = /^\/user($|\/)/;
+
+  terms.prefix = terms.prefix.filter((p) => !userRegex.test(p));
+  terms.not_prefix = terms.not_prefix.filter((p) => !userRegex.test(p));
 
 
   terms.not_prefix.push('/user');
   terms.not_prefix.push('/user');
 }
 }