mirror of
https://github.com/greg-js/arch-wiki-man
synced 2024-11-17 09:26:12 +00:00
multi-language support
This commit is contained in:
parent
7dddf950a1
commit
8a80136246
12
bin/find.js
12
bin/find.js
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var _ = require('lodash');
|
||||||
var getContents = require('../lib/fileio').getContents;
|
var getContents = require('../lib/fileio').getContents;
|
||||||
var convert = require('../lib/fileio').convert;
|
var convert = require('../lib/fileio').convert;
|
||||||
var processMd = require('../lib/fileio').processMd;
|
var processMd = require('../lib/fileio').processMd;
|
||||||
@ -11,7 +12,7 @@ var tmpSave = require('../lib/fileio').tmpSave;
|
|||||||
var removeTmp = require('../lib/fileio').removeTmp;
|
var removeTmp = require('../lib/fileio').removeTmp;
|
||||||
|
|
||||||
var lastUpdate = require('arch-wiki-md-repo').updated;
|
var lastUpdate = require('arch-wiki-md-repo').updated;
|
||||||
var articles = require('arch-wiki-md-repo').doneList;
|
var articles = require('arch-wiki-md-repo').db;
|
||||||
|
|
||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
|
|
||||||
@ -29,6 +30,9 @@ var yargs = require('yargs')
|
|||||||
.boolean('w')
|
.boolean('w')
|
||||||
.alias('w', 'web')
|
.alias('w', 'web')
|
||||||
.describe('w', 'open in browser')
|
.describe('w', 'open in browser')
|
||||||
|
.default('l', 'english')
|
||||||
|
.alias('l', 'language')
|
||||||
|
.describe('l', 'choose a language (default: english)')
|
||||||
.help('h')
|
.help('h')
|
||||||
.alias('h', 'help')
|
.alias('h', 'help')
|
||||||
.argv;
|
.argv;
|
||||||
@ -37,6 +41,7 @@ var searchTerms = yargs._;
|
|||||||
var isDeep = yargs.d;
|
var isDeep = yargs.d;
|
||||||
var isApro = yargs.k;
|
var isApro = yargs.k;
|
||||||
var isWeb = yargs.w;
|
var isWeb = yargs.w;
|
||||||
|
var lang = yargs.l;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
name: '',
|
name: '',
|
||||||
@ -47,6 +52,8 @@ var options = {
|
|||||||
manual: '',
|
manual: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
articles = _.find(articles, { lang: lang }).articles;
|
||||||
|
|
||||||
Promise.resolve(narrowDown(articles, searchTerms, isDeep, isApro)).then(function select(filteredArticles) {
|
Promise.resolve(narrowDown(articles, searchTerms, isDeep, isApro)).then(function select(filteredArticles) {
|
||||||
return selectArticle(filteredArticles);
|
return selectArticle(filteredArticles);
|
||||||
}).then(function makeRoff(selectedArticle) {
|
}).then(function makeRoff(selectedArticle) {
|
||||||
@ -74,5 +81,6 @@ Promise.resolve(narrowDown(articles, searchTerms, isDeep, isApro)).then(function
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).catch(function catchAll(err) {
|
}).catch(function catchAll(err) {
|
||||||
console.log(err);
|
console.log(err.message);
|
||||||
|
console.log(err.stack);
|
||||||
});
|
});
|
||||||
|
@ -26,7 +26,7 @@ function convert(contents, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getContents(article) {
|
function getContents(article) {
|
||||||
article.path = getArticlePath(article.path);
|
article.path = getArticlePath(article.mdPath);
|
||||||
return fsReadFile(article.path, 'utf-8').then(function readArticle(contents) {
|
return fsReadFile(article.path, 'utf-8').then(function readArticle(contents) {
|
||||||
article.contents = contents;
|
article.contents = contents;
|
||||||
article.title = sanitize(article.title);
|
article.title = sanitize(article.title);
|
||||||
|
@ -13,9 +13,7 @@ function narrowDown(articles, terms, deep, apropos) {
|
|||||||
return new RegExp(term.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'), 'i');
|
return new RegExp(term.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'), 'i');
|
||||||
});
|
});
|
||||||
|
|
||||||
var filtered = articles.filter(function filterOutCategoryPages(article) {
|
var filtered = articles.slice();
|
||||||
return !article.category;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (apropos) {
|
if (apropos) {
|
||||||
filtered = filtered.map(function getArticleContents(art) {
|
filtered = filtered.map(function getArticleContents(art) {
|
||||||
|
@ -6,6 +6,9 @@ var archWiki = require.resolve('arch-wiki-md-repo');
|
|||||||
exports.getArticlePath = getArticlePath;
|
exports.getArticlePath = getArticlePath;
|
||||||
|
|
||||||
function getArticlePath(relativeArticlePath) {
|
function getArticlePath(relativeArticlePath) {
|
||||||
|
console.log(relativeArticlePath);
|
||||||
|
console.log(archWiki);
|
||||||
|
|
||||||
var absoluteArticlePath = path.resolve(archWiki, '..', 'wiki', relativeArticlePath);
|
var absoluteArticlePath = path.resolve(archWiki, '..', 'wiki', relativeArticlePath);
|
||||||
return absoluteArticlePath;
|
return absoluteArticlePath;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
"bluebird": "^3.1.5",
|
"bluebird": "^3.1.5",
|
||||||
"chalk": "^1.1.1",
|
"chalk": "^1.1.1",
|
||||||
"inquirer": "^0.11.4",
|
"inquirer": "^0.11.4",
|
||||||
|
"lodash": "^4.3.0",
|
||||||
"remark": "^3.2.2",
|
"remark": "^3.2.2",
|
||||||
"remark-man": "^2.0.1",
|
"remark-man": "^2.0.1",
|
||||||
"remark-unlink": "^2.0.0",
|
"remark-unlink": "^2.0.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user