Skip to content
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

Add support for Algolia DocSearch #127

Merged
merged 4 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions layouts/partials/hooks/body-end.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ with .Site.Params.algolia_docsearch }}
<!-- scripts for algolia docsearch -->
{{ end }}
3 changes: 3 additions & 0 deletions layouts/partials/hooks/head-end.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ with .Site.Params.algolia_docsearch }}
<!-- stylesheet for algolia docsearch -->
{{ end }}
2 changes: 1 addition & 1 deletion layouts/partials/search-input.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ with .Site.Params.gcs_engine_id }}
{{ with or .Site.Params.gcs_engine_id .Site.Params.algolia_docsearch }}
<input type="search" class="form-control td-search-input" placeholder="&#xf002 {{ T "ui_search" }}" aria-label="{{ T "ui_search" }}" autocomplete="off">
{{ end }}
5 changes: 5 additions & 0 deletions userguide/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,17 @@ rss_sections = ["blog"]
# Google Custom Search Engine ID. Remove or comment out to disable search.
gcs_engine_id = "011217106833237091527:la2vtv2emlw"

# Enable Algolia DocSearch
algolia_docsearch = false

# User interface configuration
[params.ui]
# Enable to show the side bar menu in its compact state.
sidebar_menu_compact = false
# Set to true to disable breadcrumb navigation.
breadcrumb_disable = false
# Set to true to hide the sidebar search box (the top nav search box will still be displayed if search is enabled)
sidebar_search_disable = false
# Set to false if you don't want to display a logo (/assets/icons/logo.svg) in the top nav bar
navbar_logo = true

Expand Down
33 changes: 31 additions & 2 deletions userguide/content/en/docs/Adding content/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ By default, the section menu will show the current section fully expanded all th

Breadcrumb navigation is enabled by default. To disable breadcrumb navigation, set site param `ui.breadcrumb_disable = true` in `config.toml`.

## Configure search
## Configure GCSE search

By default Docsy uses a [Google Custom Search Engine](https://cse.google.com/cse/all) to search your site. To enable this feature, you'll first need to make sure that you have built a public production version of your site, as otherwise your site won't be crawled and indexed.

Expand Down Expand Up @@ -132,7 +132,7 @@ Once you have your search engine set up, you can add the feature to your site:
gcs_engine_id = "011737558837375720776:fsdu1nryfng"
```

### Disabling search
### Disabling GCSE search

If you don't specify a Google Custom Search Engine ID for your project, the search box won't appear in your site. If you're using the default `config.toml` from the example site and want to disable search, just comment out or remove the relevant line.

Expand All @@ -143,3 +143,32 @@ By default, the search box appears in both the top navigation bar and at the top
```
sidebar_search_disable = true
```

## Configure Algolia DocSearch

As an alternative to GCSE, you can use [Algolia DocSearch](https://community.algolia.com/docsearch/) with this theme. Algolia DocSearch is free for public documentation sites.

### Sign up for Algolia DocSearch

Complete the form at [https://community.algolia.com/docsearch/#join-docsearch-program](https://community.algolia.com/docsearch/#join-docsearch-program).

If you are accepted to the program, you will receive the JavaScript code to add to your documentation site from Algolia by email.

### Adding Algolia DocSearch

1. Enable Algolia DocSearch in `config.toml`.

```
# Enable Algolia DocSearch
algolia_docsearch = true
```

2. Remove or comment out any GCSE ID in `config.toml` as you can only have one type of search enabled. See [Disabling GCSE search](#disabling-gcse-search).

3. Disable the sidebar search in `config.toml` as this is not currently supported for Algolia DocSearch. See [Disabling the sidebar search box](#disabling-the-sidebar-search-box).

3. Add the JavaScript code provided to you by Algolia to the head and body of every page on your site. See [Add code to head or before body end](/docs/adding-content/lookandfeel/#add-code-to-head-or-before-body-end) for details.

4. Update the `inputSelector` field in the body end Javascript with the appropriate CSS selector (e.g. `.td-search-input` to use the default CSS from this theme).

When you've completed these steps the Algolia search should be enabled on your site. Search results are displayed as a drop-down under the search box, so you don't need to add any search results page.