diff options
author | Yuchen Pei <id@ypei.org> | 2023-10-30 22:37:49 +1100 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2023-10-30 22:37:49 +1100 |
commit | 4b6733188057bdaada89b841303e387108e0dc0d (patch) | |
tree | bc5f758893fd144ac623839f2ddd8c6a1c028726 | |
parent | bbee0d8e36149d703eee0cfeb9583affa3f0b677 (diff) |
Add tracli-url-rewriter, a custom function variable to rewrite redirect urls
-rw-r--r-- | traclicker.el | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/traclicker.el b/traclicker.el index 2cb5f58..c6c9094 100644 --- a/traclicker.el +++ b/traclicker.el @@ -67,6 +67,14 @@ For example to avoid accidental unsubscription." :type 'regexp :group 'traclicker) +(defcustom tracli-url-rewriter 'identity + "Function to rewrite redirect url. + +A rewrite function takes a string and returns a string. It may, +for example, remove utm tracking queries." + :type 'function + :group 'traclicker) + (defun tracli-read-data () "Read data from `tracli-db-file'." (when (file-exists-p tracli-db-file) @@ -137,25 +145,26 @@ Sends a HEAD request." (with-current-buffer buffer (goto-char (point-min)) (when (re-search-forward "^Location: \\(.*\\)$" nil t) - (match-string 1))))) + (funcall tracli-url-rewriter (match-string 1)))))) (defun tracli-collect-urls () "Collect all http/https urls in the current buffer." (save-excursion - (let ((results)) + (let ((results) + (urls (alist-get 'urls tracli-data))) (while (re-search-forward org-link-plain-re nil t) (let ((scheme (match-string-no-properties 1)) (url (match-string-no-properties 0))) (when (and (member scheme '("http" "https")) (not (member url results)) (not (string-match-p tracli-exclude-url-pattern url)) - (not (gethash url (alist-get 'urls tracli-data)))) + (not (and urls (gethash url urls)))) (push url results)))) (reverse results)))) (defun tracli-get-buffer-redirect-urls () "Get a list of redirect urls in the current buffer." - (let ((parsed (tracli-parse-buffer))) + (let ((parsed (tracli-parse-buffer))) (with-temp-buffer (insert (format "%s" parsed)) (goto-char (point-min)) |