searchlink 2.3.93 → 2.3.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/searchlink/exceptions.rb +7 -7
- data/lib/searchlink/searches/keenable.rb +89 -0
- data/lib/searchlink/searches.rb +17 -12
- data/lib/searchlink/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f49b8784f92c34246bfb67f5adf770325ca343de1d2a935946dc5d3791a46237
|
|
4
|
+
data.tar.gz: e94c2bb8368201da8272caf3ed45308e694f527ad892513f95338b9b91f47ca3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: da81a868d12f0d8ab47c0c832c9f1b8346eb7a253f0f65bdc9980efe394f55a1a873f68b14f77c65c39b8bf20270463b1a5e39bd5f85a470890fa9173dc4ebe7
|
|
7
|
+
data.tar.gz: 673affa6a19aa176be08a88d245b0255925c54cb1164b0c8dc81e09855cfaec299c0e6f3e51c64cb7a64e43590610497c6ec4ebb9fa96d997b0c7022b60da2c0
|
|
@@ -5,25 +5,25 @@ module SL
|
|
|
5
5
|
class VersionError < StandardError
|
|
6
6
|
def initialize(msg)
|
|
7
7
|
msg = msg ? ": #{msg}" : ""
|
|
8
|
-
|
|
8
|
+
warn "Versioning error#{msg}"
|
|
9
9
|
|
|
10
|
-
super()
|
|
10
|
+
super("Versioning error#{msg}")
|
|
11
11
|
|
|
12
12
|
Process.exit 1
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
# Custom plugin error
|
|
16
|
+
# Custom plugin error. Does not abort the process; callers that load
|
|
17
|
+
# optional plugins should rescue this and continue.
|
|
17
18
|
class PluginError < StandardError
|
|
18
19
|
def initialize(msg = nil, plugin: nil)
|
|
19
20
|
plugin = %("#{plugin}") if plugin
|
|
20
21
|
plugin ||= "plugin"
|
|
21
22
|
msg = ": #{msg}" if msg
|
|
22
|
-
|
|
23
|
+
message = "Error in #{plugin}#{msg}"
|
|
24
|
+
warn message
|
|
23
25
|
|
|
24
|
-
super()
|
|
25
|
-
|
|
26
|
-
Process.exit 1
|
|
26
|
+
super(message)
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SL
|
|
4
|
+
# Keenable web search
|
|
5
|
+
class KeenableSearch
|
|
6
|
+
class << self
|
|
7
|
+
# Returns the settings hash for the KeenableSearch plugin.
|
|
8
|
+
#
|
|
9
|
+
# @return [Hash] settings including trigger, searches, and config entries
|
|
10
|
+
#
|
|
11
|
+
def settings
|
|
12
|
+
{
|
|
13
|
+
trigger: "kn",
|
|
14
|
+
searches: [
|
|
15
|
+
["kn", "Keenable Search"]
|
|
16
|
+
],
|
|
17
|
+
config: [
|
|
18
|
+
{
|
|
19
|
+
key: "keenable_api_key",
|
|
20
|
+
value: "xxxxxx",
|
|
21
|
+
required: false,
|
|
22
|
+
description: "Keenable API key for web search (see https://keenable.ai)"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Returns true if a usable Keenable API key is configured.
|
|
29
|
+
#
|
|
30
|
+
# @return [Boolean] true when a non-placeholder API key is present
|
|
31
|
+
#
|
|
32
|
+
def api_key?
|
|
33
|
+
return false unless SL.config.key?("keenable_api_key") && SL.config["keenable_api_key"]
|
|
34
|
+
|
|
35
|
+
key = SL.config["keenable_api_key"].to_s.strip
|
|
36
|
+
return false if key.empty? || key =~ /^(x{4,})?$/i
|
|
37
|
+
|
|
38
|
+
@api_key = key
|
|
39
|
+
|
|
40
|
+
true
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Perform a Keenable web search and return the first result.
|
|
44
|
+
#
|
|
45
|
+
# @param _search_type [String] the search shortcut ("kn")
|
|
46
|
+
# @param search_terms [String] the terms to search for
|
|
47
|
+
# @param link_text [String] the text to display for the link
|
|
48
|
+
#
|
|
49
|
+
# @return [Array] [url, title, link_text] or DuckDuckGo fallback
|
|
50
|
+
#
|
|
51
|
+
def search(_search_type, search_terms, link_text)
|
|
52
|
+
unless api_key?
|
|
53
|
+
SL.notify("Keenable not configured", "Missing Keenable API key, defaulting to DuckDuckGo")
|
|
54
|
+
return SL.ddg(search_terms, link_text, google: false)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
headers = {
|
|
58
|
+
"X-API-Key" => @api_key,
|
|
59
|
+
"X-Keenable-Title" => "SearchLink",
|
|
60
|
+
"Content-Type" => "application/json"
|
|
61
|
+
}
|
|
62
|
+
# Curl::Json passes the body inside single quotes; escape them as JSON.
|
|
63
|
+
body = { query: search_terms.gsub("%22", '"'), max_results: 1 }.to_json.gsub("'", "\\u0027")
|
|
64
|
+
|
|
65
|
+
res = Curl::Json.new("https://api.keenable.ai/v1/search", data: body, headers: headers, symbolize_names: true)
|
|
66
|
+
return SL.ddg(search_terms, link_text, google: false) unless res && res.code.to_i == 200 && res.json
|
|
67
|
+
|
|
68
|
+
results = res.json[:results]
|
|
69
|
+
first = results.is_a?(Array) ? results.find { |r| r.is_a?(Hash) && r[:url] } : nil
|
|
70
|
+
return SL.ddg(search_terms, link_text, google: false) unless first
|
|
71
|
+
|
|
72
|
+
output_url = first[:url]
|
|
73
|
+
output_title = first[:title] || link_text
|
|
74
|
+
|
|
75
|
+
if defined?(SL.config) && SL.config.respond_to?(:[]) && output_title && SL.config["remove_seo"]
|
|
76
|
+
output_title.remove_seo!(output_url)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
[output_url, output_title, link_text]
|
|
80
|
+
rescue StandardError => e
|
|
81
|
+
SL.notify("Keenable error", "Error fetching Keenable results, switching to DuckDuckGo")
|
|
82
|
+
SL.add_error("Keenable error", e.message)
|
|
83
|
+
SL.ddg(search_terms, link_text, google: false)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
SL::Searches.register "keenable", :search, self
|
|
88
|
+
end
|
|
89
|
+
end
|
data/lib/searchlink/searches.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module SL
|
|
4
4
|
# Searches and plugin registration
|
|
5
|
+
# rubocop:disable Metrics/ModuleLength
|
|
5
6
|
module Searches
|
|
6
7
|
class << self
|
|
7
8
|
def plugins
|
|
@@ -132,27 +133,24 @@ module SL
|
|
|
132
133
|
plugins_folder = File.expand_path("~/.local/searchlink/plugins")
|
|
133
134
|
new_plugins_folder = File.expand_path("~/.config/searchlink/plugins")
|
|
134
135
|
|
|
135
|
-
if File.directory?(plugins_folder) && !File.directory?(new_plugins_folder)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
load_custom_scripts(plugins_folder)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
return unless File.directory?(new_plugins_folder)
|
|
136
|
+
load_custom_folder(plugins_folder) if File.directory?(plugins_folder) && !File.directory?(new_plugins_folder)
|
|
137
|
+
load_custom_folder(new_plugins_folder) if File.directory?(new_plugins_folder)
|
|
138
|
+
end
|
|
144
139
|
|
|
145
|
-
|
|
140
|
+
def load_custom_folder(plugins_folder)
|
|
141
|
+
Dir.glob(File.join(plugins_folder, "**/*.rb")).sort.each do |plugin|
|
|
146
142
|
require plugin
|
|
143
|
+
rescue PluginError, LoadError, StandardError => e
|
|
144
|
+
warn "Skipping plugin #{File.basename(plugin)}: #{e.message}"
|
|
147
145
|
end
|
|
148
146
|
|
|
149
|
-
load_custom_scripts(
|
|
147
|
+
load_custom_scripts(plugins_folder)
|
|
150
148
|
end
|
|
151
149
|
|
|
152
150
|
def load_custom_scripts(plugins_folder)
|
|
153
151
|
Dir.glob(File.join(plugins_folder, "**/*.{json,yml,yaml}")).each do |file|
|
|
154
152
|
ext = File.extname(file).sub(/^\./, "")
|
|
155
|
-
config =
|
|
153
|
+
config = File.read(file)
|
|
156
154
|
|
|
157
155
|
cfg = case ext
|
|
158
156
|
when /^y/i
|
|
@@ -163,6 +161,9 @@ module SL
|
|
|
163
161
|
cfg["filename"] = File.basename(file)
|
|
164
162
|
cfg["path"] = file.shorten_path
|
|
165
163
|
SL::ScriptSearch.new(cfg)
|
|
164
|
+
rescue PluginError, JSON::ParserError, Psych::SyntaxError => e
|
|
165
|
+
warn "Skipping plugin #{File.basename(file)}: #{e.message}"
|
|
166
|
+
next
|
|
166
167
|
end
|
|
167
168
|
end
|
|
168
169
|
|
|
@@ -179,6 +180,7 @@ module SL
|
|
|
179
180
|
end
|
|
180
181
|
end
|
|
181
182
|
end
|
|
183
|
+
# rubocop:enable Metrics/ModuleLength
|
|
182
184
|
end
|
|
183
185
|
|
|
184
186
|
# import
|
|
@@ -205,6 +207,9 @@ require_relative "searches/github"
|
|
|
205
207
|
# import
|
|
206
208
|
require_relative "searches/kagi"
|
|
207
209
|
|
|
210
|
+
# import
|
|
211
|
+
require_relative "searches/keenable"
|
|
212
|
+
|
|
208
213
|
# import
|
|
209
214
|
require_relative "searches/google"
|
|
210
215
|
|
data/lib/searchlink/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: searchlink
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.3.
|
|
4
|
+
version: 2.3.95
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brett Terpstra
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -302,6 +302,7 @@ files:
|
|
|
302
302
|
- lib/searchlink/searches/hook.rb
|
|
303
303
|
- lib/searchlink/searches/itunes.rb
|
|
304
304
|
- lib/searchlink/searches/kagi.rb
|
|
305
|
+
- lib/searchlink/searches/keenable.rb
|
|
305
306
|
- lib/searchlink/searches/lastfm.rb
|
|
306
307
|
- lib/searchlink/searches/linkding.rb
|
|
307
308
|
- lib/searchlink/searches/lyrics.rb
|