feat(cli): support doc search

This commit is contained in:
陈嘉涵 2019-12-09 15:38:40 +08:00
parent d9cedca9a8
commit e461a80dbe
6 changed files with 26 additions and 8 deletions

View File

@ -1,6 +1,6 @@
<template>
<div class="app">
<van-doc :config="config" :simulator="simulator">
<van-doc :lang="lang" :config="config" :simulator="simulator">
<router-view />
</van-doc>
</div>
@ -32,6 +32,11 @@ export default {
},
computed: {
lang() {
const { lang } = this.$route.meta;
return lang || '';
},
config() {
const { locales } = config.site;

View File

@ -53,8 +53,7 @@ export default {
props: {
lang: String,
config: Object,
versions: Array,
searchConfig: Object
versions: Array
},
data() {
@ -67,6 +66,10 @@ export default {
langLink() {
const { lang } = this.config.nav;
return `#${this.$route.path.replace(lang.from, lang.to)}`;
},
searchConfig() {
return this.config.searchConfig;
}
},

View File

@ -1,5 +1,5 @@
<template>
<input class="van-doc-search" :placeholder="searchPlaceholder">
<input class="van-doc-search" :placeholder="placeholder">
</template>
<script>
@ -12,8 +12,8 @@ export default {
},
computed: {
searchPlaceholder() {
return this.lang === 'zh-CN' ? '搜索文档...' : 'Search...';
placeholder() {
return this.searchConfig.placeholder || 'Search...';
}
},

View File

@ -4,7 +4,6 @@
:lang="lang"
:config="config"
:versions="versions"
:search-config="searchConfig"
@switch-version="$emit('switch-version', $event)"
/>
<doc-nav :base="base" :nav-config="config.nav" />
@ -44,7 +43,6 @@ export default {
props: {
lang: String,
versions: Array,
searchConfig: Object,
currentSimulator: Number,
simulator: String,
config: {

View File

@ -8,8 +8,10 @@
<meta http-Equiv="Cache-Control" Content="no-cache" />
<meta http-Equiv="Pragma" Content="no-cache" />
<meta http-Equiv="Expires" Content="0" />
<link href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css" rel="stylesheet" />
</head>
<body ontouchstart>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script>
</body>
</html>

View File

@ -22,6 +22,11 @@ module.exports = {
url: 'https://github.com/youzan/vant'
}
],
searchConfig: {
apiKey: '90067aecdaa2c85220e2783cd305caac',
indexName: 'vant',
placeholder: '搜索文档...'
},
nav: [
{
title: '开发指南',
@ -360,6 +365,11 @@ module.exports = {
url: 'https://github.com/youzan/vant'
}
],
searchConfig: {
apiKey: '90067aecdaa2c85220e2783cd305caac',
indexName: 'vant',
placeholder: 'Search...'
},
nav: [
{
title: 'Essentials',