Hello Hexo

Hello Hexo

JiangWen Lv4

Welcome to Hexo ! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub .

快速开始

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

进阶优化

新增文章时自动打开Markdown编辑器

需求:由于每次在使用 hexo n "文章名称" 时还要去打开编辑器,这太麻烦了!我们可以通过一个监听的js代码去监听hexo新建文章的命令,并自动打开相应的 Markdown编辑器来实现联动,这样岂不是即方便且优雅!

  1. 首先在 hexo/scripts 下新建一个 editArticle.js 文件,如果没有 scripts 文件可以手动创建一个。

  2. editArticle.js 文件并写入如下内容即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const { spawn } = require("child_process");
const os = require("os");

// 新建文档时,启动typora打开文章
hexo.on("new", (data) => {
const filename = data.path;
const typoraPath = getTyporaPath();

if (typoraPath) {
spawn(typoraPath, [filename]);
}
});

// 根据当前的操作系统,设置启动应用的路径(编辑器可执行文件的位置,要根据自己实际情况更改)
function getTyporaPath() {
const platform = os.type();
if (platform === "Darwin") {
// MacOS
return "/Applications/Typora.app/Contents/MacOS/Typora";
} else if (platform === "Windows_NT") {
// Windows
return "D:\\Typora\\Typora.exe";
} else {
console.error("Unsupported platform:", platform);
return null;
}
}

  • 标题: Hello Hexo
  • 作者: JiangWen
  • 创建于: 2022-09-28 11:45:00
  • 更新于: 2023-06-18 15:54:09
  • 链接: https://blog.jiangwen.site/2022/09/28/Hexo/Hello Hexo/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
 评论