aboutsummaryrefslogtreecommitdiff
path: root/src/content.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/content.rs')
-rw-r--r--src/content.rs51
1 files changed, 25 insertions, 26 deletions
diff --git a/src/content.rs b/src/content.rs
index 0f81149..ed1d8c5 100644
--- a/src/content.rs
+++ b/src/content.rs
@@ -9,37 +9,36 @@ use cursive::theme::Effect;
9use cursive::utils::markup::StyledString; 9use cursive::utils::markup::StyledString;
10use cursive::views::Dialog; 10use cursive::views::Dialog;
11use cursive::Cursive; 11use cursive::Cursive;
12use reqwest::Url;
12use serde_json::Value; 13use serde_json::Value;
13use CONFIGURATION; 14use CONFIGURATION;
14 15
15pub fn query_url_gen(title: &str) -> String { 16pub fn query_url_gen(title: &str) -> Url {
16 // query config 17 Url::parse_with_params(
17 let mut url = CONFIGURATION.wiki_url.clone(); 18 &(CONFIGURATION.wiki_url.clone() + "/w/api.php"),
18 url.push_str("/w/api.php?"); 19 &[
19 url.push_str("action=query&"); 20 ("action", "query"),
20 url.push_str("format=json&"); 21 ("format", "json"),
21 url.push_str("prop=extracts%7Clinks&"); 22 ("prop", "extracts|links"),
22 url.push_str("indexpageids=1&"); 23 ("indexpageids", "1"),
23 url.push_str("titles="); 24 ("titles", &urlencoding::encode(&title.replace(" ", "_"))),
24 url.push_str(&urlencoding::encode(title)); 25 ("redirects", "1"),
25 url.push_str("&"); 26 ("pllimit", "100"),
26 url.push_str("redirects=1&"); 27 ("explaintext", "1"),
27 url.push_str("pllimit=100&"); 28 ],
28 url.push_str("explaintext=1"); 29 ).unwrap()
29 url
30} 30}
31 31
32pub fn search_url_gen(search: &str) -> String { 32pub fn search_url_gen(search: &str) -> Url {
33 // search config 33 Url::parse_with_params(
34 let mut url = CONFIGURATION.wiki_url.clone(); 34 &(CONFIGURATION.wiki_url.clone() + "/w/api.php"),
35 url.push_str("/w/api.php?"); 35 &[
36 url.push_str("action=opensearch&"); 36 ("action", "opensearch"),
37 url.push_str("format=json&"); 37 ("format", "json"),
38 url.push_str("search="); 38 ("search", &urlencoding::encode(search)),
39 url.push_str(&urlencoding::encode(&search)); 39 ("limit", "20"),
40 url.push_str("&"); 40 ],
41 url.push_str("limit=20"); 41 ).unwrap()
42 url
43} 42}
44 43
45pub fn get_extract(v: &Value) -> Result<String, reqwest::Error> { 44pub fn get_extract(v: &Value) -> Result<String, reqwest::Error> {