-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·51 lines (41 loc) · 1.61 KB
/
build.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
#!/bin/bash
KO_DOCS_PATH="astro/src/content/docs/ko"
CONSTS_PATH="astro/src/consts.ts"
rm -rf $KO_DOCS_PATH
mkdir -p $KO_DOCS_PATH
# copy README.md to introduction.md
cp README.md $KO_DOCS_PATH/introduction.md
# remove current sidebar consts
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' '/export const SIDEBAR: Sidebar = {/,/^}/d' $CONSTS_PATH
else
sed -i '/export const SIDEBAR: Sidebar = {/,/^}/d' $CONSTS_PATH
fi
# copy chapters to ko/chapter
chapters=$(find . -maxdepth 1 -type d -name 'chapter*' | sort -V)
for chapter in $chapters; do
mkdir -p "$KO_DOCS_PATH/$chapter"
cp -r "$chapter" "$KO_DOCS_PATH"
done
# add sidebar consts
echo "export const SIDEBAR: Sidebar = {" | tee -a $CONSTS_PATH
echo " ko: {" | tee -a $CONSTS_PATH
for chapter in $chapters; do
header=$(basename "${chapter/chapter/Chapter }")
contents=$(find "$chapter" -maxdepth 1 -type f -name '*.mdx' | sort -V)
echo " '$header': [" | tee -a $CONSTS_PATH
for content in $contents; do
content=${content/.mdx/}
content_name=$(basename "${content/ko\//}")
# content name is {number}_{subnumber}_{title1}_{title2}_..._{titleN}.
# so replace {number}_{subnumber}_ with {number}.{subnumber}.
content_name=$(echo "$content_name" | sed -E 's/([0-9])_([0-9])_/\1.\2. /')
content_name=${content_name//_/ }
# remove "./" from content
content=${content/.\//}
echo " { text: '$content_name', link: '/ko/$content' }," | tee -a $CONSTS_PATH
done
echo " ]," | tee -a $CONSTS_PATH
done
echo " }" | tee -a $CONSTS_PATH
echo "}" | tee -a $CONSTS_PATH