-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_example.sh
More file actions
executable file
·47 lines (37 loc) · 1.05 KB
/
Copy pathindex_example.sh
File metadata and controls
executable file
·47 lines (37 loc) · 1.05 KB
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
#!/bin/bash
DEBUG="${DEBUG:-0}"
MIN_SIZE="${MIN_SIZE:-100k}"
if [ "$DEBUG" = "1" ]; then
set -uxo pipefail
else
set -uo pipefail
fi
SOURCE_ROOT="/media/rfranr/8a2e60fb-c9e9-4d23-b8f3-a45a2b01a8a3/share1"
TARGET_ROOT="assets/docs"
find "$SOURCE_ROOT" -type f -iname "*.pdf" -size +"$MIN_SIZE" | while read -r pdf; do
relative="${pdf#$SOURCE_ROOT/}"
relative_no_ext="${relative%.pdf}"
out="$TARGET_ROOT/${relative_no_ext}.txt"
mkdir -p "$(dirname "$out")"
echo "Converting: $pdf"
echo "Output: $out"
if ! pdftotext "$pdf" "$out"; then
echo "ERROR converting: $pdf" >&2
continue
fi
echo
echo "========================================"
echo "INDEXING DOCUMENT"
echo "========================================"
echo "FILE: $out"
echo "SOURCE PDF: $pdf"
echo "MIN SIZE: $MIN_SIZE"
echo "========================================"
echo
if ! pnpm run start index "$out" \
--metadata "{\"fileName\":\"$out\",\"sourcePdf\":\"$pdf\"}"; then
echo "ERROR indexing: $out" >&2
echo "SOURCE PDF: $pdf" >&2
continue
fi
done