Hexo博客文章管理脚本

之前学 Shell 写了一个简单的脚本,最方便的是用来备份整个 blog_dir 到 Gitee 仓库。

留个笔记!

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
echo "----------------------------------"
echo "----------------------------------"

select input in "新建文章" "更新博客" "备份博客" "退出脚本"
do
case $input in
新建文章)
cd /Users/ashin/blog
echo
read -p "请输入文章名称:" post_name
hexo new post ${post_name}
echo "##############"
echo "-文章创建成功-"
echo "##############"

cd /Users/ashin/blog/source/_posts
echo "已打开文章,开始编辑吧"
open ${post_name}.md
echo
echo
echo "----------------------------------"
echo "1) 新建文章"
echo "2) 更新博客"
echo "3) 备份博客"
echo "4) 退出脚本"
echo "----------------------------------"
;;

更新博客)
echo "#############"
echo "-开始更新博客-"
echo "#############"
cd /Users/ashin/blog
hexo clean;hexo g;hexo d
echo "##############"
echo "-博客更新完成-"
echo "##############"
echo
echo
echo "----------------------------------"
echo "1) 新建文章"
echo "2) 更新博客"
echo "3) 备份博客"
echo "4) 退出脚本"
echo "----------------------------------"
;;

备份博客)
echo "#############"
echo "-开始备份博客-"
echo "#############"

cd /Users/ashin/blog
time_backup=$(date "+%Y-%m-%d %H:%M:%S")
git add .
git commit -m "$time_backup"
git push
echo
echo
echo "##############"
echo "---备份完成!---"
echo "##############"
echo
echo
echo "----------------------------------"
echo "1) 新建文章"
echo "2) 更新博客"
echo "3) 备份博客"
echo "4) 退出脚本"
echo "----------------------------------"
;;

退出脚本)
exit
;;

*)
echo
echo "选择错误,请重新选择!"
echo "----------------------------------"
echo "1) 新建文章"
echo "2) 更新博客"
echo "3) 备份博客"
echo "4) 退出脚本"
echo "----------------------------------"
;;
esac
done