-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_post.sh
executable file
·104 lines (94 loc) · 2.62 KB
/
render_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
#!/bin/bash
function show_help {
echo "Usage: buildsite.sh [OPTION]..."
echo "Knit posts, rebuild jekyll blog <chepec>"
echo ""
echo "-c convert all _knitr/*.Rmd files to _posts/*.md (does not overwrite existing md)"
echo "-o overwrite existing *.md files"
echo "-f convert '_knitr/<filename>.Rmd' to markdown in _posts"
echo "-b build the jekyll site"
echo "-s send changes to live dir"
echo "-h show this help"
}
rmdfile=""
bashpwd=$(pwd)
# initialise flags here
# convert new *.Rmd => *.md?
convert=false
# convert even if *.md exists?
overwrite_md=false
# convert a specific Rmd file?
convert_file=false
# build jekyll site?
buildsite=false
# make changes live?
send_live=false
if [ $# -eq 0 ] ; then
# no args at all? show usage
show_help
exit 0
fi
# reset OPTINDEX in case getopts has been used previously in the shell
OPTIND=1
while getopts "h?cf:obs" opt; do
case $opt in
c)
# just a flag, no options
convert=true
;;
f)
# has a mandatory option, filename
convert_file=true
rmdfile=$OPTARG
;;
o)
# just a flag, no options
overwrite_md=true
;;
b)
# just a flag, no options
buildsite=true
;;
s)
# just a flag, no options
send_live=true
;;
h|\?)
show_help
exit 0
esac
done
shift $((OPTIND-1))
#### 1. convert/overwrite *.Rmd to *.md
# uses the function KnitPost() from the R-script render_post.R
if [ "$convert" = true ] ; then
echo ">>>> jc: Converting RMarkdown to Markdown (overwrite = $overwrite_md)"
if [ "$overwrite_md" = true ] ; then
Rscript -e "source('./render_post.R'); KnitPost(overwrite=TRUE)"
else
Rscript -e "source('./render_post.R'); KnitPost()"
fi
fi
#### 2. convert a specific Rmd-file
# uses the function KnitPost() from the R-script render_post.R
if [ "$convert_file" = true ] ; then
echo ">>>> jc: Converting file" $rmdfile
# check that $rmdfile exists
if [ -f $rmdfile ]; then
Rscript -e "source('./render_post.R'); KnitPost(bashwd='$bashpwd',convert_file='$rmdfile',date='$(date +'%Y-%m-%d')')"
else
show_help
exit 0
fi
fi
#### 3. build the site
if [ "$buildsite" = true ] ; then
echo ">>>> jc: Building site to /var/www/blog"
jekyll build -s ~/jekyll/chepec -d /var/www/blog
fi
#### 4. make changes live (send to public server)
if [ "$send_live" = true ] ; then
echo ">>>> jc: Sending changes to live server"
unison jekyll-damietta -auto
fi
exit 0