Skip to content

Commit 7a1ccfd

Browse files
committed
improve functions documentation
1 parent 7d830af commit 7a1ccfd

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,21 @@ VuePress theme.
3131

3232
### Functions
3333

34-
You can define the following functions:
34+
You can define functions to hook into various seach features. The functions that can be implemented are as follows:
3535

3636
```ts
3737
/**
3838
* Augment, adjust, or manipulate the suggestions shown to users.
3939
*/
4040
async function processSuggestions(suggestions: Suggestion[], queryString: string, queryTerms: string[]): Suggestion[]
41+
4142
/**
4243
* Callback function to call when a user clicks on a suggestion.
4344
*/
4445
async function onGoToSuggestion(index: number, suggestion: Suggestion, queryString: string, queryTerms: string[])
4546
```
4647

47-
You can provide it like so:
48+
Functions are provided to the plugin like so:
4849

4950
```js
5051
const fs = require('fs');
@@ -53,17 +54,19 @@ const { path } = require('@vuepress/shared-utils');
5354
module.exports = {
5455
plugins: [
5556
['fulltext-search', {
57+
// provide the contents of a JavaScript file
5658
functions: fs.readFileSync(path.resolve(__dirname, 'fulltextSearchFunctions.js')),
5759
}],
5860
]
5961
}
6062
```
6163

62-
For example, in `fulltextSearchFunctions.js`:
64+
For example, in `fulltextSearchFunctions.js`, you might have:
6365

6466
```js
6567
export async function processSuggestions(suggestions, queryString, queryTerms) {
6668
if (queryString) {
69+
// add a suggestion to start a search in an external service
6770
suggestions.push({
6871
path: 'https://sourcegraph.com/search?patternType=literal&q=',
6972
slug: queryString,
@@ -77,7 +80,7 @@ export async function processSuggestions(suggestions, queryString, queryTerms) {
7780
}
7881
7982
export async function onGoToSuggestion() {
80-
// some analytics stuff
83+
// create an analytics event
8184
}
8285
```
8386

0 commit comments

Comments
 (0)