From e1ed4e887a9e57af37e384fb08423d293502423c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Thu, 14 May 2020 11:03:29 +0200 Subject: [PATCH] fix(docsearch): use absolute URLs --- packages/docsearch-react/src/DocSearchModal.tsx | 10 ---------- packages/website/src/theme/SearchBar/index.js | 6 +++++- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/docsearch-react/src/DocSearchModal.tsx b/packages/docsearch-react/src/DocSearchModal.tsx index 9a6c47cab..f5f78607d 100644 --- a/packages/docsearch-react/src/DocSearchModal.tsx +++ b/packages/docsearch-react/src/DocSearchModal.tsx @@ -230,16 +230,6 @@ export function DocSearchModal({ return Object.values( groupBy(items, (item) => item.hierarchy.lvl1) ) - .map((items) => { - return items.map((item) => { - const url = new URL(item.url); - - return { - ...item, - url: item.url.replace(url.origin, ''), - }; - }); - }) .map(transformItems) .map((hits) => hits.map((item) => { diff --git a/packages/website/src/theme/SearchBar/index.js b/packages/website/src/theme/SearchBar/index.js index d55441c41..ad1f26332 100644 --- a/packages/website/src/theme/SearchBar/index.js +++ b/packages/website/src/theme/SearchBar/index.js @@ -112,9 +112,13 @@ function SearchBar() { }} transformItems={(items) => { return items.map((item) => { + const url = new URL(item.url); + return { ...item, - url: item.url.replace('#__docusaurus', ''), + url: item.url + .replace(url.origin, '') + .replace('#__docusaurus', ''), }; }); }}