Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit f753189

Browse files
Sean Hoseanho96
andauthored
fix: unencoded url for categories (#2551)
* fix: unencoded url for categories * chore: remove console log * fix: casing of category title Co-authored-by: Sean Ho <[email protected]>
1 parent fe196f8 commit f753189

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/common/utility.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ export const slugify = (text) =>
345345
.toLowerCase()
346346
.trim() // Remove whitespace from both sides of a string
347347
.replace(/\s+/g, '-') // Replace spaces with -
348-
.replace(/[^\w-]+/g, '') // Remove all non-word chars
349348
.replace(/--+/g, '-') // Replace multiple - with single -
350349

351350
export const unslugify = (slug) => {

src/pages/academy/components/_search-banner.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,12 +749,12 @@ const SearchBanner = ({ hidden }: SearchBannerProps) => {
749749

750750
const handleHref = (category) => {
751751
if (isBrowser() && window.location.pathname.includes('/academy/videos')) {
752-
return `/academy/search?type=video&category=${slugify(category)}`
752+
return `/academy/search?type=video&category=${encodeURIComponent(slugify(category))}`
753753
}
754754
if (isBrowser() && window.location.pathname.includes('/academy/blog')) {
755-
return `/academy/search?type=article&category=${slugify(category)}`
755+
return `/academy/search?type=article&category=${encodeURIComponent(slugify(category))}`
756756
}
757-
return `/academy/search?category=${slugify(category)}`
757+
return `/academy/search?category=${encodeURIComponent(slugify(category))}`
758758
}
759759

760760
return (

src/pages/academy/search/index.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,24 @@ const SearchPage = () => {
290290
: total_article
291291
} of ${total_article} results`
292292

293+
// This is a temporary solution without adding slug to the combined_filter_type
294+
// array from the constant file. This can be refactored in the future but
295+
// requires a change in the logic for both SearchBanner and search page.
296+
const getCategoryText = () => {
297+
switch (category_type) {
298+
case 'cfds':
299+
return 'CFDs'
300+
case 'dbot':
301+
return 'DBot'
302+
case 'dtrader':
303+
return 'DTrader'
304+
case 'deriv-mt5':
305+
return 'Deriv MT5'
306+
default:
307+
return unslugify(category_type)
308+
}
309+
}
310+
293311
return (
294312
<Layout type="academy" margin_top={'14.4'}>
295313
<SEO
@@ -320,7 +338,7 @@ const SearchPage = () => {
320338
Selection for
321339
</Header>
322340
<Header type="heading-2" as="span" color="black-3" weight="normal">
323-
{unslugify(category_type)}
341+
{getCategoryText()}
324342
</Header>
325343
</>
326344
)}

0 commit comments

Comments
 (0)