From b21d0424ad6bf3cec141abe7e1bb624744c12fc6 Mon Sep 17 00:00:00 2001 From: Louie S Date: Wed, 18 Oct 2023 18:08:59 -0400 Subject: Rewrite to base off template; index more terms --- src/index.sh | 95 ---------------------------------------------------- src/index_pages.sh | 42 +++++++++++++++++++++++ src/index_terms.sh | 39 +++++++++++++++++++++ src/lib/create_table | 7 ++++ src/lib/get_type | 13 +++++++ src/lib/insert | 8 +++++ 6 files changed, 109 insertions(+), 95 deletions(-) delete mode 100755 src/index.sh create mode 100755 src/index_pages.sh create mode 100755 src/index_terms.sh create mode 100644 src/lib/create_table create mode 100644 src/lib/get_type create mode 100644 src/lib/insert (limited to 'src') diff --git a/src/index.sh b/src/index.sh deleted file mode 100755 index a2a52d0..0000000 --- a/src/index.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env sh - -DB_PATH="$1" -shift - -get_title() { - FILE="$1" - - PATTERN="<[tT][iI][tT][lL][eE]>.*" - - #Find pattern in file - grep -Eo "$PATTERN" "$FILE" | - #Remove tag - sed 's/<[^>]*>//g' | \ - #Remove '(automake)' - sed 's/(Autoconf)//g' | \ - #Remove trailing space - sed 's/[ ]*$//g' | \ - #Remove trailing man categories - sed 's/ [0-9][mx]\?$//g' | \ - #Replace '&' with '&' - sed 's/&/&/g' | \ - # ReplACE '–' with '-' - sed 's/–/-/g' | \ - #Replace '<' with '<' - sed 's/</[^<]*" "$1" | while read -r line; do + insert_term "$line" + done + + shift + done +} + +insert_term() { + LINK="$1" + #NAME="$(echo "$LINK" | pup -p 'a text{}' | sed 's/\"\"//g' | tr -d \\n)" + NAME="$(echo "$LINK" | cut -d ' ' -f 1)" + PAGE_PATH="$(echo "$LINK" | pup -p 'a attr{href}')" + + TYPE=$(get_type "$PAGE_PATH") + if [ -z "$TYPE" ]; then + TYPE="Guide" + fi + + insert "$DB_PATH" "$NAME" "$TYPE" "man/$PAGE_PATH" +} + +create_table "$DB_PATH" +insert_index_terms "$@" diff --git a/src/lib/create_table b/src/lib/create_table new file mode 100644 index 0000000..a783c50 --- /dev/null +++ b/src/lib/create_table @@ -0,0 +1,7 @@ +create_table() { + DB_PATH="$1" + + sqlite3 "$DB_PATH" "CREATE TABLE IF NOT EXISTS searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);" + sqlite3 "$DB_PATH" "CREATE UNIQUE INDEX IF NOT EXISTS anchor ON searchIndex (name, type, path);" +} + diff --git a/src/lib/get_type b/src/lib/get_type new file mode 100644 index 0000000..9f04b53 --- /dev/null +++ b/src/lib/get_type @@ -0,0 +1,13 @@ +get_type() { + FILE="$1" + CATEGORY="$(echo "$FILE" | grep -Eo "\.[0-9].?\.html$")" + + if [ -n "$CATEGORY" ]; then + case "$CATEGORY" in + .1*) echo "Command" ;; + .2*) echo "Service" ;; + .3*) echo "Function" ;; + *) echo "Object" ;; + esac + fi +} diff --git a/src/lib/insert b/src/lib/insert new file mode 100644 index 0000000..31c1b4c --- /dev/null +++ b/src/lib/insert @@ -0,0 +1,8 @@ +insert() { + DB_PATH="$1" + NAME="$2" + TYPE="$3" + PAGE_PATH="$4" + + sqlite3 "$DB_PATH" "INSERT INTO searchIndex(name, type, path) VALUES (\"$NAME\",\"$TYPE\",\"$PAGE_PATH\");" +} -- cgit