Skip to content

Commit

Permalink
Merge pull request #99 from vtex-apps/fix/fixed-app-versions-on-searc…
Browse files Browse the repository at this point in the history
…h-results

Prevent search results from containing version numbers
  • Loading branch information
victorhmp authored Aug 19, 2020
2 parents 7de77a9 + 6ef4e5c commit c2ef183
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Search results pointing to urls with fixed version numbers, which might be outdated.

## [2.1.2] - 2020-06-24
### Fixed
Expand Down
10 changes: 9 additions & 1 deletion react/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ const isNotLastResult = (results: SearchResult[], index: number) =>

const isFirstResult = (index: number) => index === 0

const removeAppVersionFromSearchResult = (url: string) => {
// https://regex101.com/r/gbllfu/1
const versionRegex = /@[\d.]+/g
const containsAppVersion = versionRegex.test(url)

return containsAppVersion ? url.replace(versionRegex, '') : url
}

const Search: FC<Props> = ({ query }) => {
const queryString = query.q || ''

Expand Down Expand Up @@ -67,7 +75,7 @@ const Search: FC<Props> = ({ query }) => {
<a
className={`link c-emphasis no-underline t-body ml-auto
flex items-center dim`}
href={result.link}>
href={removeAppVersionFromSearchResult(result.link)}>
<div className="flex flex-column flex-row di">
<span>Read More</span>
<div className="ml5">
Expand Down

0 comments on commit c2ef183

Please sign in to comment.