refactor: checks if search results are relatives

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2022-07-01 10:37:42 +02:00
parent cd7c1b3007
commit aa9cddeaa7
3 changed files with 20 additions and 4 deletions
@@ -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}