@@ -31,20 +31,21 @@ VuePress theme.
31
31
32
32
### Functions
33
33
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 :
35
35
36
36
``` ts
37
37
/**
38
38
* Augment, adjust, or manipulate the suggestions shown to users.
39
39
*/
40
40
async function processSuggestions(suggestions : Suggestion [], queryString : string , queryTerms : string []): Suggestion []
41
+
41
42
/**
42
43
* Callback function to call when a user clicks on a suggestion.
43
44
*/
44
45
async function onGoToSuggestion(index : number , suggestion : Suggestion , queryString : string , queryTerms : string [])
45
46
```
46
47
47
- You can provide it like so :
48
+ Functions are provided to the plugin like so :
48
49
49
50
` ` ` js
50
51
const fs = require('fs');
@@ -53,17 +54,19 @@ const { path } = require('@vuepress/shared-utils');
53
54
module.exports = {
54
55
plugins: [
55
56
['fulltext-search', {
57
+ // provide the contents of a JavaScript file
56
58
functions: fs.readFileSync(path.resolve(__dirname, 'fulltextSearchFunctions.js')),
57
59
}],
58
60
]
59
61
}
60
62
` ` `
61
63
62
- For example , in ` fulltextSearchFunctions.js ` :
64
+ For example , in ` fulltextSearchFunctions.js ` , you might have :
63
65
64
66
` ` ` js
65
67
export async function processSuggestions(suggestions, queryString, queryTerms) {
66
68
if (queryString) {
69
+ // add a suggestion to start a search in an external service
67
70
suggestions.push({
68
71
path: 'https://sourcegraph.com/search?patternType=literal&q=',
69
72
slug: queryString,
@@ -77,7 +80,7 @@ export async function processSuggestions(suggestions, queryString, queryTerms) {
77
80
}
78
81
79
82
export async function onGoToSuggestion() {
80
- // some analytics stuff
83
+ // create an analytics event
81
84
}
82
85
` ` `
83
86
0 commit comments