forked from CDCgov/PyRenew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pre-commit-rst-placeholder.sh
executable file
·56 lines (44 loc) · 1.63 KB
/
.pre-commit-rst-placeholder.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
#!/usr/bin/env sh
TUTORIALS_DIR=docs/source/tutorials
# For each *qmd file in model/docs, create a corresponding rst file
# under docs/source/tutorial
COUNTER=0
# Removing everything under docs/source/tutorials/*rst with the exception of the index.rst file.
# This is to ensure that the index.rst file is not deleted.
RST_FILES=$(find $TUTORIALS_DIR -type f -name '*.rst' -not -name 'index.rst')
# Counting which of the rst files are not in model/docs
for rst in $RST_FILES; do
# Capture the basename
bname=$(basename $rst .rst)
# Check if the corresponding qmd file exists
if [ ! -f model/docs/${bname}.qmd ]; then
echo "Removing $rst"
rm $rst
COUNTER=$((COUNTER+1))
fi
done
for qmd in model/docs/*.qmd; do
# Capture the basename
bname=$(basename $qmd .qmd)
# Check if the corresponding rst file already exists
if [ -f ${TUTORIALS_DIR}/${bname}.rst ]; then
echo "RST file already exists: ${TUTORIALS_DIR}${bname}.rst"
continue
fi
# Increment counter
COUNTER=$((COUNTER+1))
# Create the rst file
rst=${TUTORIALS_DIR}/${bname}.rst
echo "Creating $rst"
# Print a message pointing to github.com/CDCgov/ on the rst file
echo ".. WARNING" > $rst
echo ".. Please do not edit this file directly." >> $rst
echo ".. This file is just a placeholder." >> $rst
echo ".. For the source file, see:" >> $rst
echo ".. <https://github.com/CDCgov/multisignal-epi-inference/tree/main/model/docs/${bname}.qmd>" >> $rst
done
# Exit with 1 if COUNTER != 0
if [ $COUNTER -ne 0 ]; then
echo "Tutorials' RST placeholders were generated."
exit 1
fi