-
Notifications
You must be signed in to change notification settings - Fork 5
/
cmd_haspot.sh
executable file
·72 lines (65 loc) · 1.65 KB
/
cmd_haspot.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
VERSION=v1.0.50
PROGNAME=$(basename $0)
sub_new() {
title=$1
post_name=$(echo ${title// /-} | tr '[:upper:]' '[:lower:]')
post_file_name=$(date +%Y-%m-%d)-$post_name
article_datetime=$(date '+%Y-%m-%d %H:%M')
cat <<EOF > posts/$post_file_name.md
---
layout: post
title: "$title"
date: $article_datetime
comments: true
categories:
---
EOF
}
sub_help() {
echo "Usage: $PROGNAME <subcommand> [options]\n"
echo " new -- generate new blog post"
echo " deploy -- push it to github"
echo " docker -- build a docker image and upload"
echo ""
echo "For help with each subcommand run:"
echo "$PROGNAME <subcommand> -h|--help"
echo ""
}
sub_deploy() {
brew install coreutils
TARGET_DIR=$(grealpath ../mno2.github.io)
TIMESTAMP=$(date +%s)
NEW_FILENAME=customize-$TIMESTAMP.css
stack run rebuild
cp -r _site/** $TARGET_DIR
cd $TARGET_DIR
find . -name "*.html" -exec sed -i '' s/customize.css/$NEW_FILENAME/g {} +
mv about/stylesheets/customize.css about/stylesheets/$NEW_FILENAME
mv stylesheets/customize.css stylesheets/$NEW_FILENAME
git add .
git commit -m "New post"
git push origin master
}
sub_docker() {
if ! [ -x "$(command -v docker)" ]; then
echo 'Error: docker is not installed.' >&2
exit 1
fi
docker build -t paulmeng/blog:$VERSION .
docker push paulmeng/blog:$VERSION
}
subcommand=$1
case $subcommand in
"" | "-h" | "--help")
sub_help
;;
*)
shift
sub_${subcommand} "$@"
if [ $? = 127 ]; then
echo "Error: '$subcommand' is not a known subcommand." >&2
echo " Run '$PROGNAME --help' for a list of known subcommands." >&2
exit 1
fi
;;
esac