about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-11 23:18:08 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-11 23:18:08 +0100
commit7851427a39ecf4bb30b5f173aa10ee78feadec1c (patch)
treef606bb921f44c00116bea9668ce6f9f6927a4023
parent2014e1e0a89db9a09a25d477e94d6fd5bc204d0f (diff)
downloadchawan-7851427a39ecf4bb30b5f173aa10ee78feadec1c.tar.gz
Add wikipedia substitution, bookmark file keybinding
-rw-r--r--res/config.toml5
-rw-r--r--src/display/pager.nim10
2 files changed, 11 insertions, 4 deletions
diff --git a/res/config.toml b/res/config.toml
index deb7e5c9..af4a0dc9 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -22,6 +22,10 @@ force-clear = false
 url = '^ddg:'
 substitute_url = '(x) => "https://lite.duckduckgo.com/lite/?kp=-1&kd=-1&q=" + x.substring(4)'
 
+[[siteconf]]
+url = '^wk:'
+substitute_url = '(x) => "https://en.wikipedia.org/wiki/Special:Search?search=" + x.substring(4)'
+
 [page]
 q = 'quit()'
 h = 'pager.cursorLeft()' 
@@ -63,6 +67,7 @@ C-j = 'pager.click()'
 M-u = 'pager.dupeBuffer()'
 C-l = 'pager.load()'
 C-k = 'pager.load("ddg:")'
+M-b = 'pager.load("~/.w3m/bookmark.html\n")'
 U = 'pager.reload()'
 r = 'pager.redraw()'
 R = 'pager.reshape()'
diff --git a/src/display/pager.nim b/src/display/pager.nim
index 464e7323..765e1e73 100644
--- a/src/display/pager.nim
+++ b/src/display/pager.nim
@@ -513,10 +513,12 @@ proc loadURL*(pager: Pager, url: string, ctype = none(string)) =
     pager.gotoURL(newRequest(firstparse.get), prev, ctype)
     return
   var urls: seq[URL]
-  let pageurl = parseURL("https://" & url)
-  if pageurl.isSome: # attempt to load remote page
-    urls.add(pageurl.get)
+  if url[0] != '/':
+    let pageurl = parseURL("https://" & url)
+    if pageurl.isSome: # attempt to load remote page
+      urls.add(pageurl.get)
   let cdir = parseURL("file://" & getCurrentDir() & DirSep)
+  let url = if url[0] == '~': expandPath(url) else: url
   let purl = percentEncode(url, LocalPathPercentEncodeSet)
   if purl != url:
     let newurl = parseURL(purl, cdir)
@@ -631,7 +633,7 @@ proc updateReadLine*(pager: Pager) =
 # Open a URL prompt and visit the specified URL.
 proc load(pager: Pager, s = "") {.jsfunc.} =
   if s.len > 0 and s[^1] == '\n':
-    pager.loadURL(s)
+    pager.loadURL(s[0..^2])
   else:
     var url = s
     if url == "":