Skip to content

Commit

Permalink
remove replaceUrl logic because the search is now separated
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Feb 23, 2022
1 parent 9ed974e commit af44802
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions docs/src/modules/components/AppSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Link from 'docs/src/modules/components/Link';
import { useTranslate, useUserLanguage } from 'docs/src/modules/utils/i18n';
import useLazyCSS from 'docs/src/modules/utils/useLazyCSS';
import { useRouter } from 'next/router';
import replaceUrl, { isNewLocation } from 'docs/src/modules/utils/replaceUrl';
import { isNewLocation } from 'docs/src/modules/utils/replaceUrl';

const SearchButton = styled('button')(({ theme }) => {
return {
Expand Down Expand Up @@ -306,20 +306,16 @@ export default function AppSearch() {
parseUrl.href = item.url;

let hash = parseUrl.hash;
let pathname = parseUrl.pathname;

if (['lvl2', 'lvl3'].includes(item.type)) {
// remove '#heading-' from `href` url so that the link targets <span class="anchor-link"> inside <h2> or <h3>
// this will make the title appear under the Header
hash = hash.replace('#heading-', '#');
}

// TODO: remove this logic once the migration to new structure is done.
// This logic covers us during the ~60 minutes that it takes Algolia to run a crawl and update its index.
// It also allows us to have a search bar that works in dev mode while the new structure is not pushed to production.
pathname = replaceUrl(pathname, router.asPath);

const { canonicalAs, canonicalPathname } = pathnameToLanguage(`${pathname}${hash}`);
const { canonicalAs, canonicalPathname } = pathnameToLanguage(
`${parseUrl.pathname}${hash}`,
);

return {
...item,
Expand Down

0 comments on commit af44802

Please sign in to comment.