Просмотр исходного кода

Test and remove user prefixes using regex

arvid-e 1 месяц назад
Родитель
Сommit
b95c44fee9
1 измененных файлов с 4 добавлено и 2 удалено
  1. 4 2
      apps/app/src/features/search/utils/disable-user-pages.ts

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

@@ -1,8 +1,10 @@
 import type { QueryTerms } from '~/server/interfaces/search';
 
 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');
 }