-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauto_post.sh
executable file
·117 lines (99 loc) · 2.42 KB
/
auto_post.sh
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
BLOG_DIR=/home/donge/WorkSpace/uniondong.github.io
COMMON_POST_TEMPLATE="common_post"
DRAINAGE_POST_TEMPLATE="drainage"
function weight_adjust()
{
CONTENT_DIR=$1
CONTENT_NAME=$2
if [ -z "${CONTENT_DIR}" ]; then
echo "please input content dir"
fi
if [ -z "${CONTENT_NAME}" ]; then
echo "please input content name"
fi
if [ -f ${CONTENT_DIR}/${CONTENT_NAME}.md ]; then
weight=$(grep -rn "weight" "${CONTENT_DIR}" | wc -l)
echo "weight adjust: $((weight - 1))"
sed -i "s/weight: 1/weight: $((weight - 1))/g" ${CONTENT_DIR}/${CONTENT_NAME}.md
fi
}
function post_common_article()
{
CONTENT_DIR=$1
CONTENT_NAME=$2
if [ -z "${CONTENT_DIR}" ]; then
echo "please input content dir"
fi
if [ -z "${CONTENT_NAME}" ]; then
echo "please input content name"
fi
if [ ! -d ${CONTENT_DIR} ]; then
mkdir -p ${CONTENT_DIR}
fi
echo "hugo new -k $COMMON_POST_TEMPLATE ${CONTENT_DIR}/${CONTENT_NAME}.md"
hugo new -k $COMMON_POST_TEMPLATE ${CONTENT_DIR}/${CONTENT_NAME}.md
weight_adjust "$CONTENT_DIR" "$CONTENT_NAME"
}
function post_drainage_article()
{
CONTENT_DIR=$1
CONTENT_NAME=$2
if [ -z "${CONTENT_DIR}" ]; then
echo "please input content dir"
fi
if [ -z "${CONTENT_NAME}" ]; then
echo "please input content name"
fi
if [ ! -d ${CONTENT_DIR} ]; then
mkdir -p ${CONTENT_DIR}
fi
echo "hugo new -k $DRAINAGE_POST_TEMPLATE ${CONTENT_DIR}/${CONTENT_NAME}.md"
hugo new -k $DRAINAGE_POST_TEMPLATE ${CONTENT_DIR}/${CONTENT_NAME}.md
weight_adjust "$CONTENT_DIR" "$CONTENT_NAME"
}
function build_hugo_and_push()
{
echo -e "\033[0;32mDeploying updates to GitHub...\033[0m"
# Build the project.
hugo # build hugo
cd content
git add .
cd ../
# Go To Public folder
cd public
# Add changes to git.
git add .
cd ../
git add .
# Commit changes.
msg="rebuilding site `date`"
if [ $# -eq 1 ]
then msg="$1"
fi
git commit -m "$msg"
# Push source and build repos.
git push origin main
# Come Back up to the Project Root
cd $BLOG_DIR
}
# main
cd $BLOG_DIR
case "$1" in
common)
post_common_article "$2" "$3"
;;
drainage)
post_drainage_article "$2" "$3"
;;
deploy)
build_hugo_and_push
;;
*)
echo "Usage: $0 {common|drainage|deploy}"
echo " $0 common dir blog_name "
echo " $0 drainage dir blog_name "
echo " $0 deploy "
exit 1
esac
exit $?