ant-design/site/theme/template/Layout/Header/algolia-config.ts
二货机器人 5b8e4e51e9
chore: Compatible for @types/react@18 (#34937)
* chore: bump types def

* chore: part ts def

* chore: part ts def

* chore: part ts def

* chore: part ts def

* chore: part ts def

* chore: part ts def

* chore: part ts def

* chore: part ts def

* chore: part ts def

* chore: part ts def

* chore: free --legacy-peer-deps

* chore: ignore peer

* chore: fix ts logic

* chore: use fork docsearch

* chore: fix demo ts
2022-04-08 22:55:42 +08:00

29 lines
889 B
TypeScript

import { DocSearchHit } from 'docsearch-react-fork/dist/esm/types';
let _internalATag: HTMLAnchorElement | null;
export function transformHitUrl(hitUrl: string) {
_internalATag = _internalATag || document.createElement('a');
// `new URL` is not supported in IE
_internalATag.href = hitUrl;
return `${_internalATag.pathname}${window.location.search || ''}${_internalATag.hash}`;
}
export const AlgoliaConfig = {
appId: 'BH4D9OD16A',
apiKey: '60ac2c1a7d26ab713757e4a081e133d0',
indexName: 'ant_design',
getSearchParams(isZhCN: boolean) {
return { facetFilters: [`tags:${isZhCN ? 'cn' : 'en'}`] };
},
transformData(hits: DocSearchHit[]) {
hits.forEach(hit => {
hit.url = transformHitUrl(hit.url);
});
return hits;
},
debug: false, // Set debug to true if you want to inspect the dropdown
};
export type IAlgoliaConfig = typeof AlgoliaConfig;