-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfbb9e6
commit 513031a
Showing
5 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#### `algolia`: Enabling Algolia DocSearch | ||
|
||
This plugin allows you to use [Algolia DocSearch](https://community.algolia.com/docsearch/) for your site. | ||
|
||
To enable it, add `algolia` to your site's plugins, and supply the required options via the `pluginsContext`. | ||
|
||
Name | Type | Default | Description | ||
---- | ---- | ------- | ------ | ||
apiKey | `String` || The API key for your site's Algolia DocSearch setup | ||
indexName | `String` || The index name for your site's Algolia DocSearch setup | ||
algoliaOptions | `Object` | `{}` | A JSON object specifying [additional options for DocSearch](https://community.algolia.com/docsearch/behavior.html#algoliaoptions) | ||
debug | `Boolean` | `false` | Whether to turn on debug mode to allow inspection of CSS styles for the dropdown | ||
|
||
```js | ||
site.json | ||
{ | ||
... | ||
"plugins": [ | ||
"algolia" | ||
], | ||
"pluginsContext": { | ||
"algolia": { | ||
"apiKey": "25626fae796133dc1e734c6bcaaeac3c", // replace with your site's api key | ||
"indexName": "docsearch", // replace with your site's index name | ||
"algoliaOptions": { "hitsPerPage": 10 }, // optional | ||
"debug": false // optional | ||
} | ||
} | ||
} | ||
``` | ||
|
||
To connect the `searchbar` component to Algolia DocSearch, add the `algolia` key. | ||
|
||
```html | ||
<searchbar placeholder="Search" algolia menu-align-right> | ||
``` | ||
|
||
Alternatively, if you are using a custom search bar, you can assign the input field the id `algolia-search-input` to connect it to Algolia DocSearch. | ||
|
||
```html | ||
<input id="algolia-search-input"> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const ALGOLIA_CSS_URL = 'https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css'; | ||
const ALGOLIA_JS_URL = 'https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js'; | ||
const ALGOLIA_INPUT_SELECTOR = '#algolia-search-input'; | ||
|
||
function buildAlgoliaInitScript(pluginContext) { | ||
return `<script> | ||
function initAlgolia() { | ||
docsearch({ | ||
apiKey: "${pluginContext.apiKey}", | ||
indexName: "${pluginContext.indexName}", | ||
inputSelector: "${ALGOLIA_INPUT_SELECTOR}", | ||
algoliaOptions: ${JSON.stringify(pluginContext.algoliaOptions || {})}, | ||
debug: ${pluginContext.debug || false}, | ||
}); | ||
} | ||
MarkBind.afterSetup(initAlgolia); | ||
</script>`; | ||
} | ||
|
||
module.exports = { | ||
getLinks: (content, pluginContext, frontMatter, utils) => [utils.buildStylesheet(ALGOLIA_CSS_URL)], | ||
getScripts: (content, pluginContext, frontMatter, utils) => | ||
[utils.buildScript(ALGOLIA_JS_URL), buildAlgoliaInitScript(pluginContext)], | ||
}; |