From 1cbbbc1ce5b4c67655dbb9636c6b16c479b14a07 Mon Sep 17 00:00:00 2001 From: Westly Wright Date: Tue, 3 Jul 2018 14:37:27 -0700 Subject: [PATCH 1/3] Bug fixes for search --- scripts/build-algolia.js | 15 +++++++++------ src/js/app.js | 6 ++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/build-algolia.js b/scripts/build-algolia.js index c2104929f2f..c49fe704b80 100755 --- a/scripts/build-algolia.js +++ b/scripts/build-algolia.js @@ -22,7 +22,7 @@ nodes.forEach(node => { title: '', content: '', postref: node.objectID, - objectID: md5(node.permalink), + objectID: null, permalink: node.permalink }; @@ -60,14 +60,17 @@ nodes.forEach(node => { paragraphOut.content = content.textContent; } - // limit the content to 10k so we dont blow up just incase someone decides to make a 40k blog post in one paragraph ¯\_(ツ)_/¯ - paragraphOut.content = paragraphOut.content.substr(0, 8000); + if (paragraphOut.content) { + // limit the content to 10k so we dont blow up just incase someone decides to make a 40k blog post in one paragraph ¯\_(ツ)_/¯ + paragraphOut.content = paragraphOut.content.substr(0, 18000); - // objectID is not quite unique yet so hash the entire object - paragraphOut.objectID = md5(JSON.stringify(paragraphOut)); + // objectID is not quite unique yet so hash the entire object + paragraphOut.objectID = md5(JSON.stringify(paragraphOut)); - nue.push(paragraphOut); + nue.push(paragraphOut); + } + // remove potentially large content (see size limits) and replace with teh summary so that we don't get results with zero highlightable results node.content = node.summary; diff --git a/src/js/app.js b/src/js/app.js index 88c7c994ad4..3d84b04eec6 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -9,6 +9,12 @@ const bootstrapDocsSearch = function() { apiKey: 'b7f43c16886fec97b87981e9e62ef1a5', indexName: window.location.host === 'rancher.com' ? 'prod_docs' : 'dev_docs', routing: true, + searchFunction: function(helper) { + if (helper.state.query === "") { + return; + } + helper.search(); + } }); search.addWidget( From f13a6e44e0f59845d0b90e89f710db5b9f58f1bc Mon Sep 17 00:00:00 2001 From: Westly Wright Date: Tue, 3 Jul 2018 14:39:51 -0700 Subject: [PATCH 2/3] drone --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 0958e7597fe..f6b6507dc44 100644 --- a/.drone.yml +++ b/.drone.yml @@ -56,7 +56,7 @@ pipeline: tag: latest secrets: [docker_username, docker_password, algolia_app_id, algolia_admin_key] environment: - - ALGOLIA_INDEX_NAME="dev_docs" + - ALGOLIA_INDEX_NAME="prod_docs" - ALGOLIA_INDEX_FILE="public/algolia.json" build_args_from_env: - ALGOLIA_APP_ID From 07ce5749a6abb8f5554eecaf6046ecee6868cc19 Mon Sep 17 00:00:00 2001 From: Westly Wright Date: Tue, 3 Jul 2018 14:51:04 -0700 Subject: [PATCH 3/3] bug fixes search --- gulpfile.babel.js | 11 +---------- scripts/build-algolia.js | 4 +--- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/gulpfile.babel.js b/gulpfile.babel.js index bd13759d2f1..972ae17b647 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -168,16 +168,7 @@ gulp.task('pub-delete', () => { gulp.task('build:search-index', (cb) => { - const env = process.env; - - env.ALGOLIA_APP_ID = '30NEY6C9UY'; - env.ALGOLIA_INDEX_NAME = isProduction ? 'prod_docs' : 'dev_docs'; - env.ALGOLIA_INDEX_FILE = 'public/algolia.json'; - - const opts = { - stdio: 'inherit', - env: env - }; + const opts = {stdio: 'inherit'}; return spawn(process.cwd()+'/scripts/build-algolia.js', opts).on('close', (/* code */) => { cb(); }); diff --git a/scripts/build-algolia.js b/scripts/build-algolia.js index c49fe704b80..5508c61fa25 100755 --- a/scripts/build-algolia.js +++ b/scripts/build-algolia.js @@ -7,8 +7,6 @@ const { const md5 = require('md5'); const atomicalgolia = require("atomic-algolia"); const fs = require('fs'); -const isProduction = process.env.NODE_ENV === 'production'; -const indexName = isProduction ? "prod_docs" : "dev_docs"; const nue = []; const rawdata = fs.readFileSync('public/algolia.json'); const nodes = JSON.parse(rawdata); @@ -84,7 +82,7 @@ const merged = [...nodes, ...nue]; // fs.writeFileSync('public/combined.algolia.json', JSON.stringify(merged)); // process.exit(0); -atomicalgolia(indexName, merged, (err, result) => { +atomicalgolia(process.env.ALGOLIA_INDEX_NAME, merged, (err, result) => { if (err) throw err; console.log(result); process.exit(0);