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.

fix: unencoded url for categories #2551

Merged
3 commits merged into from Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/common/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ export const slugify = (text) =>
.toLowerCase()
.trim() // Remove whitespace from both sides of a string
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w-]+/g, '') // Remove all non-word chars
.replace(/--+/g, '-') // Replace multiple - with single -

export const unslugify = (slug) => {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/academy/components/_search-banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,12 @@ const SearchBanner = ({ hidden }: SearchBannerProps) => {

const handleHref = (category) => {
if (isBrowser() && window.location.pathname.includes('/academy/videos')) {
return `/academy/search?type=video&category=${slugify(category)}`
return `/academy/search?type=video&category=${encodeURIComponent(slugify(category))}`
}
if (isBrowser() && window.location.pathname.includes('/academy/blog')) {
return `/academy/search?type=article&category=${slugify(category)}`
return `/academy/search?type=article&category=${encodeURIComponent(slugify(category))}`
}
return `/academy/search?category=${slugify(category)}`
return `/academy/search?category=${encodeURIComponent(slugify(category))}`
}

return (
Expand Down
20 changes: 19 additions & 1 deletion src/pages/academy/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,24 @@ const SearchPage = () => {
: total_article
} of ${total_article} results`

// This is a temporary solution without adding slug to the combined_filter_type
// array from the constant file. This can be refactored in the future but
// requires a change in the logic for both SearchBanner and search page.
const getCategoryText = () => {
switch (category_type) {
case 'cfds':
return 'CFDs'
case 'dbot':
return 'DBot'
case 'dtrader':
return 'DTrader'
case 'deriv-mt5':
return 'Deriv MT5'
default:
return unslugify(category_type)
}
}

return (
<Layout type="academy" margin_top={'14.4'}>
<SEO
Expand Down Expand Up @@ -320,7 +338,7 @@ const SearchPage = () => {
Selection for
</Header>
<Header type="heading-2" as="span" color="black-3" weight="normal">
{unslugify(category_type)}
{getCategoryText()}
</Header>
</>
)}
Expand Down