refactor: checks if search results are relatives
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
+5
-1
@@ -65,7 +65,11 @@ export function CatalogSearchResultListItem(
|
||||
const analytics = useAnalytics();
|
||||
|
||||
const configApi = useApi(configApiRef);
|
||||
const to = configApi.getString('app.baseUrl').concat(result.location);
|
||||
let to = result.location;
|
||||
// Is relative url
|
||||
if (!to.match(/^([a-z]*:)?\/\//i)) {
|
||||
to = configApi.getString('app.baseUrl').concat(to);
|
||||
}
|
||||
|
||||
const handleClick = () => {
|
||||
analytics.captureEvent('discover', result.title, {
|
||||
|
||||
@@ -65,7 +65,11 @@ export const DefaultResultListItemComponent = ({
|
||||
const analytics = useAnalytics();
|
||||
const configApi = useApi(configApiRef);
|
||||
|
||||
const to = configApi.getString('app.baseUrl').concat(result.location);
|
||||
let to = result.location;
|
||||
// Is relative url
|
||||
if (!to.match(/^([a-z]*:)?\/\//i)) {
|
||||
to = configApi.getString('app.baseUrl').concat(to);
|
||||
}
|
||||
|
||||
const handleClick = () => {
|
||||
analytics.captureEvent('discover', result.title, {
|
||||
|
||||
@@ -77,7 +77,11 @@ export const TechDocsSearchResultListItem = (
|
||||
const configApi = useApi(configApiRef);
|
||||
|
||||
const handleClick = () => {
|
||||
const to = configApi.getString('app.baseUrl').concat(result.location);
|
||||
let to = result.location;
|
||||
// Is relative url
|
||||
if (!to.match(/^([a-z]*:)?\/\//i)) {
|
||||
to = configApi.getString('app.baseUrl').concat(to);
|
||||
}
|
||||
analytics.captureEvent('discover', result.title, {
|
||||
attributes: { to },
|
||||
value: rank,
|
||||
@@ -153,7 +157,11 @@ export const TechDocsSearchResultListItem = (
|
||||
};
|
||||
|
||||
const LinkWrapper = ({ children }: PropsWithChildren<{}>) => {
|
||||
const to = configApi.getString('app.baseUrl').concat(result.location);
|
||||
let to = result.location;
|
||||
// Is relative url
|
||||
if (!to.match(/^([a-z]*:)?\/\//i)) {
|
||||
to = configApi.getString('app.baseUrl').concat(to);
|
||||
}
|
||||
return asLink ? (
|
||||
<Link noTrack to={to} onClick={handleClick}>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user