-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.sh
executable file
·226 lines (178 loc) · 6.43 KB
/
doc.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
main() {
# Check if the number of arguments is exactly one
if [ $# -eq 1 ]; then
# Check if the argument is one of the specified values
case "$1" in
"install" | "preview" | "make-my-day")
$1 # Call the function by its name. Function name identical to command
;;
* )
echo "ERROR Invalid or missing command."
usage
exit 1
;;
esac
else
usage
exit 1
fi
}
function usage(){
echo "Usage: $0 <command>"
echo "Known commands are are:"
echo " install"
echo " make-my-day"
echo " preview"
}
function install() {
python -m pip install -r requirements.txt
rm -rf .venv
mkdir .venv
python -m pipenv install --no-site-packages --dev
curl -L -o .venv/plantuml.jar https://github.com/plantuml/plantuml/releases/download/v1.2024.0/plantuml-1.2024.0.jar
}
function preview() {
# Clean
rm -rf build/html
mkdir build/html
# Start continuous build, open browser automatically which reloads on change.
python -m pipenv run sphinx-autobuild doc build/html --port 1440 --open-browser
}
function build() {
# Clean
rm -rf build/html
mkdir build/html
# Build
python -m pipenv run sphinx doc build/html
}
function make-my-day() {
dir_doc_root_path='./doc/dairy'
file_name='index'
file_extension='rst'
year=$(date +"%Y")
week=$(date +"CW%V")
day=$(date +"%u-%a" | tr 'a-z' 'A-Z')
dir_entry_relpath=.
file_entry_relpath_wo_extension=$file_name
file_entry_relpath=${file_entry_relpath_wo_extension}.$file_extension
dir_year_relpath=$year
file_year_relpath_wo_extension=$dir_year_relpath/$file_name
file_year_relpath=${file_year_relpath_wo_extension}.$file_extension
dir_week_relpath=$(date +"$year/$week")
file_week_relpath_wo_extension=$dir_week_relpath/$file_name
file_week_relpath=${file_week_relpath_wo_extension}.$file_extension
dir_day_relpath="$dir_week_relpath/$day"
file_day_relpath_wo_extension=$dir_day_relpath/$file_name
file_day_relpath=${file_day_relpath_wo_extension}.$file_extension
date_with_week=$(echo $dir_day_relpath | tr '/' '/')
date_with_month=$(date +"%Y-%b-%d")
weekday_name_full=$(date +"%A")
pushd $dir_doc_root_path > /dev/null
# Create day if not exist
create_day () {
if [ ! -f $file_day_relpath ]; then
heading="$weekday_name_full, $date_with_month"
#heading="$(echo $date_with_week | sed -n 's/\///; s/\//./p') : $heading"
underline=""
i=0
while [ $i -lt ${#heading} ]; do
underline="$underline#"
i=$((i+1))
done
mkdir -p $dir_day_relpath
echo $heading >> $file_day_relpath
echo $underline >> $file_day_relpath
(echo ; echo) >> $file_day_relpath
echo "info: Create file $dir_doc_root_path/$file_day_relpath ... done."
echo " $day/$file_name" >> $file_week_relpath
else
echo "info: File $dir_doc_root_path/$file_day_relpath already exists. Skip creation."
fi
mkdir -p $dir_day_relpath/_figures
mkdir -p $dir_day_relpath/_attachments
}
create_day
# Create week if not exist, otherwise update
rewrite_week () {
heading=$(echo $dir_week_relpath | sed 's/\///g')
underline=""
i=0
while [ $i -lt ${#heading} ]; do
underline="$underline#"
i=$((i+1))
done
mkdir -p $dir_week_relpath
echo $heading > $file_week_relpath
echo $underline >> $file_week_relpath
(echo) >> $file_week_relpath
echo ".. toctree::" >> $file_week_relpath
echo " :maxdepth: 1" >> $file_week_relpath
(echo) >> $file_week_relpath
day_entries=$(cd $dir_week_relpath ; ls -w1 -d * | sed -n '/[1-7]-.../p')
for day_entry in $day_entries ; do
echo " $day_entry/index" >> $file_week_relpath
done
echo "info: Rewrite file $dir_doc_root_path/$file_week_relpath "
}
rewrite_week
rewrite_year () {
heading="$year"
underline=""
i=0
while [ $i -lt ${#heading} ]; do
underline="$underline#"
i=$((i+1))
done
mkdir -p $dir_year_relpath
echo $heading > $file_year_relpath
echo $underline >> $file_year_relpath
(echo) >> $file_year_relpath
echo ".. toctree::" >> $file_year_relpath
echo " :maxdepth: 1" >> $file_year_relpath
(echo) >> $file_year_relpath
week_entries=$(cd $dir_year_relpath ; ls -w1 -d * | sed -n '/CW[0-9][0-9]/p')
for week_entry in $week_entries ; do
echo " $week_entry/index" >> $file_year_relpath
done
echo "info: Rewrite file $dir_doc_root_path/$file_year_relpath "
}
rewrite_year
rewrite_entry () {
heading="Daily Notes"
underline=""
i=0
while [ $i -lt ${#heading} ]; do
underline="$underline#"
i=$((i+1))
done
mkdir -p $dir_entry_relpath
echo $heading > $file_entry_relpath
echo $underline >> $file_entry_relpath
(echo) >> $file_entry_relpath
echo ".. toctree::" >> $file_entry_relpath
echo " :maxdepth: 1" >> $file_entry_relpath
(echo) >> $file_entry_relpath
week_entries=$(cd $dir_entry_relpath ; ls -w1 -d * | sed -n '/[0-9][0-9][0-9][0-9]/p')
for week_entry in $week_entries ; do
echo " $week_entry/index" >> $file_entry_relpath
done
echo "info: Rewrite file $file_entry_relpath "
}
rewrite_entry
popd >/dev/null # relates to pushd $dir_doc_root_path
# At codespace skip subsequent actions. Use the username as indicator for that.
if [ "$USER" = "codespace" ]; then
exit
fi
# On iPad skip subsequent actions. Use the username as indicator for that.
if [ "$USER" = "mobile" ]; then
exit
fi
# Open VS code
file_to_open_in_ide="$dir_doc_root_path/$file_day_relpath"
echo "info: Open vscode and go to file $file_to_open_in_ide"
# echo "TODO: Adapt manually .vscode/settings.json to make esbonio use this week as source folder: $dir_week_relpath"
code . --goto $file_to_open_in_ide:$(echo $(cat $file_to_open_in_ide | wc -l))
}
main "$@"