Skip to content

Local Doc Search #1671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions packages/typescriptlang-org/src/components/layout/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,35 @@ import { OpenInMyLangQuickJump } from "./LanguageRecommendation";
export const SiteNav = (props: Props) => {
const i = createInternational<typeof navCopy>(useIntl())
const IntlLink = createIntlLink(props.lang)
const loadDocSearch = () => {
const isDev = document.location.host.includes('localhost')
let customHandleSelected;

if (isDev) {
customHandleSelected = (input, event, suggestion, datasetNumber, context) => {
const urlToOpen = suggestion.url.replace("www.typescriptlang.org", "localhost:8000").replace("https", "http")
window.open(urlToOpen)
}
}


// @ts-ignore - this comes from the script above
docsearch({
apiKey: '3c2db2aef0c7ff26e8911267474a9b2c',
indexName: 'typescriptlang',
inputSelector: '.search input',
handleSelected: customHandleSelected,
});
}
// This extra bit of mis-direction ensures that non-essential code runs after
// the page is loaded
useEffect(() => {
setupStickyNavigation()

// @ts-ignore - this could come from a previous page load
if (typeof docsearch !== 'undefined') {
// @ts-ignore - just been validate
docsearch({
apiKey: '3c2db2aef0c7ff26e8911267474a9b2c',
indexName: 'typescriptlang',
inputSelector: '.search input',
});
// @ts-ignore - this comes from the script above
if (window.docsearch) {
loadDocSearch();
}

if (document.getElementById("algolia-search")) return

const searchScript = document.createElement('script');
Expand All @@ -43,13 +56,8 @@ export const SiteNav = (props: Props) => {
searchScript.async = true;
searchScript.onload = () => {
// @ts-ignore - this comes from the script above
if (typeof docsearch !== 'undefined') {
// @ts-ignore - this comes from the script above
docsearch({
apiKey: '3c2db2aef0c7ff26e8911267474a9b2c',
indexName: 'typescriptlang',
inputSelector: '.search input'
});
if (window.docsearch) {
loadDocSearch();

searchCSS.rel = 'stylesheet';
searchCSS.href = withPrefix('/css/docsearch.css');
Expand Down