aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-05-29 23:05:43 -0700
committerFuwn <[email protected]>2023-05-29 23:05:43 -0700
commit92ee80008474f0af84798dd231e4d25cd61f929b (patch)
tree810c959a8907e5e111cbbcde772867f0ae9abe80 /src/lib
downloadnectar-92ee80008474f0af84798dd231e4d25cd61f929b.tar.xz
nectar-92ee80008474f0af84798dd231e4d25cd61f929b.zip
feat: initial release
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/chapter_reader.sh13
-rw-r--r--src/lib/chapter_selection.sh38
2 files changed, 51 insertions, 0 deletions
diff --git a/src/lib/chapter_reader.sh b/src/lib/chapter_reader.sh
new file mode 100644
index 0000000..396a1db
--- /dev/null
+++ b/src/lib/chapter_reader.sh
@@ -0,0 +1,13 @@
+chapter_reader() {
+ # Chapter page HTML
+ chapter_content="$(gum spin --spinner line --show-output -- \
+ curl --silent --request GET "${1}")"
+
+ # Convert chapter HTML to GitHub Flavoured Markdown (closest to Honeyfeed)
+ markdown="$(echo "${chapter_content}" |
+ pup 'div.wrap-body.div' |
+ pandoc -f html -t gfm)"
+
+ # Display stylised chapter in default pager (usually less)
+ echo "${markdown}" | glow -w "$(tput cols)" -p -
+}
diff --git a/src/lib/chapter_selection.sh b/src/lib/chapter_selection.sh
new file mode 100644
index 0000000..c3534a5
--- /dev/null
+++ b/src/lib/chapter_selection.sh
@@ -0,0 +1,38 @@
+chapter_selection() {
+ # Novel page HTML
+ novel_page="$(gum spin --spinner line --show-output -- \
+ curl --silent --get --data-urlencode "k=${args[title]}" "${1}")"
+
+ # Chapter data
+ IFS=$'\n' read -r -d '\n' -a chapter_locations <<<"$(echo "${novel_page}" |
+ pup 'div.list-chapter a.list-group-item attr{href}')" || true
+ IFS=$'\n' read -r -d '\n' -a chapter_names <<<"$(echo "${novel_page}" |
+ pup 'div.list-chapter span.chapter-name text{}')" || true
+
+ # Chapter collection for Gum
+ chapters=""
+
+ # Fix output format for Gum
+ for ((i = 0; i < "${#chapter_locations[@]}"; i++)); do
+ chapters+="$(printf "\nChapter ${i}:%s" "${chapter_names[${i}]}")"
+ done
+
+ # Remove leading new-line
+ chapters="$(echo "${chapters}" | sed '/./,$!d')"
+
+ # Prompt for user's novel choice
+ chapter_choice="$(echo "${chapters}" | gum filter)"
+
+ # Remove chapter discriminator from chapter choice
+ chapter_choice="${chapter_choice#Chapter [0-9]*: }"
+
+ # Locate chapter choice location
+ for ((i = 0; i < "${#chapter_locations[@]}"; i++)); do
+ if [[ "${chapter_names[${i}]}" = " ${chapter_choice}" ]]; then
+ chapter_location="https://www.honeyfeed.fm${chapter_locations[${i}]}"
+ fi
+ done
+
+ # Return chapter location
+ echo "${chapter_location}"
+}