aboutsummaryrefslogtreecommitdiff
path: root/src
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
downloadnectar-92ee80008474f0af84798dd231e4d25cd61f929b.tar.xz
nectar-92ee80008474f0af84798dd231e4d25cd61f929b.zip
feat: initial releasev0.1.0
Diffstat (limited to 'src')
-rw-r--r--src/bashly.yml34
-rw-r--r--src/chapter_command.sh1
-rw-r--r--src/lib/chapter_reader.sh13
-rw-r--r--src/lib/chapter_selection.sh38
-rw-r--r--src/novel_command.sh5
-rw-r--r--src/search_command.sh44
6 files changed, 135 insertions, 0 deletions
diff --git a/src/bashly.yml b/src/bashly.yml
new file mode 100644
index 0000000..80e8132
--- /dev/null
+++ b/src/bashly.yml
@@ -0,0 +1,34 @@
+name: nectar
+help: Command-line Honeyfeed Reader
+version: 0.1.0
+
+commands:
+ - name: chapter
+ alias: c
+ help: Read a chapter directly in your terminal
+ dependencies: [gum, curl, pup, pandoc, echo, glow]
+
+ args:
+ - name: id
+ help: The ID of the target chapter
+ required: true
+
+ - name: novel
+ alias: n
+ help: Select a chapter to read directly in your terminal
+ dependencies: [gum, curl, pup, pandoc, echo, glow]
+
+ args:
+ - name: id
+ help: The ID of the target novel
+ required: true
+
+ - name: search
+ alias: s
+ help: Search and select a novel to read directly in your terminal
+ dependencies: [gum, curl, pup, pandoc, echo, glow]
+
+ args:
+ - name: title
+ help: A partial title of the target novel
+ required: true
diff --git a/src/chapter_command.sh b/src/chapter_command.sh
new file mode 100644
index 0000000..6660810
--- /dev/null
+++ b/src/chapter_command.sh
@@ -0,0 +1 @@
+chapter_reader "https://www.honeyfeed.fm/chapters/${args[id]}"
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}"
+}
diff --git a/src/novel_command.sh b/src/novel_command.sh
new file mode 100644
index 0000000..ccd66e2
--- /dev/null
+++ b/src/novel_command.sh
@@ -0,0 +1,5 @@
+# Obtain user's chapter choice
+chapter_location="$(chapter_selection "https://www.honeyfeed.fm/novels/${args[id]}")"
+
+# Display chapter
+chapter_reader "${chapter_location}"
diff --git a/src/search_command.sh b/src/search_command.sh
new file mode 100644
index 0000000..8817c97
--- /dev/null
+++ b/src/search_command.sh
@@ -0,0 +1,44 @@
+# Search page HTML
+search_page="$(gum spin --spinner line --show-output -- \
+ curl --silent --get --data-urlencode "k=${args[title]}" \
+ "https://www.honeyfeed.fm/search/novel_title")"
+
+# Novel data
+IFS=$'\n' read -r -d '\n' -a novel_locations <<<"$(echo "${search_page}" |
+ pup 'div.novel-unit-type-h a.a-img-hover attr{href}')" || true
+IFS=$'\n' read -r -d '\n' -a novel_names <<<"$(echo "${search_page}" |
+ pup 'h3.novel-name text{}')" || true
+# IFS=$'\n' read -r -d '\n' -a novel_update_dates <<<"$(echo "${search_page}" |
+# pup 'div.information-unit-novel span:not([class]) text{}')" || true
+# IFS=$'\n' read -r -d '\n' -a novel_chapter_counts <<<"$(echo "${search_page}" |
+# pup 'div.information-unit-novel div.flex div:not([class]) text{}')" || true
+# IFS=$'\n' read -r -d '\n' -a novel_statuses <<<"$(echo "${search_page}" |
+# pup 'div.information-unit-novel div.flex div.wrap-publish-status text{}')" ||
+# true
+
+# Novel collection for Gum
+novels=""
+
+# Fix output format for Gum
+for ((i = 0; i < "${#novel_locations[@]}"; i++)); do
+ novels+="$(printf "\n%s" "${novel_names[${i}]}")"
+done
+
+# Remove leading new-line
+novels="$(echo "${novels}" | sed '/./,$!d')"
+
+# Prompt for user's novel choice
+novel_choice="$(echo "${novels}" | gum filter)"
+
+# Locate novel choice location
+for ((i = 0; i < "${#novel_locations[@]}"; i++)); do
+ if [[ "${novel_names[${i}]}" = "${novel_choice}" ]]; then
+ novel_location="https://www.honeyfeed.fm${novel_locations[${i}]}"
+ fi
+done
+
+# Obtain user's chapter choice
+chapter_location="$(chapter_selection "${novel_location}")"
+
+# Display chapter
+chapter_reader "${chapter_location}"