Skip to content

Commit a807a2c

Browse files
committed
add script to install and run the project
1 parent 72c9ade commit a807a2c

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
Repository for [tupleblog](http://tupleblog.github.io) (in Thai) based on [Jekyll](http://jekyllrb.com/) [HPSTR](https://github.com/mmistakes/hpstr-jekyll-theme) theme.
44

5+
### `tpb` script
6+
7+
`tpb` script is now live! `tpb.sh` will help you install and serve the site easily. All you need to have is Ruby version >= `2.5.3`.
8+
9+
Here is how the script help looks like:
10+
11+
```sh
12+
$ ./tpb.sh
13+
Usage: ./tpb.sh [-i] [-d]
14+
15+
Options:
16+
-i, --install install dependencies with gem (gem install bundler) and bundler (bundle install).
17+
-d, --debug serve jekyll locally using bundler.
18+
```
19+
20+
If you have already installed Ruby, you can go ahead with the command `./tpb.sh -i`. This will install `bundler` if it is not installed yet and then run `bundle install` for you. Another command is `./tpb.sh -d` or debug. This command starts with commenting specified `url` in the `_config.yml` of the project then serving Jekyll with `JEKYLL_ENV=production` prefix. It also uncomment the line for you when you stop the server by hitting `ctrl`+`c`.
21+
22+
523
### Running the blog locally
624

725
First, go to `_config.yml` then change line 9 for running locally. Then, change
@@ -11,7 +29,7 @@ directory to the repository and then do the following
1129
2. Download `ruby` using [Homebrew](https://brew.sh/) for Mac. For Windows, download **RubyInstaller** and
1230
**DEVELOPMENT KIT** regarding your OS architecture from [here](https://rubyinstaller.org/downloads/).
1331
For **RubyInstaller**, just double click and done. For **DEVELOPMENT KIT**, please follows [its instruction](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit).
14-
3. Update your installed gems to latest version `gem update`. If updating failed try running `gem update --system` to update its core (see [this post](http://guides.rubygems.org/ssl-certificate-update/#installing-using-update-packages)).
32+
3. Update your installed gems to latest version `gem update`. If updating failed try running `gem update --system` to update its core (see [this post](http://guides.rubygems.org/ssl-certificate-update/#installing-using-update-packages)).
1533
4. `gem install bundler`
1634
5. `bundle install` (For Windows, run `cmd` as Administrator)
1735
6. `bundle exec jekyll serve` to serve the site in port 4000. You can also run

tpb.sh

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env bash
2+
3+
# ---------------------------
4+
# helper functions
5+
# ---------------------------
6+
## detect if it is on which system, because inplace sed on MacOS requires backup extension
7+
isMac() {
8+
if [[ "$OSTYPE" == "darwin"* ]]; then
9+
return 0
10+
fi
11+
12+
return 1
13+
}
14+
15+
## sed inplace for cross platform
16+
xsed() {
17+
# $1 : pattern
18+
# $2 : filename
19+
if isMac; then
20+
sed -Ei '' "$1" "$2"
21+
else
22+
sed -Ei "$1" "$2"
23+
fi
24+
}
25+
26+
## check if imageMagick is installed
27+
checkRequirement() {
28+
if ! type ruby > /dev/null; then
29+
echo "ruby not found, please install.. (rbenv recommended)"
30+
return 1
31+
fi
32+
if ! type gem > /dev/null; then
33+
echo "gem not found, please install.. (rbenv recommended)"
34+
return 1
35+
fi
36+
return 0
37+
}
38+
39+
## display help
40+
displayHelp(){
41+
echo "Usage: $0 [-i] [-d]"
42+
echo
43+
echo " Options:"
44+
echo " -i, --install install dependencies with gem (gem install bundler) and bundler (bundle install)."
45+
echo " -d, --debug serve jekyll locally using bundler."
46+
echo
47+
48+
exit 1
49+
}
50+
51+
# ---------------------------
52+
# functions
53+
# ---------------------------
54+
## install dependencies
55+
installDeps() {
56+
if ! type bundle > /dev/null; then
57+
echo -e ">> bundle not found, installing..\n"
58+
gem install bundler
59+
fi
60+
61+
echo -e ">> installing bundles..\n"
62+
bundle install
63+
}
64+
65+
## debug locally
66+
debugLocally() {
67+
local config_file
68+
config_file="./_config.yml"
69+
70+
# comment url line on start
71+
xsed 's/^(url:.*)/\# \1/' $config_file
72+
73+
# serve jekyll locally
74+
JEKYLL_ENV=production bundle exec jekyll serve
75+
76+
# uncomment url line on stop
77+
xsed 's/^#\s*(url: https\:\/\/tupleblog.*)/\1/' $config_file
78+
}
79+
80+
# ---------------------------
81+
# main
82+
# ---------------------------
83+
84+
main() {
85+
# check requirement first
86+
if ! checkRequirement; then exit 1; fi
87+
88+
case $1 in
89+
'-i' | '--install' )
90+
installDeps
91+
exit
92+
;;
93+
'-d' | '--debug' )
94+
debugLocally
95+
exit
96+
;;
97+
'-t' | '--test' )
98+
debugLocally
99+
# displayHelp
100+
;;
101+
* )
102+
displayHelp
103+
;;
104+
esac
105+
}
106+
107+
main $@

0 commit comments

Comments
 (0)