-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
49 lines (38 loc) · 1.16 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
#!/bin/sh
# eg. sh ./build.sh
summary_file="SUMMARY.md"
if [ ! -f $summary_file ]; then
echo "Error: $summary_file is not exist"
exit 1;
fi
cat $summary_file | grep -v ^$ | while read line
do
title=`echo $line | awk 'BEGIN{FS="[";RS="]"} NF>1 {print $NF}'`
page=`echo $line | grep -Eo '\([^\)]*\)' | tail -1 | sed -e 's/(//g;s/)//g'`
array=(${page//// })
if [[ ${array[0]} == "" || ${array[1]} == "" ]]; then
continue
fi
# 目录名称
dir_name=${array[0]}
# 章节文件名称
file_name=${array[1]}
# 章节
chapter=`echo $file_name | sed "s/.md//g"`
# 目录名称校验
if [[ $dir_name =~ ^s[0-9]+ ]]; then
# 判断目录是否存在 不存在生成目录
if [ ! -d "$dir_name" ]; then
mkdir "$dir_name"
# 章节
chapter=`echo $dir_name | sed "s/s//g"`
# 生成README.md文件
echo "# $chapter $title\n***" > "$dir_name"/README.md
fi
if [ ! -f "$dir_name"/"$file_name" ]; then
# 生成章节文件
echo "# $chapter $title\n***" > "$dir_name"/"$file_name"
fi
fi
done
echo "OK."