From 8a81dbf6605ec1b809f6d469a09d788d76cecea1 Mon Sep 17 00:00:00 2001 From: Westly Wright Date: Mon, 2 Jul 2018 12:28:19 -0700 Subject: [PATCH] bug fixes for releasing --- gulpfile.babel.js | 21 ++++++++++++++++++-- build-algolia.js => scripts/build-algolia.js | 18 +++++++---------- 2 files changed, 26 insertions(+), 13 deletions(-) rename build-algolia.js => scripts/build-algolia.js (88%) diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 8f02e905e92..bd13759d2f1 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -31,13 +31,13 @@ gulp.task('dev', ['build-dev'], () => { }); gulp.task('build', (cb) => { - runSequence('pub-delete', 'sass', 'build:vendor', 'build:app', 'fonts', 'img', 'hugo', () => { + runSequence('pub-delete', 'sass', 'build:vendor', 'build:app', 'fonts', 'img', 'hugo', 'build:search-index', () => { cb(); }); }); gulp.task('build-staging', (cb) => { - runSequence('pub-delete', 'sass', 'build:vendor', 'build:app', 'fonts', 'img', 'hugo-staging', () => { + runSequence('pub-delete', 'sass', 'build:vendor', 'build:app', 'fonts', 'img', 'hugo-staging', 'build:search-index', () => { cb(); }); }); @@ -165,3 +165,20 @@ gulp.task('cms-delete', () => { gulp.task('pub-delete', () => { return del(['public/**', '!public']); }); + + +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 + }; + return spawn(process.cwd()+'/scripts/build-algolia.js', opts).on('close', (/* code */) => { + cb(); + }); +}); diff --git a/build-algolia.js b/scripts/build-algolia.js similarity index 88% rename from build-algolia.js rename to scripts/build-algolia.js index 049154583e4..8ab30004204 100755 --- a/build-algolia.js +++ b/scripts/build-algolia.js @@ -9,23 +9,19 @@ const atomicalgolia = require("atomic-algolia"); const fs = require('fs'); const indexName = "dev_docs" const nue = []; -const { spawnSync } = require('child_process'); - -spawnSync('gulp', ['build'], { stdio: 'inherit' }); - -const rawdata = fs.readFileSync('public/algolia.json'); -const nodes = JSON.parse(rawdata); +const rawdata = fs.readFileSync('public/algolia.json'); +const nodes = JSON.parse(rawdata); nodes.forEach(node => { const dom = new JSDOM(node.content); const content = dom.window.document.body; //post content wrapped in a body tag const contentChildren = content.children; // all the children of the body tag const paragraphOut = { - anchor: '#', - title: '', - content: '', - postref: node.objectID, - objectID: md5(node.permalink), + anchor: '#', + title: '', + content: '', + postref: node.objectID, + objectID: md5(node.permalink), permalink: node.permalink };