Skip to content

Commit

Permalink
fix: search links with basehref
Browse files Browse the repository at this point in the history
  • Loading branch information
felixroos committed Dec 6, 2023
1 parent 6b31160 commit 2ddd2d1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion website/src/components/Header/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import './Search.css';

import { createPortal } from 'react-dom';
import * as docSearchReact from '@docsearch/react';
const { BASE_URL } = import.meta.env;
const baseNoTrailing = BASE_URL.endsWith('/') ? BASE_URL.slice(0, -1) : BASE_URL;

/** FIXME: This is still kinda nasty, but DocSearch is not ESM ready. */
const DocSearchModal = docSearchReact.DocSearchModal || (docSearchReact as any).default.DocSearchModal;
Expand Down Expand Up @@ -89,9 +91,13 @@ export default function Search() {
const a = document.createElement('a');
a.href = item.url;
const hash = a.hash === '#overview' ? '' : a.hash;
let pathname = a.pathname;
pathname = pathname.startsWith('/') ? pathname.slice(1) : pathname;
pathname = pathname.endsWith('/') ? pathname.slice(0, -1) : pathname;
const url = `${baseNoTrailing}/${pathname}/${hash}`;
return {
...item,
url: `${a.pathname}${hash}`,
url,
};
});
}}
Expand Down

0 comments on commit 2ddd2d1

Please sign in to comment.