mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-22 19:18:31 +00:00
fix: search links with basehref
This commit is contained in:
parent
6b31160bbd
commit
2ddd2d1f39
@ -6,6 +6,8 @@ import './Search.css';
|
|||||||
|
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import * as docSearchReact from '@docsearch/react';
|
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. */
|
/** FIXME: This is still kinda nasty, but DocSearch is not ESM ready. */
|
||||||
const DocSearchModal = docSearchReact.DocSearchModal || (docSearchReact as any).default.DocSearchModal;
|
const DocSearchModal = docSearchReact.DocSearchModal || (docSearchReact as any).default.DocSearchModal;
|
||||||
@ -89,9 +91,13 @@ export default function Search() {
|
|||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = item.url;
|
a.href = item.url;
|
||||||
const hash = a.hash === '#overview' ? '' : a.hash;
|
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 {
|
return {
|
||||||
...item,
|
...item,
|
||||||
url: `${a.pathname}${hash}`,
|
url,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user