Skip to content

Commit

Permalink
fix(v2): custom searchbar should appear even if themeconfig.algolia i…
Browse files Browse the repository at this point in the history
…s undefined
  • Loading branch information
endiliey committed Oct 29, 2019
1 parent 7714afb commit dd0cfb7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fixed a bug in which if `themeConfig.algolia` is not defined, the custom searchbar won't appear.
- Reduce memory usage consumption.
- Slightly adjust search icon position to be more aligned on small width device.
- Convert sitemap plugin to TypeScript.
Expand Down
16 changes: 7 additions & 9 deletions packages/docusaurus-theme-classic/src/theme/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function Navbar() {
const [theme, setTheme] = useTheme();
const {siteConfig = {}} = context;
const {baseUrl, themeConfig = {}} = siteConfig;
const {algolia, navbar = {}} = themeConfig;
const {navbar = {}} = themeConfig;
const {title, logo = {}, links = []} = navbar;

const showSidebar = useCallback(() => {
Expand Down Expand Up @@ -137,14 +137,12 @@ function Navbar() {
unchecked: <Sun />,
}}
/>
{algolia && (
<div className="navbar__search" key="search-box">
<SearchBar
handleSearchBarToggle={setIsSearchBarExpanded}
isSearchBarExpanded={isSearchBarExpanded}
/>
</div>
)}
<div className="navbar__search" key="search-box">
<SearchBar
handleSearchBarToggle={setIsSearchBarExpanded}
isSearchBarExpanded={isSearchBarExpanded}
/>
</div>
</div>
</div>
<div
Expand Down
51 changes: 51 additions & 0 deletions website/docs/theme-classic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
id: theme-classic
title: Classic Theme Configuration
---

_This section is a work in progress._

## Navbar

### Navbar Title & Logo

You can add a logo and title to the navbar via `themeConfig.navbar`. Logo can be placed in [static folder](static-assets.md).

```js
// docusaurus.config.js
module.exports = {
themeConfig: {
navbar: {
title: 'Site Title',
logo: {
alt: 'Site Logo',
src: 'img/logo.svg',
},
}
}
```
### Navbar Links
You can add links to the navbar via `themeConfig.navbar.links`:
```js
// docusaurus/config.js
module.exports = {
themeConfig: {
navbar: {
links: [
{
to: 'docs/docusaurus.config.js',
label: 'docusaurus.config.js',
position: 'left',
},
// ... other links
],
}
}
```
Outbound links automatically get `target="_blank" rel="noopener noreferrer"`. You can offer `target` and `rel` to customize the attributes:
## Footer
2 changes: 1 addition & 1 deletion website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
{
type: 'category',
label: 'Themes',
items: ['using-themes', 'advanced-themes'],
items: ['using-themes', 'advanced-themes', 'theme-classic'],
},
'presets',
],
Expand Down

0 comments on commit dd0cfb7

Please sign in to comment.