From a010d641e6a52e65f03df3a0b555f57b306b51b4 Mon Sep 17 00:00:00 2001
From: ULIVZ <472590061@qq.com>
Date: Sun, 22 Apr 2018 03:36:16 +0800
Subject: [PATCH 01/16] feat: algolia search - basically migrated
---
docs/.vuepress/config.js | 6 ++
lib/default-theme/AlgoliaSearchBox.vue | 120 +++++++++++++++++++++++++
lib/default-theme/Navbar.vue | 15 +++-
yarn.lock | 116 ++++++++++++++++++++++--
4 files changed, 250 insertions(+), 7 deletions(-)
create mode 100644 lib/default-theme/AlgoliaSearchBox.vue
diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js
index 278669cced..dc8ccabdd9 100644
--- a/docs/.vuepress/config.js
+++ b/docs/.vuepress/config.js
@@ -28,6 +28,12 @@ module.exports = {
repo: 'vuejs/vuepress',
editLinks: true,
docsDir: 'docs',
+ algolia: {
+ appId: 'BH4D9OD16A',
+ apiKey: '85cc3221c9f23bfbaa4e3913dd7625ea',
+ indexName: 'vuejs',
+ algoliaOptions: { facetFilters: ["version:v2"] }
+ },
locales: {
'/': {
label: 'English',
diff --git a/lib/default-theme/AlgoliaSearchBox.vue b/lib/default-theme/AlgoliaSearchBox.vue
new file mode 100644
index 0000000000..ef5378c81f
--- /dev/null
+++ b/lib/default-theme/AlgoliaSearchBox.vue
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
diff --git a/lib/default-theme/Navbar.vue b/lib/default-theme/Navbar.vue
index 571e777aa5..1d6711752b 100644
--- a/lib/default-theme/Navbar.vue
+++ b/lib/default-theme/Navbar.vue
@@ -12,7 +12,8 @@
@@ -20,11 +21,21 @@
diff --git a/yarn.lock b/yarn.lock
index a30b0c56a2..8d9fdc6fb2 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -106,6 +106,10 @@ acorn@^5.0.0, acorn@^5.0.3, acorn@^5.3.0, acorn@^5.4.1, acorn@^5.5.0:
version "5.5.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.5.3.tgz#f473dd47e0277a08e28e9bec5aeeb04751f0b8c9"
+agentkeepalive@^2.2.0:
+ version "2.2.0"
+ resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-2.2.0.tgz#c5d1bd4b129008f1163f236f86e5faea2026e2ef"
+
ajv-keywords@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.1.1.tgz#617997fc5f60576894c435f940d819e135b80762"
@@ -139,6 +143,26 @@ ajv@^6.0.1, ajv@^6.1.0:
json-schema-traverse "^0.3.0"
uri-js "^3.0.2"
+algoliasearch@^3.24.5:
+ version "3.27.0"
+ resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-3.27.0.tgz#675b7f2d186e5785a1553369b15d47b53d4efb31"
+ dependencies:
+ agentkeepalive "^2.2.0"
+ debug "^2.6.8"
+ envify "^4.0.0"
+ es6-promise "^4.1.0"
+ events "^1.1.0"
+ foreach "^2.0.5"
+ global "^4.3.2"
+ inherits "^2.0.1"
+ isarray "^2.0.1"
+ load-script "^1.0.0"
+ object-keys "^1.0.11"
+ querystring-es3 "^0.2.1"
+ reduce "^1.0.1"
+ semver "^5.1.0"
+ tunnel-agent "^0.6.0"
+
align-text@^0.1.1, align-text@^0.1.3:
version "0.1.4"
resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117"
@@ -329,6 +353,12 @@ atob@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.0.tgz#ab2b150e51d7b122b9efc8d7340c06b6c41076bc"
+autocomplete.js@^0.29.0:
+ version "0.29.0"
+ resolved "https://registry.yarnpkg.com/autocomplete.js/-/autocomplete.js-0.29.0.tgz#0185f7375ee9daf068f7d52d794bc90dcd739fd7"
+ dependencies:
+ immediate "^3.2.3"
+
autoprefixer@^6.3.1:
version "6.7.7"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-6.7.7.tgz#1dbd1c835658e35ce3f9984099db00585c782014"
@@ -1597,6 +1627,15 @@ dir-glob@^2.0.0:
arrify "^1.0.1"
path-type "^3.0.0"
+docsearch.js@^2.5.2:
+ version "2.5.2"
+ resolved "https://registry.yarnpkg.com/docsearch.js/-/docsearch.js-2.5.2.tgz#1a3521c92e5f252cc522c57357ef1c47b945b381"
+ dependencies:
+ algoliasearch "^3.24.5"
+ autocomplete.js "^0.29.0"
+ hogan.js "^3.0.2"
+ to-factory "^1.0.0"
+
doctrine@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d"
@@ -1616,6 +1655,10 @@ dom-serializer@0:
domelementtype "~1.1.1"
entities "~1.1.1"
+dom-walk@^0.1.0:
+ version "0.1.1"
+ resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018"
+
domain-browser@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.2.0.tgz#3d31f50191a6749dd1375a7f522e823d42e54eda"
@@ -1743,6 +1786,13 @@ entities@^1.1.1, entities@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0"
+envify@^4.0.0:
+ version "4.1.0"
+ resolved "https://registry.yarnpkg.com/envify/-/envify-4.1.0.tgz#f39ad3db9d6801b4e6b478b61028d3f0b6819f7e"
+ dependencies:
+ esprima "^4.0.0"
+ through "~2.3.4"
+
errno@^0.1.3, errno@~0.1.7:
version "0.1.7"
resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.7.tgz#4684d71779ad39af177e3f007996f7c67c852618"
@@ -1777,7 +1827,7 @@ es-to-primitive@^1.1.1:
is-date-object "^1.0.1"
is-symbol "^1.0.1"
-es6-promise@^4.2.4:
+es6-promise@^4.1.0, es6-promise@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.4.tgz#dc4221c2b16518760bd8c39a52d8f356fc00ed29"
@@ -1905,7 +1955,7 @@ esutils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
-events@^1.0.0:
+events@^1.0.0, events@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924"
@@ -2407,6 +2457,13 @@ global-dirs@^0.1.0:
dependencies:
ini "^1.3.4"
+global@^4.3.2:
+ version "4.3.2"
+ resolved "https://registry.yarnpkg.com/global/-/global-4.3.2.tgz#e76989268a6c74c38908b1305b10fc0e394e9d0f"
+ dependencies:
+ min-document "^2.19.0"
+ process "~0.5.1"
+
globals@^11.0.1:
version "11.4.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.4.0.tgz#b85c793349561c16076a3c13549238a27945f1bc"
@@ -2616,6 +2673,13 @@ hoek@4.x.x:
version "4.2.1"
resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.1.tgz#9634502aa12c445dd5a7c5734b572bb8738aacbb"
+hogan.js@^3.0.2:
+ version "3.0.2"
+ resolved "https://registry.yarnpkg.com/hogan.js/-/hogan.js-3.0.2.tgz#4cd9e1abd4294146e7679e41d7898732b02c7bfd"
+ dependencies:
+ mkdirp "0.3.0"
+ nopt "1.0.10"
+
hosted-git-info@^2.1.4:
version "2.6.0"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.6.0.tgz#23235b29ab230c576aab0d4f13fc046b0b038222"
@@ -2730,6 +2794,10 @@ ignore@^3.3.3, ignore@^3.3.5:
version "3.3.7"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021"
+immediate@^3.2.3:
+ version "3.2.3"
+ resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.2.3.tgz#d140fa8f614659bd6541233097ddaac25cdd991c"
+
import-lazy@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43"
@@ -3108,6 +3176,10 @@ isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
+isarray@^2.0.1:
+ version "2.0.4"
+ resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.4.tgz#38e7bcbb0f3ba1b7933c86ba1894ddfc3781bbb7"
+
isemail@3.x.x:
version "3.1.2"
resolved "https://registry.yarnpkg.com/isemail/-/isemail-3.1.2.tgz#937cf919002077999a73ea8b1951d590e84e01dd"
@@ -3627,6 +3699,10 @@ load-json-file@^4.0.0:
pify "^3.0.0"
strip-bom "^3.0.0"
+load-script@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/load-script/-/load-script-1.0.0.tgz#0491939e0bee5643ee494a7e3da3d2bac70c6ca4"
+
loader-runner@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.3.0.tgz#f482aea82d543e07921700d5a46ef26fdac6b8a2"
@@ -3948,6 +4024,12 @@ mimic-fn@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
+min-document@^2.19.0:
+ version "2.19.0"
+ resolved "https://registry.yarnpkg.com/min-document/-/min-document-2.19.0.tgz#7bd282e3f5842ed295bb748cdd9f1ffa2c824685"
+ dependencies:
+ dom-walk "^0.1.0"
+
mini-css-extract-plugin@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/mini-css-extract-plugin/-/mini-css-extract-plugin-0.4.0.tgz#ff3bf08bee96e618e177c16ca6131bfecef707f9"
@@ -4010,6 +4092,10 @@ mixin-deep@^1.2.0:
for-in "^1.0.2"
is-extendable "^1.0.1"
+mkdirp@0.3.0:
+ version "0.3.0"
+ resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.3.0.tgz#1bbf5ab1ba827af23575143490426455f481fe1e"
+
mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
@@ -4158,6 +4244,12 @@ node-pre-gyp@^0.6.39:
tar "^2.2.1"
tar-pack "^3.4.0"
+nopt@1.0.10:
+ version "1.0.10"
+ resolved "https://registry.yarnpkg.com/nopt/-/nopt-1.0.10.tgz#6ddd21bd2a31417b92727dd585f8a6f37608ebee"
+ dependencies:
+ abbrev "1"
+
nopt@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d"
@@ -4264,7 +4356,7 @@ object-copy@^0.1.0:
define-property "^0.2.5"
kind-of "^3.0.3"
-object-keys@^1.0.8:
+object-keys@^1.0.11, object-keys@^1.0.8, object-keys@~1.0.0:
version "1.0.11"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"
@@ -4933,6 +5025,10 @@ process@^0.11.10:
version "0.11.10"
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
+process@~0.5.1:
+ version "0.5.2"
+ resolved "https://registry.yarnpkg.com/process/-/process-0.5.2.tgz#1638d8a8e34c2f440a91db95ab9aeb677fc185cf"
+
progress@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f"
@@ -5005,7 +5101,7 @@ query-string@^4.1.0:
object-assign "^4.1.0"
strict-uri-encode "^1.0.0"
-querystring-es3@^0.2.0:
+querystring-es3@^0.2.0, querystring-es3@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
@@ -5138,6 +5234,12 @@ reduce-function-call@^1.0.1:
dependencies:
balanced-match "^0.4.2"
+reduce@^1.0.1:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/reduce/-/reduce-1.0.1.tgz#14fa2e5ff1fc560703a020cbb5fbaab691565804"
+ dependencies:
+ object-keys "~1.0.0"
+
regenerate@^1.2.1:
version "1.3.3"
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.3.tgz#0c336d3980553d755c39b586ae3b20aa49c82b7f"
@@ -5981,7 +6083,7 @@ through2@^2.0.0, through2@^2.0.2:
readable-stream "^2.1.5"
xtend "~4.0.1"
-through@2, "through@>=2.2.7 <3", through@^2.3.6:
+through@2, "through@>=2.2.7 <3", through@^2.3.6, through@~2.3.4:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
@@ -6013,6 +6115,10 @@ to-arraybuffer@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43"
+to-factory@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/to-factory/-/to-factory-1.0.0.tgz#8738af8bd97120ad1d4047972ada5563bf9479b1"
+
to-object-path@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/to-object-path/-/to-object-path-0.3.0.tgz#297588b7b0e7e0ac08e04e672f85c1f4999e17af"
From 330d6f0f5a49c97a5682a36adc896c8e29c2037c Mon Sep 17 00:00:00 2001
From: ULIVZ <472590061@qq.com>
Date: Sun, 22 Apr 2018 04:40:01 +0800
Subject: [PATCH 02/16] fix: enhance style
---
lib/default-theme/AlgoliaSearchBox.vue | 48 ++++++++++++++++++--------
package.json | 1 +
2 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/lib/default-theme/AlgoliaSearchBox.vue b/lib/default-theme/AlgoliaSearchBox.vue
index ef5378c81f..5a762d00a5 100644
--- a/lib/default-theme/AlgoliaSearchBox.vue
+++ b/lib/default-theme/AlgoliaSearchBox.vue
@@ -56,7 +56,7 @@ $info = #1C90F3
text-align left
&:before
border-color #999
- .ds-dataset-1
+ [class*=ds-dataset-]
border none
padding 0
.ds-suggestions
@@ -78,27 +78,17 @@ $info = #1C90F3
background rgba(255, 255, 255, 0.6)
.algolia-docsearch-suggestion--wrapper
padding 0
- /*.algolia-docsearch-suggestion--content,*/
.algolia-docsearch-suggestion--title
font-weight 600
- margin-bottom: 0
+ margin-bottom 0
color $dark
.algolia-docsearch-suggestion--subcategory-column
- float none
- width 150px
- min-width 150px
- display table-cell
vertical-align top
padding 5px 7px 5px 5px
border-color $border
background #f1f3f5
&:after
display none
- .algolia-docsearch-suggestion--content
- float none
- display table-cell
- width 100%
- vertical-align top
.algolia-docsearch-suggestion--subcategory-column-text
color #555
.algolia-docsearch-footer
@@ -107,10 +97,38 @@ $info = #1C90F3
background-color #e7edf3!important
color $dark
-
@media (min-width: $MQMobile)
- .ds-dropdown-menu
- min-width: 515px!important
+ .algolia-search-wrapper
+ .algolia-autocomplete
+ .algolia-docsearch-suggestion
+ .algolia-docsearch-suggestion--subcategory-column
+ float none
+ width 150px
+ min-width 150px
+ display table-cell
+ .algolia-docsearch-suggestion--content
+ float none
+ display table-cell
+ width 100%
+ vertical-align top
+ .ds-dropdown-menu
+ min-width 515px!important
+
+@media (max-width: $MQMobile)
+ .algolia-search-wrapper
+ .algolia-docsearch-suggestion--wrapper
+ padding 5px 7px 5px 5px!important
+ .algolia-docsearch-suggestion--subcategory-column
+ padding 0!important
+ background white!important
+ .algolia-docsearch-suggestion--subcategory-column-text:after
+ content " > "
+ font-size 10px
+ line-height 14.4px
+ display inline-block
+ width 5px
+ margin -3px 3px 0
+ vertical-align middle
@media (max-width: $MQMobileNarrow)
.ds-dropdown-menu
diff --git a/package.json b/package.json
index 87f1559d37..602634b5eb 100644
--- a/package.json
+++ b/package.json
@@ -51,6 +51,7 @@
"copy-webpack-plugin": "^4.5.1",
"css-loader": "^0.28.11",
"diacritics": "^1.3.0",
+ "docsearch.js": "^2.5.2",
"es6-promise": "^4.2.4",
"escape-html": "^1.0.3",
"file-loader": "^1.1.11",
From 8621a6cfcb31f87c68487efe40634343aa79baf3 Mon Sep 17 00:00:00 2001
From: ULIVZ <472590061@qq.com>
Date: Sun, 22 Apr 2018 04:48:47 +0800
Subject: [PATCH 03/16] chore: remove debug option
---
lib/default-theme/AlgoliaSearchBox.vue | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/default-theme/AlgoliaSearchBox.vue b/lib/default-theme/AlgoliaSearchBox.vue
index 5a762d00a5..0ddc5b190c 100644
--- a/lib/default-theme/AlgoliaSearchBox.vue
+++ b/lib/default-theme/AlgoliaSearchBox.vue
@@ -15,7 +15,6 @@ export default {
docsearch = docsearch.default
docsearch(Object.assign(this.options, {
inputSelector: '#algolia-search-input',
- debug: true,
autocompleteOptions: {
openOnFocus: true
}
From 075891853fcff914f96a0570b38e514fcf0f92c8 Mon Sep 17 00:00:00 2001
From: ULIVZ <472590061@qq.com>
Date: Sun, 22 Apr 2018 04:50:21 +0800
Subject: [PATCH 04/16] chore: add some comments
---
lib/default-theme/AlgoliaSearchBox.vue | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/default-theme/AlgoliaSearchBox.vue b/lib/default-theme/AlgoliaSearchBox.vue
index 0ddc5b190c..f778f282e3 100644
--- a/lib/default-theme/AlgoliaSearchBox.vue
+++ b/lib/default-theme/AlgoliaSearchBox.vue
@@ -27,8 +27,8 @@ export default {
From 702d6766b47e6fd220814b62868872d4784012ac Mon Sep 17 00:00:00 2001
From: ULIVZ <472590061@qq.com>
Date: Tue, 24 Apr 2018 00:52:09 +0800
Subject: [PATCH 11/16] feat: support algolia search per locale
---
docs/.vuepress/config.js | 12 ++++++++++
lib/default-theme/AlgoliaSearchBox.vue | 32 ++++++++++++++++++--------
lib/default-theme/Navbar.vue | 7 ++++--
3 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js
index 278669cced..9dc6650d65 100644
--- a/docs/.vuepress/config.js
+++ b/docs/.vuepress/config.js
@@ -47,6 +47,12 @@ module.exports = {
link: '/default-theme-config/'
}
],
+ algolia: {
+ appId: 'BH4D9OD16A',
+ apiKey: '85cc3221c9f23bfbaa4e3913dd7625ea',
+ indexName: 'vuejs',
+ algoliaOptions: { facetFilters: ["version:v2"] }
+ },
sidebar: {
'/guide/': genSidebarConfig('Guide')
}
@@ -55,6 +61,12 @@ module.exports = {
label: '简体中文',
selectText: '选择语言',
editLinkText: '在 GitHub 上编辑此页',
+ algolia: {
+ appId: 'BH4D9OD16A',
+ apiKey: '5638280abff9d207417bb03be05f0b25',
+ indexName: 'vuejs_cn2',
+ algoliaOptions: { facetFilters: ["version:v2"] }
+ },
nav: [
{
text: '指南',
diff --git a/lib/default-theme/AlgoliaSearchBox.vue b/lib/default-theme/AlgoliaSearchBox.vue
index eb509888c8..c27f1bbdda 100644
--- a/lib/default-theme/AlgoliaSearchBox.vue
+++ b/lib/default-theme/AlgoliaSearchBox.vue
@@ -1,6 +1,6 @@
@@ -8,15 +8,27 @@
export default {
props: ['options'],
mounted () {
- Promise.all([
- import(/* webpackChunkName: "docsearch" */ 'docsearch.js/dist/cdn/docsearch.min.js'),
- import(/* webpackChunkName: "docsearch" */ 'docsearch.js/dist/cdn/docsearch.min.css')
- ]).then(([docsearch]) => {
- docsearch = docsearch.default
- docsearch(Object.assign(this.options, {
- inputSelector: '#algolia-search-input'
- }))
- })
+ this.initialize()
+ },
+ methods: {
+ initialize () {
+ Promise.all([
+ import(/* webpackChunkName: "docsearch" */ 'docsearch.js/dist/cdn/docsearch.min.js'),
+ import(/* webpackChunkName: "docsearch" */ 'docsearch.js/dist/cdn/docsearch.min.css')
+ ]).then(([docsearch]) => {
+ docsearch = docsearch.default
+ docsearch(Object.assign(this.options, {
+ debug: true,
+ inputSelector: '#algolia-search-input'
+ }))
+ })
+ }
+ },
+ watch: {
+ options (newValue) {
+ this.$el.innerHTML = ''
+ this.initialize(newValue)
+ }
}
}
diff --git a/lib/default-theme/Navbar.vue b/lib/default-theme/Navbar.vue
index 1d6711752b..c7d86d1b44 100644
--- a/lib/default-theme/Navbar.vue
+++ b/lib/default-theme/Navbar.vue
@@ -12,7 +12,7 @@
@@ -28,8 +28,11 @@ import NavLinks from './NavLinks.vue'
export default {
components: { SidebarButton, NavLinks, SearchBox, AlgoliaSearchBox },
computed: {
+ algolia () {
+ return this.$themeLocaleConfig.algolia || this.$site.themeConfig.algolia || {}
+ },
isAlgoliaSearch () {
- const { algolia } = this.$site.themeConfig
+ const algolia = this.algolia
return algolia && algolia.appId && algolia.apiKey && algolia.indexName
},
isSearch() {
From ea8aa21c8ea35031539439fc6ae50a2cf4f1e975 Mon Sep 17 00:00:00 2001
From: ULIVZ <472590061@qq.com>
Date: Tue, 24 Apr 2018 01:10:14 +0800
Subject: [PATCH 12/16] docs: document algolia option
---
docs/config/README.md | 18 ++++++++++++++++++
docs/zh/config/README.md | 18 ++++++++++++++++++
lib/default-theme/Navbar.vue | 2 +-
3 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/docs/config/README.md b/docs/config/README.md
index 9bc25a3f43..06958fc960 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -98,6 +98,24 @@ The `serviceWorker` option only handles the service worker. To make your site fu
Also, only enable this if you are able to deploy your site with SSL, since service worker can only be registered under HTTPs URLs.
:::
+### algolia
+
+- Type: `Object`
+- Default: `undefined`
+
+Using `algolia` option allows you to disable the default built-in headers-based search and leverage the [algolia docsearch](https://github.com/algolia/docsearch), to enable this search, You have to provide at least `apiKey` and `indexName`:
+
+```js
+module.exports = {
+ algolia: {
+ apiKey: '',
+ indexName: ''
+ }
+}
+```
+
+Rest available options refer to [docsearch options](https://github.com/algolia/docsearch#docsearch-options).
+
### locales
- Type: `{ [path: string]: Object }`
diff --git a/docs/zh/config/README.md b/docs/zh/config/README.md
index 89b1278d42..6d6f54099c 100644
--- a/docs/zh/config/README.md
+++ b/docs/zh/config/README.md
@@ -97,6 +97,24 @@ module.exports = {
当然,仅仅只在你的网站部署后能用 SSL 的时候开启它,因为 service worker 只能在 HTTPs 的链接下注册。
:::
+### algolia
+
+- 类型: `Object`
+- 默认值: `undefined`
+
+使用 `algolia` 选项可以让你禁用掉默认的基于 headers 的搜索,从而使用 [algolia docsearch](https://github.com/algolia/docsearch)。为了使其生效,你必须提供至少 `apiKey` 和 `indexName` 这两个选项:
+
+```js
+module.exports = {
+ algolia: {
+ apiKey: '',
+ indexName: ''
+ }
+}
+```
+
+其他可用的选项可以参考 [docsearch options](https://github.com/algolia/docsearch#docsearch-options)。
+
### locales
- 类型: `{ [path: string]: Object }`
diff --git a/lib/default-theme/Navbar.vue b/lib/default-theme/Navbar.vue
index c7d86d1b44..e982d4806e 100644
--- a/lib/default-theme/Navbar.vue
+++ b/lib/default-theme/Navbar.vue
@@ -33,7 +33,7 @@ export default {
},
isAlgoliaSearch () {
const algolia = this.algolia
- return algolia && algolia.appId && algolia.apiKey && algolia.indexName
+ return algolia && algolia.apiKey && algolia.indexName
},
isSearch() {
return !this.isAlgoliaSearch && this.$site.themeConfig.search !== false
From a95aa89769c94ba14c571caaed6aeedb1cc6ccb4 Mon Sep 17 00:00:00 2001
From: ULIVZ <472590061@qq.com>
Date: Tue, 24 Apr 2018 01:14:29 +0800
Subject: [PATCH 13/16] docs: update i18n
---
docs/guide/i18n.md | 3 +++
docs/zh/guide/i18n.md | 3 +++
2 files changed, 6 insertions(+)
diff --git a/docs/guide/i18n.md b/docs/guide/i18n.md
index eb6ac4a8cc..2ae4b7c3cd 100644
--- a/docs/guide/i18n.md
+++ b/docs/guide/i18n.md
@@ -56,6 +56,8 @@ module.exports = {
label: 'English',
// text for the edit-on-github link
editLinkText: 'Edit this page on GitHub',
+ // algolia docsearch options for current locale
+ algolia: {},
nav: [
{ text: 'Nested', link: '/nested/' }
],
@@ -71,6 +73,7 @@ module.exports = {
nav: [
{ text: '嵌套', link: '/zh/nested/' }
],
+ algolia: {},
sidebar: {
'/zh/': [/* ... */],
'/zh/nested/': [/* ... */]
diff --git a/docs/zh/guide/i18n.md b/docs/zh/guide/i18n.md
index 5d97beba56..216048225c 100644
--- a/docs/zh/guide/i18n.md
+++ b/docs/zh/guide/i18n.md
@@ -53,6 +53,7 @@ module.exports = {
selectText: 'Languages',
label: 'English',
editLinkText: 'Edit this page on GitHub',
+ algolia: {},
nav: [
{ text: 'Nested', link: '/nested/' }
],
@@ -68,6 +69,8 @@ module.exports = {
label: '简体中文',
// 编辑链接文字
editLinkText: '在 GitHub 上编辑此页',
+ // 当前 locale 的 algolia docsearch 选项
+ algolia: {},
nav: [
{ text: '嵌套', link: '/zh/nested/' }
],
From 88f7435ed561c13d635b536de18c07355d2af18b Mon Sep 17 00:00:00 2001
From: ULIVZ <472590061@qq.com>
Date: Tue, 24 Apr 2018 02:19:40 +0800
Subject: [PATCH 14/16] chore: address comments
---
docs/config/README.md | 2 +-
docs/zh/config/README.md | 4 ++--
lib/default-theme/Navbar.vue | 7 ++-----
lib/noop.js | 1 +
lib/prepare.js | 8 ++++++++
lib/webpack/createBaseConfig.js | 4 ++++
6 files changed, 18 insertions(+), 8 deletions(-)
create mode 100644 lib/noop.js
diff --git a/docs/config/README.md b/docs/config/README.md
index 06958fc960..f64afeaa80 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -103,7 +103,7 @@ Also, only enable this if you are able to deploy your site with SSL, since servi
- Type: `Object`
- Default: `undefined`
-Using `algolia` option allows you to disable the default built-in headers-based search and leverage the [algolia docsearch](https://github.com/algolia/docsearch), to enable this search, You have to provide at least `apiKey` and `indexName`:
+Using `algolia` option allows you to leverage [algolia docsearch](https://github.com/algolia/docsearch) to displace the default built-in headers-based search, to enable this search, you have to provide at least `apiKey` and `indexName`:
```js
module.exports = {
diff --git a/docs/zh/config/README.md b/docs/zh/config/README.md
index 6d6f54099c..614ffb7979 100644
--- a/docs/zh/config/README.md
+++ b/docs/zh/config/README.md
@@ -102,7 +102,7 @@ module.exports = {
- 类型: `Object`
- 默认值: `undefined`
-使用 `algolia` 选项可以让你禁用掉默认的基于 headers 的搜索,从而使用 [algolia docsearch](https://github.com/algolia/docsearch)。为了使其生效,你必须提供至少 `apiKey` 和 `indexName` 这两个选项:
+使用 `algolia` 选项可以让你用 [algolia docsearch](https://github.com/algolia/docsearch) 取代默认的基于 headers 的搜索 。为了使其生效,你必须提供至少 `apiKey` 和 `indexName` 这两个选项:
```js
module.exports = {
@@ -113,7 +113,7 @@ module.exports = {
}
```
-其他可用的选项可以参考 [docsearch options](https://github.com/algolia/docsearch#docsearch-options)。
+其他可用的选项请参考 [docsearch options](https://github.com/algolia/docsearch#docsearch-options)。
### locales
diff --git a/lib/default-theme/Navbar.vue b/lib/default-theme/Navbar.vue
index e982d4806e..704b7552e7 100644
--- a/lib/default-theme/Navbar.vue
+++ b/lib/default-theme/Navbar.vue
@@ -13,7 +13,7 @@
@@ -21,7 +21,7 @@