diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/index.sh | 48 |
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/&/&/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 "$@" |