aboutsummaryrefslogtreecommitdiffstats
path: root/nyxt
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-02-09 01:10:56 -0800
committerGravatar Tom Willemse2022-02-09 01:10:56 -0800
commit56978223eb8f9f7de774a18f62023c5f6ecc31ee (patch)
treeca17fa3f035a91534e72044e08db2a50d3112014 /nyxt
parentadda08ef4a09ae0370b031eba489199a8ec09eb4 (diff)
downloadnew-dotfiles-56978223eb8f9f7de774a18f62023c5f6ecc31ee.tar.gz
new-dotfiles-56978223eb8f9f7de774a18f62023c5f6ecc31ee.zip
[nyxt] Add function that redirects some URLs to free alternatives
Diffstat (limited to 'nyxt')
-rw-r--r--nyxt/.config/nyxt/init.lisp.org71
1 files changed, 65 insertions, 6 deletions
diff --git a/nyxt/.config/nyxt/init.lisp.org b/nyxt/.config/nyxt/init.lisp.org
index 33dcf84..484d8ff 100644
--- a/nyxt/.config/nyxt/init.lisp.org
+++ b/nyxt/.config/nyxt/init.lisp.org
@@ -5,16 +5,75 @@ Always restore the previous session when the browser starts.
((session-restore-prompt :always-restore)))
#+end_src
+Add a function that automatically redirects certain URLs to free alternatives.
+
+#+begin_src lisp
+ (defun init-redirect-to-alternative (request-data)
+ (labels ((log-uri (uri)
+ (log:info "Switching to URL: ~a://~a~a"
+ (quri:uri-scheme uri)
+ (quri:uri-host uri)
+ (quri:uri-path uri))))
+ (let* ((uri (url request-data))
+ (host (quri:uri-host uri)))
+ (cond
+ ((search "blog.bitsrc.io" host)
+ (setf (url request-data)
+ (progn
+ (setf (quri:uri-host uri) "scribe.rip"
+ (quri:uri-path uri) (concatenate 'string "/bitsrc" (quri:uri-path uri)))
+ (log-uri uri)
+ uri)))
+ ((search "levelup.gitconnected.com" host)
+ (setf (url request-data)
+ (progn
+ (setf (quri:uri-host uri) "scribe.rip"
+ (quri:uri-path uri) (concatenate 'string "/gitconnected" (quri:uri-path uri)))
+ (log-uri uri)
+ uri)))
+ ((or (search "kevingosse.medium.com" host)
+ (search "minidump.net" host))
+ (setf (url request-data)
+ (progn
+ (setf (quri:uri-host uri) "scribe.rip"
+ (quri:uri-path uri) (concatenate 'string "/kevingosse" (quri:uri-path uri)))
+ (log-uri uri)
+ uri)))
+ ((search "medium.com" host :end2 (length "medium.com"))
+ (setf (url request-data)
+ (progn
+ (setf (quri:uri-host uri) "scribe.rip")
+ (log-uri uri)
+ uri)))
+ ((search "twitter.com" host)
+ (setf (url request-data)
+ (progn
+ (setf (quri:uri-host uri) "nitter.net")
+ (log-uri uri)
+ uri)))
+ ((search "www.youtube.com" host)
+ (setf (url request-data)
+ (progn
+ (setf (quri:uri-host uri) "redirect.invidious.io")
+ (log-uri uri)
+ uri))))))
+ request-data)
+#+end_src
+
I want the keys to function more like Emacs, so I enable =emacs-mode= for all buffers. I also want my downloads to go to =~/downloads= instead of =~/Downloads=.
#+begin_src lisp
(define-configuration buffer
- ((default-modes (append '(emacs-mode) %slot-default%))
- (download-path (make-instance 'data-path :dirname "~/downloads"))
- ;; Bind org-capture to `C-c o c', but only in emacs-mode.
- (override-map
- (let ((map (make-keymap "override-map")))
- (define-key map "C-c o c" 'org-capture)))))
+ ((default-modes (append '(emacs-mode) %slot-default%))
+ (download-path (make-instance 'data-path :dirname "~/downloads"))
+ (request-resource-hook
+ (reduce #'hooks:add-hook
+ (mapcar #'make-handler-resource (list #'init-redirect-to-alternative))
+ :initial-value %slot-default%))
+ ;; Bind org-capture to `C-c o c', but only in emacs-mode.
+ (override-map
+ (let ((map (make-keymap "override-map")))
+ (define-key map "C-c o c" 'org-capture)))))
#+end_src
Set up capturing URLs with org-capture in Emacs. From https://ag91.github.io/blog/2021/07/09/org-capture-in-nyxt-taking-notes-while-browsing/.