|
|
|
@ -2,11 +2,12 @@
|
|
|
|
|
|
|
|
|
|
var inquirer = require('inquirer');
|
|
|
|
|
var chalk = require('chalk');
|
|
|
|
|
var getContents = require('../lib/fileio').getContents;
|
|
|
|
|
|
|
|
|
|
exports.narrowDown = narrowDown;
|
|
|
|
|
exports.selectArticle = selectArticle;
|
|
|
|
|
|
|
|
|
|
function narrowDown(articles, terms, deep) {
|
|
|
|
|
function narrowDown(articles, terms, deep, apropos) {
|
|
|
|
|
var reSearchTerms = terms.map(function mapRE(term) {
|
|
|
|
|
return new RegExp(term, 'i');
|
|
|
|
|
});
|
|
|
|
@ -15,8 +16,21 @@ function narrowDown(articles, terms, deep) {
|
|
|
|
|
return !article.category;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (deep) {
|
|
|
|
|
return filtered.filter(function filterOnTitle(article) {
|
|
|
|
|
if (apropos) {
|
|
|
|
|
filtered = filtered.map(function getArticleContents(art) {
|
|
|
|
|
return getContents(art).then(function makeArts(article) {
|
|
|
|
|
return article;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return Promise.all(filtered).then(function filterIt(items) {
|
|
|
|
|
return items.filter(function filterOnTitleContents(article) {
|
|
|
|
|
return reSearchTerms.every(function checkRE(reTerm) {
|
|
|
|
|
return reTerm.test(article.title) || reTerm.test(article.contents);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else if (deep) {
|
|
|
|
|
return filtered.filter(function filterOnTitleDesc(article) {
|
|
|
|
|
return reSearchTerms.every(function checkRE(reTerm) {
|
|
|
|
|
return reTerm.test(article.title) || reTerm.test(article.description);
|
|
|
|
|
});
|
|
|
|
@ -55,7 +69,6 @@ function selectArticle(articles) {
|
|
|
|
|
name: 'selection',
|
|
|
|
|
message: 'Select the Arch Wiki article',
|
|
|
|
|
choices: choices,
|
|
|
|
|
pageSize: 15,
|
|
|
|
|
}], function getAnswer(response) {
|
|
|
|
|
var pos = choices.indexOf(response.selection);
|
|
|
|
|
return resolve(sorted[pos]);
|
|
|
|
|