-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.sh
executable file
·84 lines (66 loc) · 2.37 KB
/
compile.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
#!/bin/bash
# Check if Pandoc is installed
if ! command -v pandoc &> /dev/null; then
echo "Pandoc is not installed."
exit 1
fi
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "jq is not installed."
exit 1
fi
# Check if toc.json exists
if [ -f "input/toc.json" ]; then
echo "Reading input files from toc.json..."
# Create output directory if it doesn't exist
if [ ! -d "output" ]; then
echo "Creating output directory..."
mkdir -p "output"
fi
# Read each title and file list from toc.json
jq -c 'to_entries[]' input/toc.json | while IFS= read -r entry; do
# Extract title and file list
title=$(echo "$entry" | jq -r '.key')
files=$(echo "$entry" | jq -r '.value[]')
echo "Processing $title..."
input_files=""
# Debug: Print each file path
echo "Files to process:"
echo "$files"
# Read each file from the file list
for file in $files; do
echo "Checking file: $file"
if [ -f "input/$file" ]; then
echo "Adding $file to combined.md"
input_files+=$(cat "input/$file")
input_files+=$'\n\n' # Use $'\n\n' for newlines
else
echo "File $file not found in input directory!"
exit 1
fi
done
# Create a temporary markdown file for Pandoc
echo -e "$input_files" > "input/combined.md"
# Convert combined.md to .odt using the .odt reference template
if [ -f "input/combined.md" ] && [ -f "resources/template.odt" ]; then
echo "Converting combined.md to $title.odt using the .odt template..."
pandoc input/combined.md -o "output/$title.odt" --reference-doc=resources/template.odt
else
echo "combined.md or template.odt not found!"
exit 1
fi
# Cleanup temporary file
rm input/combined.md
echo "$title conversion to .odt complete!"
done
# Convert .odt to .pdf using LibreOffice
echo "Converting .odt files to .pdf..."
for odt_file in output/*.odt; do
pdf_file="output/$(basename "$odt_file" .odt).pdf"
soffice --headless --convert-to pdf "$odt_file" --outdir "$(dirname "$pdf_file")"
done
echo "Conversion to .pdf complete!"
else
echo "toc.json not found!"
exit 1
fi