未分类

使用bat批处理脚本优化hexo的使用体验

使用bat批处理脚本优化hexo的使用体验


使用环境:windows 10

1.png
  • 干了什么?
    • 1.使用bat批处理简化了创建文章的过程
    • 2.使用bat批处理简化了在本地预览的过程
    • 3.使用bat处理简化了把blog发布到github pages
  • 怎么做?

    • 1.在优化之前创建blog需要打开cmd,然后输入hexo new "文章标题",然后还要去文件夹里手动打开md文档,这样就搞很智障

创建hexo文章.bat

1
2
3
4
5
6
7
8
9
10
11
@echo off(代码解释:用户输入文章名字,然后调用hexo new "文章名字"创建文章)
set /p name=请输入文章名字:
echo 输入的是: %name%
echo 请等待······
hexo new %name% && call 3.bat %name%(这里的call 3.bat是调用了同一文件夹下的3.bat)
pause

下面这个是3.bat

1
2
3
4
5
6
7
8
9
start /min /w mshta vbscript:setTimeout("window.close()",1000) (代码解释:延时一秒执行)
echo The InputValue is %1
set name=%1 (继承 创建hexo文章.bat 的变量)
echo %name%
start /d "C:\Program Files (x86)\MarkdownPad 2" MarkdownPad2.exe "D:\hexo\source\_posts\%name%.md" (用markdownpad2 打开刚刚创建好的文章,进行编辑)

  • 2.编辑好的文章放在本地hexo服务器预览的时候,要在cmd里输入hexo ghexo s,我把他们也搞成了批处理

    发布文章到本地服务器.bat

    1
    2
    3
    4
    5
    start 4.bat(运行4.bat)
    start /min /w mshta vbscript:setTimeout("window.close()",6000)(在运行5.bat之前等待,因为hexo g要花费一定的时间)
    start 5.bat(运行5.bat)

4.bat

1
hexo g

5.bat

1
hexo s

  • 3.发布文章到github pages

发布文章到github.bat

1
2
3
start 1.bat
start /min /w mshta vbscript:setTimeout("window.close()",1200)
start 2.bat

1.bat

1
2
3
4
5
6
7
8
9
@echo off
echo 清除本地hexo
echo 请等待······
hexo clean
exit

2.bat

1
2
3
4
5
6
7
@echo off
echo 发布中······
hexo d
pause

大概就这样吧,一个渣渣的折腾。

分享到