-
Notifications
You must be signed in to change notification settings - Fork 3
/
bibliogram-handler.lisp
59 lines (49 loc) · 2.43 KB
/
bibliogram-handler.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
;;;; freestance-handler, a redirector from mainstream websites to their
;;;; privacy-supporting mirrors for the Nyxt browser
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU General Public License for more details.
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;;; bibliogram-handler.lisp
(in-package :nx-freestance-handler)
(defvar *preferred-bibliogram-instance* nil)
(defun bibliogram-handler (request-data)
(let ((url (url request-data)))
(setf (url request-data)
(if (search "instagram.com" (quri:uri-host url))
(progn
(setf (quri:uri-host url) (or *preferred-bibliogram-instance*
"bibliogram.art"))
(if (and (< 0 (length (quri:uri-path url)))
(not (str:starts-with? "/p/" (quri:uri-path url))))
(setf (quri:uri-path url)
(concatenate 'string "/u" (quri:uri-path url))))
(log:info "Switching to Bibliogram: ~s" (render-url url))
url)
url)))
request-data)
#+nyxt-2
(in-package :nyxt)
#+nyxt-2
(define-command set-preferred-bibliogram-instance ()
"Set the preferred Bibliogram instance."
(let ((instance (prompt-minibuffer
:input-prompt "Input the URL of the instance"
:suggestion-function (history-suggestion-filter
:prefix-urls (list (object-string
(url (current-buffer))))))))
(setf nx-freestance-handler:*preferred-bibliogram-instance* instance)))
#+nyxt-3
(define-command-global set-preferred-bibliogram-instance ()
"Set the preferred Bibliogram instance."
(let ((instance (prompt
:prompt "Input the URL of the instance"
:sources (list (make-instance 'prompter:raw-source)
(make-instance 'nyxt/history-mode:history-all-source)))))
(setf nx-freestance-handler:*preferred-bibliogram-instance* instance)))