windows 脚本自动上传 hugo 或 hexo 文章

数字玩具 2022年02月04日 21:32

灵感

在 Obsidian 编辑完后每次总要重新打开博客安装的根目录执行生成文件、添加文件、上传文件,😯而且每次进行操作的命令还都一样! 我受不了了!!!

忽然想到🧨,完全可以使用脚本嘛!在服务器上使用脚本可以,为什么不直接也用脚本进行操作嘞🧐?

产物

CMD 版

然后便有了下面这一坨:

 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
29
30
31
32
33
chcp 65001 #因为cmd乱码问题所以先切换字符

@echo off

echo "执行博客文章上传程序~"

echo "切换到博客目录"

E: #切换盘符才能去博客目录

cd E:\Remote\Hugo\blog

echo "博客生成文件..."

hugo -D

echo "博客文件上传"

cd public

git add --all

set now=%date% %time%

echo "Time:" %now%

git commit -m "%now%"

git push origin master

echo "上传完成!"

pause

Copy

好简单! 虽然是第一版,但是够用了完全🎉🎉🎉!只要稍作修改也能别人使用吧?

有问题再改咯~

发现问题

  1. 在执行脚本时有几率会未知卡(qia)住。解决:按按空格敲打敲打它

Powershell 版

 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
29
30
31
32
33
34
35
36
37
38
39
40
41
chcp 65001

$blogRootPath = 'E:\Remote\Hugo\blog'

$blogPublicPath= 'E:\Remote\Hugo\blog\public'

$disk = 'E:'

$time = Get-Date

Set-Location $disk

Write-Output "博客目录: $blogRootPath"

Set-Location $blogRootPath

Write-Output "hugo生成文件开始"

hugo -D

Write-Output "hugo生成文件结束"

Write-Output "git上传文件开始"

Write-Output "博客public目录: $blogPublicPath"

Set-Location $blogPublicPath

git add --all

git commit -m $time

git push origin master

Write-Output "git上传文件结束"

"执行完成,按任意键退出!" ;

Read-Host | Out-Null ;

Exit

Copy

PoswerShell 的执行好像麻烦一点欸😂。好像还有一点问题,但,又不是不能用!

废话

先暂时这样用着咯,等有问题的时候在改一点,有时间整出个 GUI 来🥰

标签

吕楪

博主.本博客的所有者,一切的开始。