summaryrefslogtreecommitdiff
path: root/src/index.sh
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2024-06-21 15:49:26 -0400
committerLouie S <louie@example.com>2024-06-21 15:49:26 -0400
commit8f1b9c79e97b3dbed49284345ea3202137317b14 (patch)
treed21cf100bc622fe04d6e4033a5a2c17ed2a8933d /src/index.sh
parent73e835df08d1d212fe1e612c175526999696add4 (diff)
Remove redundant code from index scriptHEADmaster
Diffstat (limited to 'src/index.sh')
-rwxr-xr-xsrc/index.sh48
1 files changed, 23 insertions, 25 deletions
diff --git a/src/index.sh b/src/index.sh
index 6b79700..d3226ec 100755
--- a/src/index.sh
+++ b/src/index.sh
@@ -1,5 +1,10 @@
#!/usr/bin/env sh
+# shellcheck source=../../../scripts/create_table.sh
+. "$(dirname "$0")"/../../../scripts/create_table.sh
+# shellcheck source=../../../scripts/insert.sh
+. "$(dirname "$0")"/../../../scripts/insert.sh
+
DB_PATH="$1"
shift
@@ -18,30 +23,23 @@ get_title() {
sed 's/&amp/&/g'
}
-insert() {
- NAME="$1"
- TYPE="$2"
- PAGE_PATH="$3"
-
- sqlite3 "$DB_PATH" "INSERT INTO searchIndex(name, type, path) VALUES (\"$NAME\",\"$TYPE\",\"$PAGE_PATH\");"
+insert_pages() {
+ # Get titles and insert into table for each html file
+ while [ -n "$1" ]; do
+ unset PAGE_NAME
+ PAGE_NAME="$(get_title "$1")"
+ echo "$PAGE_NAME" | while read -r line; do
+ if [ -n "$line" ]; then
+ unset TITLE
+ TITLE="$(echo "$line" | sed 's/<[^>]*>//g' | sed -E 's/^Chapter |Appendix //' | sed 's/^[A-Z0-9]\.[^ ]* //')"
+ unset LINK
+ LINK="$(basename "$1")#$(echo "$line" | sed 's/^.\{7\}//' | sed 's/\"\/>.*//')"
+ insert "$DB_PATH" "$TITLE" "Guide" "$LINK"
+ fi
+ done
+ shift
+ done
}
-# Create table
-sqlite3 "$DB_PATH" "CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);"
-sqlite3 "$DB_PATH" "CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);"
-
-# Get titles and insert into table for each html file
-while [ -n "$1" ]; do
- unset PAGE_NAME
- PAGE_NAME="$(get_title "$1")"
- echo "$PAGE_NAME" | while read -r line; do
- if [ -n "$line" ]; then
- unset TITLE
- TITLE="$(echo "$line" | sed 's/<[^>]*>//g' | sed -E 's/^Chapter |Appendix //' | sed 's/^[A-Z0-9]\.[^ ]* //')"
- unset LINK
- LINK="$(basename "$1")#$(echo "$line" | sed 's/^.\{7\}//' | sed 's/\"\/>.*//')"
- insert "$TITLE" "Guide" "$LINK"
- fi
- done
- shift
-done
+create_table "$DB_PATH"
+insert_pages "$@"