This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
generate-docs.sh
executable file
·108 lines (81 loc) · 3.37 KB
/
generate-docs.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
105
106
107
108
#!/bin/bash
# generate-docs.sh
##################
# globals #####################################################################
readonly SCRIPT_DIR="$(cd "$(dirname $0)" && pwd)"
function exit_error() {
echo -e "ERROR: $@" >&2
exit 1
}
generate_nav_section() {
local tmp
local mdfile
local sidebar="$SCRIPT_DIR/docs.wiki/_Sidebar.md"
[[ -f "$sidebar" ]] || return 1
cd "$(dirname "$sidebar")"
echo "nav:"
while IFS='' read -r line || [[ -n "$line" ]]; do
case "$line" in
"## [About](About)")
echo " - About:"
echo " - About.md"
;;
"## "*)
echo " - ${line/### /}:"
[[ "$line" == *"General"* ]] && echo " - index.md"
;;
"### "*)
echo " - ${line/#### /}:"
;;
*"- "*)
if [[ "$line" == *"- ["* ]]; then
# example of input/output of the sed below:
# in : - [Tips and Tricks](Tips-and-Tricks)
# out: - Tips and Tricks: Tips-and-Tricks.md
tmp="$(sed 's/\[\(.*\)\](\(.*\))/\1: \2/' <<< "$line").md"
echo " $tmp"
mdfile="$(echo "${tmp// /}" | cut -d: -f2)"
echo -e "\n\n\n## Changelog\n\nLast 10 changes on this page:\n" >> "$mdfile"
git log -n 10 --date=format:"%Y-%m-%d %H:%M" --pretty=format:"- \`[%cd] %cn:\` %s" "$mdfile" >> "$mdfile"
else
echo " $line:"
fi
;;
esac
done < "$sidebar"
cd - > /dev/null
}
function main() {
cd "$SCRIPT_DIR"
echo "--- Getting wiki pages..."
git clone https://github.com/RetroAchievements/docs.wiki.git
cd docs.wiki || exit_error "There's something wrong with 'docs.wiki' directory."
ln -sf Home.md index.md
echo -e "\n\n\n## Changelog\n\nLast 10 changes on this page:\n" >> Home.md
git log -n 10 --date=format:"%Y-%m-%d %H:%M" --pretty=format:"- \`[%cd] %cn:\` %s" Home.md >> Home.md
echo "--- Done!"
echo
echo "--- Configure CNAME..."
echo 'docs.retroachievements.org' > CNAME
echo "--- Done!"
echo
cd - >/dev/null
cp -R img docs.wiki/
echo "--- Generating the custom mkdocs.yml..."
cp template.mkdocs.yml mkdocs.yml || exit_error "Failed to copy \"mkdocs.yml\"."
generate_nav_section >> mkdocs.yml || exit_error "Failed to generate \"nav:\" section."
echo "--- Done!"
echo
# TODO: create a custom Docker image with a Dockerfile like this:
# FROM squidfunk/mkdocs-material
# RUN pip install git+https://github.com/cmitu/mkdocs-altlink-plugin
#docker container run --rm -v ${PWD}:/docs squidfunk/mkdocs-material gh-deploy
# These git commands are here to prevent the need of
# `mkdocs gh-deploy --force`, which would overwrite the commit history.
# see: https://github.com/mkdocs/mkdocs/issues/973
git checkout -b gh-pages
git pull --rebase origin gh-pages
git checkout master
mkdocs gh-deploy
}
main "$@"