Эх сурвалжийг харах

Fix change file name not change image path
Fix change image name not change image dirctory
Optimize the rename scheme
Update Screenshots to v1.3.26

zhuzhuyule 7 жил өмнө
parent
commit
1758969506

+ 16 - 4
README.md

@@ -36,9 +36,21 @@ Inherit [Moeditor](https://github.com/Moeditor/Moeditor), I want to fix it appro
   * Quick New Post in hexo source 
   * Quick Modify File Name (In Hexo Post Edit)  
   * Shortcut Support
-  * Editor Line number Show/Hide
+  * Editor Line Number Show/Hide
   * Auto Show/Hide Scroll
   * Scorll Together/None
+  * --------- v1.2.12 (2018-01-14) ---------
+  * Add Quick Hexo Command `hexo d`,`hexo g`,`hexo s`,`hexo clean` :triangular_flag_on_post:
+  * Quick Deploy Post
+  * --------- v1.3.21 (2018-01-30) ---------
+  * Quick Change Image to Markdown :triangular_flag_on_post:
+    * Support Drag Image
+    * Support Paste Clipboard Image
+  * Add Image Cloud (Those are Free Cloud) :triangular_flag_on_post:
+    * Support [SM.MS](https://sm.ms) 
+    * Support [QiNiu](https://portal.qiniu.com) 
+    * Support [Tencent](https://console.cloud.tencent.com) 
+  * Add Quick Start (Common Directory, Common URL)
 * HexoEditor (Inherit [Moeditor](https://github.com/Moeditor/Moeditor))
   * GitHub Flavored Markdown
   * TeX math expressions
@@ -50,7 +62,7 @@ Inherit [Moeditor](https://github.com/Moeditor/Moeditor), I want to fix it appro
   * Code highlight themes (powered by [highlight.js](https://highlightjs.org/))
   * Auto reload
   * Localization
-  * ~~Focus mode~~
+  * Focus mode
 
 # Screenshots
 
@@ -73,11 +85,11 @@ Inherit [Moeditor](https://github.com/Moeditor/Moeditor), I want to fix it appro
 
 # Plan To Do
 - [ ] Add Toc
-- [ ] Add Hexo Title Header setting (40%)
+- [x] Add Hexo Title Header setting (100%)
 - [ ] Add base highlight ShortCut
 - [ ] Add history files tree
 .....
-- [ ] Deploy Post
+- [x] Deploy Post
 - [ ] Add multi-editing in tabs
 
 # Building

+ 46 - 44
app/moe-action.js

@@ -48,54 +48,56 @@ class MoeditorAction {
         let notOpened = false;
         try {
             let hexoDir = moeApp.config.get('hexo-root-dir');
-            let templateFile = path.resolve(hexoDir, 'scaffolds', 'post.md');
-            let content = '' +
-                '---\n' +
-                'title: {{ title }}\n' +
-                'date: {{ date }}\n' +
-                'categories: \n' +
-                'tags: \n' +
-                '---';
+            if( hexoDir && fs.existsSync(hexoDir)){
+                let templateFile = path.resolve(hexoDir, 'scaffolds', 'post.md');
+                let content = '' +
+                    '---\n' +
+                    'title: {{ title }}\n' +
+                    'date: {{ date }}\n' +
+                    'categories: \n' +
+                    'tags: \n' +
+                    '---';
 
-            let fileDir = path.resolve(hexoDir, 'source', '_posts');
-            if (fs.statSync(fileDir).isDirectory()) {
-                let nowDate, fileName, count = 0;
-                do {
-                    nowDate = moment().format('YYYY-MM-DD HH:mm:ss');
-                    if (count > 0)
-                        nowDate = nowDate + count;
-                    count += 1;
-                    fileName = path.resolve(fileDir, nowDate.replace(/[-: ]/g, '') + '.md');
-                    if (count > 50) {
-                        break;
+                let fileDir = path.resolve(hexoDir, 'source', '_posts');
+                if (fs.statSync(fileDir).isDirectory()) {
+                    let nowDate, fileName, count = 0;
+                    do {
+                        nowDate = moment().format('YYYY-MM-DD HH:mm:ss');
+                        if (count > 0)
+                            nowDate = nowDate + count;
+                        count += 1;
+                        fileName = path.resolve(fileDir, nowDate.replace(/[-: ]/g, '') + '.md');
+                        if (count > 50) {
+                            break;
+                        }
+                    } while (fs.existsSync(fileName));
+                    if (fs.existsSync(templateFile)) {
+                        content = fs.readFileSync(templateFile).toString()
+                            .replace(/title:\s+\{\{[^\}]+\}\}/, 'title: ' + nowDate.replace(/[-: ]/g, ''))
+                            .replace(/date:\s+/, 'date: ' + nowDate)
+                            .replace(/\{\{[^\}]+\}\}/g, '');
                     }
-                } while (fs.existsSync(fileName));
-                if (fs.existsSync(templateFile)) {
-                    content = fs.readFileSync(templateFile).toString()
-                        .replace(/title:\s+\{\{[^\}]+\}\}/, 'title: ' + nowDate.replace(/[-: ]/g, ''))
-                        .replace(/date:\s+/, 'date: ' + nowDate)
-                        .replace(/\{\{[^\}]+\}\}/g, '');
-                }
 
-                lastDir = fileDir;
-                MoeditorFile.write(fileName, content);
-                if (fs.existsSync(fileName)) {
-                    let hexoWindow = require('electron').BrowserWindow.getFocusedWindow();
-                    if (typeof hexoWindow.hexoeditorWindow == 'undefined' || hexoWindow.hexoeditorWindow.changed || hexoWindow.hexoeditorWindow.content) {
-                        app.addRecentDocument(fileName);
-                        moeApp.open(fileName,fileName);
-                    } else {
-                        hexoWindow.hexoeditorWindow.defName = fileName;
-                        hexoWindow.hexoeditorWindow.fileName = fileName;
-                        hexoWindow.hexoeditorWindow.directory = lastDir;
-                        hexoWindow.hexoeditorWindow.fileContent = hexoWindow.hexoeditorWindow.content = MoeditorFile.read(fileName).toString();
-                        hexoWindow.hexoeditorWindow.changed = false;
-                        hexoWindow.hexoeditorWindow.window.setDocumentEdited(false);
-                        hexoWindow.hexoeditorWindow.window.setRepresentedFilename(hexoWindow.hexoeditorWindow.fileName);
-                        hexoWindow.hexoeditorWindow.window.webContents.send('refresh-editor', {});
-                        app.addRecentDocument(fileName);
+                    lastDir = fileDir;
+                    MoeditorFile.write(fileName, content);
+                    if (fs.existsSync(fileName)) {
+                        let hexoWindow = require('electron').BrowserWindow.getFocusedWindow();
+                        if (typeof hexoWindow.hexoeditorWindow == 'undefined' || hexoWindow.hexoeditorWindow.changed || hexoWindow.hexoeditorWindow.content) {
+                            app.addRecentDocument(fileName);
+                            moeApp.open(fileName,fileName);
+                        } else {
+                            hexoWindow.hexoeditorWindow.defName = fileName;
+                            hexoWindow.hexoeditorWindow.fileName = fileName;
+                            hexoWindow.hexoeditorWindow.directory = lastDir;
+                            hexoWindow.hexoeditorWindow.fileContent = hexoWindow.hexoeditorWindow.content = MoeditorFile.read(fileName).toString();
+                            hexoWindow.hexoeditorWindow.changed = false;
+                            hexoWindow.hexoeditorWindow.window.setDocumentEdited(false);
+                            hexoWindow.hexoeditorWindow.window.setRepresentedFilename(hexoWindow.hexoeditorWindow.fileName);
+                            hexoWindow.hexoeditorWindow.window.webContents.send('refresh-editor', {});
+                            app.addRecentDocument(fileName);
+                        }
+                        notOpened = false;
                     }
-                    notOpened = false;
                 }
             }
         } catch (e) {

+ 12 - 0
doc/cn/README.md

@@ -39,6 +39,18 @@
   * 编辑框行号显示/隐藏
   * 智能显示滚动条
   * 滚动条启用/取消同步滚动
+  * --------- v1.2.12 (2018-01-14) ---------
+  * 添加快速执行Hexo命令 `hexo d`,`hexo g`,`hexo s`,`hexo clean` :triangular_flag_on_post:
+  * 快速部署
+  * --------- v1.3.21 (2018-01-30) ---------
+  * 图片转换为Markdown格式 :triangular_flag_on_post:
+    * 支持拖拽图片
+    * 支持剪贴板粘贴
+  * 添加图床支持 :triangular_flag_on_post:
+    * 支持 [SM.MS](https://sm.ms) 
+    * 支持 [QiNiu](https://portal.qiniu.com) 
+    * 支持 [Tencent](https://console.cloud.tencent.com) 
+  * 添加快速启动(常用目录,常用地址)
 * HexoEditor (继承 [Moeditor](https://github.com/Moeditor/Moeditor) 原有功能)
   * GitHub 风格 Markdown 显示
   * TeX math 表达式

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "HexoEditor",
-  "version": "1.3.24",
+  "version": "1.3.26",
   "description": "This is markdown editor for Hexo.",
   "main": "app/index.js",
   "scripts": {

BIN
screenshots/about.png


BIN
screenshots/gif-mode.gif


BIN
screenshots/gif-settings.gif


BIN
screenshots/gif-uploadImage.gif


BIN
screenshots/main.png


BIN
screenshots/menu.png


BIN
screenshots/settings.png


BIN
screenshots/side-menu.png


BIN
screenshots/write-mode.png


+ 7 - 0
views/about/moe-about.css

@@ -17,6 +17,13 @@
 *  along with Moeditor. If not, see <http://www.gnu.org/licenses/>.
 */
 
+html {
+    width: calc(100% - 2px);
+    height: calc(100% - 2px);
+    overflow: hidden;
+    border: 1px solid #d2d2d2;
+}
+
 body {
     background-color: #fbfbfb;
     margin: 0;

+ 18 - 10
views/main/hexo-image.js

@@ -201,17 +201,22 @@ class ImgManager {
     }
 
     renameImage(imgName, newImgName) {
-        this.updateDictionary(imgName + '$', newImgName)
+        this.updateDictionary(imgName + '\\b', newImgName)
     }
 
     renameDirPath(fileName) {
         this.updateDictionary('/' + this.postName + '/', '/' + fileName + '/')
+        this.imgPathDir = path.resolve(this.imgPathDir,'..', fileName);
         this.postName = fileName;
     }
 
     updateDictionary(oldStr, newStr) {
         if (Object.keys(this.imgPathToMarkURL).length > 0) {
             this.imgPathToMarkURL = JSON.parse(JSON.stringify(this.imgPathToMarkURL).replace(new RegExp(oldStr, 'g'), newStr));
+            if (Object.keys(this.imgPathToUrlPath).length > 0)
+                this.imgPathToUrlPath = JSON.parse(JSON.stringify(this.imgPathToUrlPath).replace(new RegExp(oldStr, 'g'), newStr));
+            if (Object.keys(this.imgPathToDelHash).length > 0)
+                this.imgPathToDelHash = JSON.parse(JSON.stringify(this.imgPathToDelHash).replace(new RegExp(oldStr, 'g'), newStr));
             if (Object.keys(this.imgMD5ToPath).length > 0)
                 this.imgMD5ToPath = JSON.parse(JSON.stringify(this.imgMD5ToPath).replace(new RegExp(oldStr, 'g'), newStr));
         }
@@ -336,15 +341,18 @@ class ImgManager {
             log.info(`Begin update Src[${maxIndex}]`);
             successList.forEach((response, index) => {
                 uploadList.push(response);
-                content = content.replace(new RegExp(imgManager.imgPathToMarkURL[response.id], 'g'), response.data.url);
-                imgManager.imgPathToUrlPath[response.id] = response.data.path;
-                imgManager.imgPathToMarkURL[response.id] = response.data.url;
-                imgManager.imgPathToDelHash[response.id] = (response.data.hash || '');
-                if (maxIndex == index) {
-                    editor.setValue(content);
-                    hexoWindow.content = content;
-                    hexoWindow.changed = true;
-                    log.info(`End update Src[${maxIndex}]`);
+                let relPath = imgManager.imgPathToMarkURL[response.id];
+                if (relPath){
+                    content = content.replace(new RegExp(relPath, 'g'), response.data.url);
+                    imgManager.imgPathToUrlPath[response.id] = response.data.path;
+                    imgManager.imgPathToMarkURL[response.id] = response.data.url;
+                    imgManager.imgPathToDelHash[response.id] = (response.data.hash || '');
+                    if (maxIndex == index) {
+                        editor.setValue(content);
+                        hexoWindow.content = content;
+                        hexoWindow.changed = true;
+                        log.info(`End update Src[${maxIndex}]`);
+                    }
                 }
             });
         }

+ 2 - 1
views/main/hexo/hexo.js

@@ -22,7 +22,6 @@ function Hexo() {
     this.enable = !!moeApp.config.get('hexo-config-enable');
     this.render = new Render(this);
     this.loadConfig();
-    moeApp.config.set('hexo-root-dir',this.config.__basedir);
 }
 
 Hexo.prototype.init = function() {
@@ -84,6 +83,8 @@ Hexo.prototype.changeConfig = function (enable) {
     if (typeof file === 'object')
         file = file.toString();
     this.config.__basedir = path.dirname(file|| '');
+    moeApp.config.set('hexo-root-dir',this.config.__basedir);
+
     // var sep = path.sep;
     // this.base_dir = base + sep;
     // this.public_dir = pathFn.join(base, 'public') + sep;

+ 16 - 9
views/main/moe-document.js

@@ -245,33 +245,40 @@ $(() => {
             if (nameNew !== nameOld){
                 let dir = path.dirname(hexoWindow.fileName);
                 let ext = path.extname(hexoWindow.fileName);
-                let count = -1,fileNameNew;
+                let count = -1,fileNameNew,imgPathNew,tmpName;
                 do {
                     count++;
-                    fileNameNew = nameOld + (count > 0 ? count : '');
-                    fileNameNew = path.resolve(dir, nameNew + ext);
+                    tmpName = nameNew + (count > 0 ? count : '');
+                    if (tmpName == nameOld)
+                        return;
+                    fileNameNew = path.resolve(dir, tmpName + ext);
+                    imgPathNew = path.join(imgManager.imgBaseDir,tmpName);
                     if (count > 50) {
                         return;
                     }
-                } while (fs.existsSync(fileNameNew))
-
+                } while (fs.existsSync(fileNameNew)||fs.existsSync(imgPathNew))
+                nameNew = tmpName;
                 fs.renameSync(hexoWindow.fileName, fileNameNew);
                 hexoWindow.fileName = fileNameNew;
-                hexoWindow.changed = ture;
+                hexoWindow.changed = true;
                 hexoWindow.window.setRepresentedFilename(fileNameNew);
                 document.getElementsByTagName('title')[0].innerText = 'HexoEditor - ' + nameNew + ext;
 
                 //修改文章中的Image链接
                 let imgPathOld = path.join(imgManager.imgBaseDir,nameOld).replace(/\\/g,'/');
                 if (fs.existsSync(imgPathOld)) {
-                    let imgPathNew = path.join(imgManager.imgBaseDir,nameNew).replace(/\\/g,'/');
+                    let content = editor.getValue();
+                    console.log(1,content)
+                    imgPathNew = imgPathNew.replace(/\\/g,'/');
                     fs.rename(imgPathOld, imgPathNew, err => {
                         if (err) log.error(err);
-                        fs.stat(imgFilePathNew, (err, stats) => {
+                        fs.stat(imgPathNew, (err, stats) => {
                             if (err) console.error(err);
                             let relativePathOld = imgManager.relativePath(imgPathOld);
                             let relativePathNew = imgManager.relativePath(imgPathNew);
-                            editor.setValue(editor.getValue().replace(new RegExp('\\]\\(/' + relativePathOld, 'g'), '](/' + relativePathNew))
+                            content = content.replace(new RegExp('\\]\\(' + relativePathOld + '\/', 'g'), '](' + relativePathNew + '/');
+                            console.log(2,content)
+                            editor.setValue(content)
                             imgManager.renameDirPath(nameNew);
                         })
                     })

+ 11 - 11
views/main/moe-style.css

@@ -34,13 +34,14 @@
     transition: margin-left .5s !important;
 }
 
-html, body {
-    margin: 0;
-    padding: 0;
-    width: 100%;
-    height: 100%;
-    overflow: hidden;
-    -webkit-user-select: none;
+html {
+    margin: 0 !important;
+    padding: 0 !important;
+    width: calc(100% - 2px) !important;
+    height: calc(100% - 2px) !important;
+    overflow: hidden !important;
+    -webkit-user-select: none !important;
+    border: 1px solid #d2d2d2 !important;
 }
 
 body{
@@ -49,15 +50,14 @@ body{
     margin: 0 !important;
     -webkit-user-select: none !important;
     cursor: default !important;
-    width: calc(100% - 2px) !important;
-    height: calc(100% - 2px) !important;
-    border: 1px solid #d2d2d2 !important;
+    width: 100% !important;
+    height: 100% !important;
 }
 
 #side-menu {
     width: 300px;
     margin-left: -301px;
-    height: 100%;
+    height: calc(100% - 67px);
     background: #fafafa;
     transition: all 200ms ease-in-out;
     padding-top: 20px;

+ 7 - 6
views/settings/moe-settings.css

@@ -17,10 +17,11 @@
  *  along with Moeditor. If not, see <http://www.gnu.org/licenses/>.
  */
 
-html, body {
-    width: 100%;
-    height: 100%;
+html {
+    width: calc(100% - 2px);
+    height: calc(100% - 2px);
     overflow: hidden;
+    border: 1px solid #d2d2d2;
 }
 
 body {
@@ -28,9 +29,9 @@ body {
     margin: 0;
     -webkit-user-select: none;
     cursor: default;
-    width: calc(100% - 2px);
-    height: calc(100% - 2px);
-    border: 1px solid #d2d2d2;
+    width: 100%;
+    height: 100%;
+    overflow: hidden;
 }
 
 #main {