Skip to content

Commit b0e3209

Browse files
committed
feat: plugin-search
1 parent 7b42984 commit b0e3209

File tree

7 files changed

+84
-3
lines changed

7 files changed

+84
-3
lines changed

Diff for: packages/@vuepress/plugin-search/.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__tests__
2+
__mocks__

Diff for: packages/@vuepress/plugin-search/README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# @vuepress/plugin-search
2+
3+
> header-based search plugin for vuepress
4+
5+
## Usage
6+
7+
1. Enable this plugin:
8+
9+
```js
10+
// .vuepress/config.js or themedir/index.js
11+
12+
module.exports = {
13+
plugins: [
14+
['@vuepress/search', {
15+
searchMaxSuggestions: 10
16+
}]
17+
],
18+
// Tweak the default color via palette.
19+
palette: {
20+
$accentColor: '#b58900',
21+
$textColor: '#586e75',
22+
$borderColor: '#eaecef',
23+
$codeBgColor: '#282c34',
24+
$arrowBgColor: '#ccc'
25+
}
26+
}
27+
```
28+
29+
2. Using search component:
30+
31+
```vue
32+
import SearchBox from '@SearchBox'
33+
```
34+
35+
## Options
36+
37+
### searchMaxSuggestions
38+
39+
- Type: `number`
40+
- Default: `true`
41+
42+
Set the maximum number of results for search

Diff for: packages/@vuepress/theme-default/components/SearchBox.vue renamed to packages/@vuepress/plugin-search/SearchBox.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
</template>
3737

3838
<script>
39+
/* global SEARCH_MAX_SUGGESTIONS */
3940
export default {
4041
data () {
4142
return {
@@ -60,8 +61,8 @@ export default {
6061
return
6162
}
6263
63-
const { pages, themeConfig } = this.$site
64-
const max = themeConfig.searchMaxSuggestions || 5
64+
const { pages } = this.$site
65+
const max = SEARCH_MAX_SUGGESTIONS
6566
const localePath = this.$localePath
6667
const matches = item => (
6768
item.title &&

Diff for: packages/@vuepress/plugin-search/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const path = require('path')
2+
3+
module.exports = (options) => ({
4+
alias: {
5+
'@SearchBox':
6+
path.resolve(__dirname, 'SearchBox.vue')
7+
},
8+
define: {
9+
SEARCH_MAX_SUGGESTIONS: options.searchMaxSuggestions || 5
10+
}
11+
})

Diff for: packages/@vuepress/plugin-search/package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@vuepress/plugin-search",
3+
"version": "1.0.0",
4+
"description": "search plugin for vuepress",
5+
"main": "index.js",
6+
"publishConfig": {
7+
"access": "public"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/vuejs/vuepress.git"
12+
},
13+
"keywords": [
14+
"documentation",
15+
"vue",
16+
"vuepress",
17+
"generator"
18+
],
19+
"author": "Evan You",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/vuejs/vuepress/issues"
23+
},
24+
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-search#readme"
25+
}

Diff for: packages/@vuepress/theme-default/components/Navbar.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<script>
4040
import SidebarButton from './SidebarButton.vue'
4141
import AlgoliaSearchBox from '@AlgoliaSearchBox'
42-
import SearchBox from './SearchBox.vue'
42+
import SearchBox from '@SearchBox'
4343
import NavLinks from './NavLinks.vue'
4444
4545
export default {

0 commit comments

Comments
 (0)