From 56978223eb8f9f7de774a18f62023c5f6ecc31ee Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 9 Feb 2022 01:10:56 -0800 Subject: [nyxt] Add function that redirects some URLs to free alternatives --- nyxt/.config/nyxt/init.lisp.org | 71 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 6 deletions(-) (limited to 'nyxt/.config') 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/. -- cgit v1.2.3-54-g00ecf