From 6ea0ce27c871bb85564b59464c1aa7fd66638075 Mon Sep 17 00:00:00 2001 From: TevinLi <6317595@qq.com> Date: Tue, 21 Mar 2017 16:58:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E5=AF=BC=E5=87=BA=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/manageFolder.js | 1 + build/manageWiki.js | 8 ++++---- lib/main.js | 31 +++++++++++++++++++------------ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/build/manageFolder.js b/build/manageFolder.js index c5c3cc0..b6e5f60 100644 --- a/build/manageFolder.js +++ b/build/manageFolder.js @@ -102,6 +102,7 @@ module.exports = { if (!path && typeof path !== 'string') { return false; } + path = path.replace(/\\/g, '/'); path = path.indexOf('library') < 0 ? path : path.split('library')[0]; path = path.indexOf('config.json') < 0 ? path : path.split('config.json')[0]; path = path.indexOf('index.html') < 0 ? path : path.split('index.html')[0]; diff --git a/build/manageWiki.js b/build/manageWiki.js index d5a1be2..cdf7c00 100644 --- a/build/manageWiki.js +++ b/build/manageWiki.js @@ -52,10 +52,10 @@ module.exports = { if (path.indexOf('library') > 0) { this.addWiki(path.split('library')[0]); } else { - const wId = this.createWikiId(path); - //不包含library路径时,需要判断是否为amWiki项目 - if (typeof this._wikis[wId] === 'undefined' && mngFolder.isAmWiki(path)) { - this.addWiki(path, wId); + //验证转换 path 为 wiki 根目录 + const root = mngFolder.isAmWiki(path); + if (root) { + this.addWiki(root); } } }, diff --git a/lib/main.js b/lib/main.js index b367cb1..25d23b5 100644 --- a/lib/main.js +++ b/lib/main.js @@ -92,12 +92,16 @@ module.exports = { //命令:手动更新当前文库导航 'amWiki:makeNav': () => { const [isOnEdit, editor, editPath] = this._getEditorPath(); - if (isOnEdit || (typeof editPath !== 'undefined' && mngFolder.isAmWiki(editPath))) { - makeNav.refresh(editPath); - mngWiki.checkAddWiki(editPath); - } else { - alert('只有当你打开一个 amWiki 文库时,才能手动更新导航文件!'); + if (typeof editPath !== 'undefined') { + //当 isOnEdit 为 false 时,editPath 仍然不一定为根目录 + const root = mngFolder.isAmWiki(editPath); + if (root) { + makeNav.refresh(root + 'library/'); + mngWiki.checkAddWiki(root); + return; + } } + alert('只有当你打开一个 amWiki 文库时,才能手动更新导航文件!'); }, //命令:粘帖截图 'amWiki:paste': () => { @@ -126,12 +130,15 @@ module.exports = { //命令:导出项目为 github wiki 'amWiki:export.gitHub': () => { const [isOnEdit, editor, editPath] = this._getEditorPath(); - if (isOnEdit || (typeof editPath !== 'undefined' && mngFolder.isAmWiki(editPath))) { - exportGithub.export(editPath); - mngWiki.checkAddWiki(editPath); - } else { - alert('导出失败!\n只能对一个 amWiki 项目进行导出!'); + if (typeof editPath !== 'undefined') { + const root = mngFolder.isAmWiki(editPath); + if (root) { + exportGithub.export(root); + mngWiki.checkAddWiki(root); + return; + } } + alert('导出失败!\n只能对一个 amWiki 项目进行导出!'); }, //命令:显示about 'amWiki:about': () => { @@ -181,8 +188,8 @@ module.exports = { if (!grammar) { return [false, editor]; } - const ePath = editor.getPath(); - if (editor.getPath().substr(-3) !== '.md') { + const ePath = editor.getPath().replace(/\\/g, '/'); + if (ePath.substr(-3) !== '.md') { return [false, editor, ePath]; } if (ePath.indexOf('library') < 0) {