forked from RetroAchievements/docs-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-docs.sh
More file actions
executable file
·123 lines (93 loc) · 2.98 KB
/
generate-docs.sh
File metadata and controls
executable file
·123 lines (93 loc) · 2.98 KB
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
#!/bin/bash
# generate-docs.sh
##################
# TODO: add an --install option to install mkdocs, material theme, etc...
# globals #####################################################################
readonly SCRIPT_DIR="$(cd "$(dirname $0)" && pwd)"
SERVE_FLAG=0
DEPLOY_FLAG=0
# functions ###################################################################
function exit_error() {
echo "ERROR: $@" >&2
exit 1
}
function get_pages_section() {
local sidebar="$SCRIPT_DIR/docs.wiki/_Sidebar.md"
[[ -f "$sidebar" ]] || return 1
echo "pages:"
echo " - index.md"
while IFS='' read -r line || [[ -n "$line" ]]; do
case "$line" in
"## User docs")
echo " - User docs:" ;;
"## Developer docs")
echo " - Developer docs:" ;;
"- "*)
echo " $(sed 's/\[.*\](\(.*\))/\1/' <<< "$line").md" ;;
"## [About](About)")
echo " - About: About.md" ;;
esac
done < "$sidebar"
}
function parse_args() {
while [[ -n "$1" ]]; do
case "$1" in
#H -h|--help Print this help message and exit.
#H
-h|--help)
echo "$(basename "$0") [OPTIONS]"
echo
echo "Where OPTIONS are:"
echo
# getting the help message from the comments in this source code
sed -n 's/^#H //p' "$0"
exit
;;
#H -s|--serve Serve the docs locally after generating the pages.
#H
-s|--serve)
SERVE_FLAG=1
;;
#H -d|--deploy Deploy the docs to GitHub pages after generating the pages.
#H
-d|--deploy)
DEPLOY_FLAG=1
;;
*) break
;;
esac
shift
done
}
function main() {
parse_args "$@"
cd "$SCRIPT_DIR"
echo "--- Getting wiki pages..."
git submodule update --recursive --remote || exit_error "Failed to get wiki pages."
echo "--- Done!"
echo
cp -R img docs.wiki/
cp -R css docs.wiki/
cd docs.wiki
ln -sf Home.md index.md
cd -
echo "--- Generating the custom mkdocs.yml..."
cp mkdocs.yml temp-mkdocs.yml || exit_error "Failed to copy \"mkdocs.yml\"."
get_pages_section >> temp-mkdocs.yml || exit_error "Failed to generate \"pages:\" section."
echo "--- Done!"
echo
if [[ "$SERVE_FLAG" == "1" ]]; then
echo "--- Generating and serving the pages locally..."
echo "--- (hit CTRL+C to terminate)"
mkdocs serve -f temp-mkdocs.yml || exit_error "Failed to generate/serve pages locally."
echo "--- Done!"
echo
fi
if [[ "$DEPLOY_FLAG" == "1" ]]; then
echo "--- Generating and deploying the pages to GitHub..."
mkdocs gh-deploy -f temp-mkdocs.yml || exit_error "Failed to generate/deploy pages to GitHub."
echo "--- Done!"
echo
fi
}
main "$@"