-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.sh
More file actions
executable file
·85 lines (71 loc) · 2.29 KB
/
command.sh
File metadata and controls
executable file
·85 lines (71 loc) · 2.29 KB
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
#!/bin/bash
# Generate & deploy site
commit_message=""
check_commit_msg(){
if [ "$*" = "-post" ]; then
commit_message="update posts"
elif [ "$*" = "-package" ]; then
commit_message="update packages"
elif [ "$*" = "-theme" ]; then
commit_message="update theme"
else
commit_message="$*"
fi
}
if [ $# -eq 2 ] && ([ $1 = "deploy" ] || [ $1 = "d" ]); then
check_commit_msg $2
echo "$ hexo clean"
hexo clean
echo "$ hexo generate"
if ! hexo generate; then
echo "Error! hexo generate failed"
exit 2
fi
if [ ! -d "docs" ]; then
echo "Error! No docs/ folder generated"
exit 3
fi
echo "$ git add"
git add -A
echo "$ git commit"
git commit -m "$commit_message"
echo "$ git push"
git push
echo "$ wrangler pages deploy"
npx wrangler pages deploy docs --project-name blog
exit 0
fi
# Compress images
if [ $# -eq 1 ] && ([ $1 = "compress" ] || [ $1 = "c" ]); then
cd source/_posts
pngquant --ext .png --force 256 */*.png
echo "PNG images under source/_posts/*/ have been compressed."
exit 0
fi
# Create a new article
if [ $# -eq 2 ] && ([ $1 = "new" ] || [ $1 = "n" ]); then
hexo new "$2"
exit 0
fi
# Start a local server
if [ $# -eq 1 ] && ([ $1 = "server" ] || [ $1 = "s" ]); then
hexo server
exit 0
fi
# Help
b=$(tput bold) # bold
e=$(tput sgr0) # end
if [ $# -eq 1 ] && ([ $1 = "help" ] || [ $1 = "h" ]); then
echo "command.sh [compress|c] Compress PNG images under ${b}source/_posts/*/${e} using pngquant"
echo "command.sh [deploy|d] <commit_message> Generate & deploy site"
echo "command.sh [deploy|d] -post Alias for ${b}command.sh deploy \"update posts\"${e}"
echo "command.sh [deploy|d] -package Alias for ${b}command.sh deploy \"update packages\"${e}"
echo "command.sh [deploy|d] -theme Alias for ${b}command.sh deploy \"update theme\"${e}"
echo "command.sh [help|h] Display help information"
echo "command.sh [new|n] Create a new article"
echo "command.sh [server|s] Start a local server"
exit 0
fi
# Error
echo "Error! Usage: command.sh [compress|deploy <commit_message>|help|server]"
exit 1