-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvps_generate_static_sites
executable file
·141 lines (109 loc) · 4.22 KB
/
vps_generate_static_sites
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# function to check if required commands exist prior to bootstrap
require() {
if [[ ! $(command -v "$1") ]]; then
printf "requires '%s', Install that and re-run\n" "$1"
exit 1
fi
}
# $1: url, $2: location
reclone_dir() {
[[ -d "$2" ]] && rm -rf "$2"
git clone --depth=1 "$1" "$2"
rm -rf "$2/.git"
}
# removes any files currently in the REMOVE_FILES array
remove_files() {
for remove_file in "${REMOVE_FILES[@]}"; do
rm -vrf "$remove_file"
done
}
# $1: static site folder to move to document root
move_to_document_root() {
TARGET="${DOCUMENT_ROOT}/$(basename "$1")"
if [[ -d "$DOCUMENT_ROOT" ]]; then
rm -rf "$TARGET"
mv -v "$1" "$DOCUMENT_ROOT"
else
printf "Error moving files: '%s' does not exist.\n" "$DOCUMENT_ROOT"
fi
}
require git
require elm
require make
require python3
require python3.11
require realpath
require pipenv
require html-minifier # npm install -g html-minifier
require uglifycss
VPS_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")/..")"
BUILD_DIR="${VPS_DIR}/static_build"
DOCUMENT_ROOT="${HOME}/static_files"
[[ ! -d "$DOCUMENT_ROOT" ]] && mkdir -p "$DOCUMENT_ROOT"
# specifies URI path
DVD_DIR="${BUILD_DIR}/dvd"
XKCD_DIR="${BUILD_DIR}/xkcd"
ANIMESHORTS_DIR="${BUILD_DIR}/animeshorts"
BACK_ARROW_DIR="${BUILD_DIR}/back-arrow"
SUNS="${BUILD_DIR}/sun-in-the-corner-of-the-page"
# clone dirs
reclone_dir "https://github.com/seanbreckenridge/xqc-dvd" "$DVD_DIR"
reclone_dir "https://github.com/seanbreckenridge/xkcd-favorites" "$XKCD_DIR"
reclone_dir "https://github.com/seanbreckenridge/animeshorts" "$ANIMESHORTS_DIR"
reclone_dir "git@github.com:seanbreckenridge/back-arrow-script.git" "$BACK_ARROW_DIR"
reclone_dir "https://github.com/seanbreckenridge/sun-in-the-corner-of-the-page" "$SUNS"
## Build each Site
## BACK-ARROW #############
cd "${BACK_ARROW_DIR}" || exit $?
yarn install || exit $?
yarn check || exit $?
yarn build || exit $?
# move to public so it works with cross origin requests
mv -v "${BACK_ARROW_DIR}/back-arrow-bundle.js" "${HOME}/p/"
## SUNS ###################
python3.11 -m pip install yattag click pyyaml
cd "$SUNS" || exit $?
python3.11 generate.py 'sun-in-the-corner-of-the-page'
move_to_document_root "$SUNS/sun-in-the-corner-of-the-page"
## DVD ####################
cd "$DVD_DIR" || exit $?
make
REMOVE_FILES=(".gitignore" ".github" "elm-stuff" "elm.json" "LICENSE" "Makefile" "README.md" "src")
remove_files
move_to_document_root "$DVD_DIR"
## XKCD ###################
cd "$XKCD_DIR" || exit $?
python3 -m pip install --user -U -r requirements.txt
python3 generate.py
./ssg
mv ./static.html ./index.html
REMOVE_FILES=("favorites.yaml" "generate.py" "LICENSE" "README.md" "requirements.txt" ".nojekyll" ".gitignore" "ssg" "index.js" "data.json")
remove_files
move_to_document_root "$XKCD_DIR"
## ANIMESHORTS ############
cd "$ANIMESHORTS_DIR" || exit $?
python3 -m pip install -U pipenv virtualenv
python3 -m pipenv --rm
python3 -m pipenv --python ~/.pyenv/versions/3.10.2/bin/python
python3 -m pipenv install
"$ANIMESHORTS_DIR"/generate
python3 -m pipenv --rm
# minify HTML
html-minifier --collapse-whitespace --minify-css --minify-js --remove-attribute-quotes --remove-comments --remove-empty-attributes --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-style-link-type-attributes --remove-tag-whitespace --input-dir "${ANIMESHORTS_DIR}/output" --output-dir "${ANIMESHORTS_DIR}/animeshorts" --file-ext html
mv "${ANIMESHORTS_DIR}/output/images" "${ANIMESHORTS_DIR}/animeshorts"
mv "${ANIMESHORTS_DIR}/output/css" "${ANIMESHORTS_DIR}/animeshorts"
find "${ANIMESHORTS_DIR}" -name "*.css" -exec uglifycss {} --output {} \;
move_to_document_root "$ANIMESHORTS_DIR/animeshorts"
### FINISH
rm -rf "$BUILD_DIR"
set -x
## generate nicer errors
rm -rf /tmp/error_html
mkdir -p /tmp/error_html
darker_errors -output-dir /tmp/error_html 'ERROR_TITLE:sean - STATUS_MSG' '502:ERROR_HEAD:<meta http-equiv="refresh" content="5">' '502:ERROR_MSG:<p>This page is currently being updated...<br /> This should be fixed in in a few seconds...</p>'
cp /tmp/error_html/502.html "${DOCUMENT_ROOT}"
# requres me to to mark error_page for each request, see https://github.com/seanbreckenridge/darker_errors
cd "$DOCUMENT_ROOT" || exit $?
darker_errors 'ERROR_TITLE:sean - STATUS_MSG'
###