From 39a902d38519128e137bedeaef2a3d042508e49d Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Sat, 11 Jul 2020 12:15:45 +0200 Subject: [PATCH] Nyxt: Replace old handlers with url-dispatching-handlers. --- .config/nyxt/init.lisp | 74 ++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/.config/nyxt/init.lisp b/.config/nyxt/init.lisp index 466fba7c..3c6f13f9 100644 --- a/.config/nyxt/init.lisp +++ b/.config/nyxt/init.lisp @@ -49,36 +49,34 @@ (defvar +youtube-dl-command+ "youtube-dl" "Path to the 'youtube-dl' program.") -(defun auto-yt-dl-handler (url) - "Download a Youtube URL asynchronously to /tmp/videos/. -Videos are downloaded with `+youtube-dl-command+'." - (let ((uri (quri:uri url))) - (when (and uri - (member-string (quri:uri-domain uri) '("youtube.com" "youtu.be")) - (string= (quri:uri-path uri) "/watch")) - (log:info "Youtube: downloading ~a" url) - (uiop:launch-program (list +youtube-dl-command+ url "-o" "/tmp/videos/%(title)s.%(ext)s")))) - url) +;; (defun auto-yt-dl-handler (url) +;; "Download a Youtube URL asynchronously to /tmp/videos/. +;; Videos are downloaded with `+youtube-dl-command+'." +;; (let ((uri (quri:uri url))) +;; (when (and uri +;; (member-string (quri:uri-domain uri) '("youtube.com" "youtu.be")) +;; (string= (quri:uri-path uri) "/watch")) +;; (log:info "Youtube: downloading ~a" url) +;; (uiop:launch-program (list +youtube-dl-command+ url "-o" "/tmp/videos/%(title)s.%(ext)s")))) +;; url) -(defun old-reddit-handler (request-data) - (let ((uri (url request-data))) - (setf (url request-data) - (if (search "reddit.com" (quri:uri-host uri)) - (progn - (setf (quri:uri-host uri) "old.reddit.com") - (log:info "Switching to old Reddit: ~s" (object-display uri)) - uri) - uri))) - request-data) +(defparameter old-reddit-handler + (url-dispatching-handler + 'old-reddit-dispatcher + (match-host "www.reddit.com") + (lambda (url) + (quri:copy-uri url :host "old.reddit.com")))) -(defun magnet-handler (request-data) - (let ((uri (url request-data))) - (if (string= (quri:uri-scheme uri) "magnet") - (progn - (echo "Opened magnet link in Transmission.") - (uiop:launch-program (list "transmission-remote" "--add" (object-string uri))) - nil) - request-data))) +(defparameter magnet-handler + (url-dispatching-handler + 'transmission-magnet-links + (match-scheme "magnet") + (lambda (url) + (uiop:launch-program + (list "transmission-remote" "--add" + (object-string url))) + (echo "Magnet link opened in Transmission.") + nil))) (defvar *my-unproxied-domains* '("jit.si" @@ -105,24 +103,22 @@ Videos are downloaded with `+youtube-dl-command+'." (define-configuration nyxt/blocker-mode:blocker-mode ((nyxt/blocker-mode:hostlists (append (list *my-blocked-hosts*) %slot-default)))) -;; (define-mode my-blocker-mode (nyxt/blocker-mode:blocker-mode) -;; "Blocker mode with custom hosts from `*my-blocked-hosts*'." -;; ((nyxt/blocker-mode:hostlists :initform (list *my-blocked-hosts* nyxt/blocker-mode:*default-hostlist*)))) +(define-mode my-blocker-mode (nyxt/blocker-mode:blocker-mode) + "Blocker mode with custom hosts from `*my-blocked-hosts*'." + ((nyxt/blocker-mode:hostlists :initform (list *my-blocked-hosts* nyxt/blocker-mode:*default-hostlist*)))) (define-configuration buffer ((default-modes (append - '(my-mode vi-normal-mode - ;; my-blocker-mode - blocker-mode + '(my-mode ;; proxy-mode - ) + ;; blocker-mode + my-blocker-mode + vi-normal-mode) %slot-default)) (request-resource-hook (reduce #'hooks:add-hook - (mapcar #'make-handler-resource (list - ;; #'auto-proxy-handler - #'magnet-handler - #'old-reddit-handler)) + (list magnet-handler + old-reddit-handler) :initial-value %slot-default)))) (defun format-c->lisp (s)