mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-11 15:22:29 +02:00
feat(v2): headerlinks (#1074)
* feat(v2): headerlinks * fix test * nits * remove tictactoe: * headerIcon * nits * remove lang dropdown * fix failing test * search box * algolia search * use babel-eslint to resolve dynamic import * nits * favicon and title * Update .eslintignore
This commit is contained in:
parent
d4458b394c
commit
85336649d3
66 changed files with 1205 additions and 2292 deletions
61
v2/lib/theme/Search/index.js
Normal file
61
v2/lib/theme/Search/index.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import './styles.css';
|
||||
|
||||
class Search extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
enabled: true,
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const {siteConfig = {}, metadata = {}} = this.props;
|
||||
const {version: thisVersion, language: thisLanguage} = metadata;
|
||||
const {algolia} = siteConfig;
|
||||
|
||||
// https://github.com/algolia/docsearch/issues/352
|
||||
const isClient = typeof window !== 'undefined';
|
||||
if (isClient) {
|
||||
import('docsearch.js').then(({default: docsearch}) => {
|
||||
docsearch({
|
||||
appId: algolia.appId,
|
||||
apiKey: algolia.apiKey,
|
||||
indexName: algolia.indexName,
|
||||
inputSelector: '#search_input_react',
|
||||
algoliaOptions: JSON.parse(
|
||||
JSON.stringify(algolia.algoliaOptions)
|
||||
.replace('VERSION', thisVersion)
|
||||
.replace('LANGUAGE', thisLanguage),
|
||||
),
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.warn('Search has failed to load and now is being disabled');
|
||||
this.setState({enabled: false});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const {enabled} = this.state;
|
||||
|
||||
return enabled ? (
|
||||
<input
|
||||
id="search_input_react"
|
||||
type="search"
|
||||
placeholder="Search docs"
|
||||
aria-label="Search docs"
|
||||
/>
|
||||
) : null;
|
||||
}
|
||||
}
|
||||
|
||||
export default Search;
|
Loading…
Add table
Add a link
Reference in a new issue