-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_all_docx.sh
45 lines (38 loc) · 985 Bytes
/
process_all_docx.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
#!/bin/sh
set -o errexit
if [ -z "$1" ]
then
OUTPUT_DIR="/github/workspace/test-cases"
else
OUTPUT_DIR="$1"
fi
mkdir -p ${OUTPUT_DIR}
python3 convert.py -r -e ./word-input ${OUTPUT_DIR}
find "${OUTPUT_DIR}"/* -type d -exec sh -c '
DIRPATH=$0
DIRNAME=$(basename "$DIRPATH")
if [ ! -f "${DIRPATH}/index.md" ]
then
if [ ! -f "${DIRPATH}/_index.md" ]
then
echo Creating title link for directory: $DIRPATH with title: $DIRNAME
cat > "${DIRPATH}/_index.md" <<EOF
---
title: "$DIRNAME"
linkTitle: "$DIRNAME"
weight: 5
---
EOF
fi
fi
' {} ${OUTPUT_DIR} ';'
RUN_EMF2PNG=$(cat << EOM
FILE=\$0
OUTDIR=\$(dirname "\${FILE}")
FILE_PNG="\${FILE%.*}.png"
libreoffice --nologo --norestore --invisible --headless --convert-to png "\$FILE" --outdir "\$OUTDIR"
convert -trim "\${FILE_PNG}" "\${FILE_PNG}"
EOM
)
# process all *.emf files from word-input and create index.md
find ${OUTPUT_DIR}/* -type f -name '*.emf' -exec sh -c "$RUN_EMF2PNG" {} ';'