searchlink 2.3.93 → 2.3.94
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/searches/keenable.rb +89 -0
- data/lib/searchlink/searches.rb +3 -0
- 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: db8c6a0ca4005dab57850ac6073c79ccb8af7a716dc2abbdca7c28e56236152d
|
|
4
|
+
data.tar.gz: 3dac8559336062734a5d207dae3478f6075198d3f2547b2500c3b511b038bce2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f8c8eaac79f1fa31bc44489911fe432575c435bf801c528fea7b19afa72bba273fac0f5469bc552eee38f17353bdc2a732a95a60821c61aa12b999e04ab41e7b
|
|
7
|
+
data.tar.gz: ecc834af5225f72159ff21dd68d03f598ff611dd1f43b98006481e5b2157cf08376d020074c7e281c2f6bd6663f6d231cef068f512ac9830df34760d291e1bf2
|
|
@@ -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
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.94
|
|
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-03 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
|