aboutsummaryrefslogtreecommitdiff
path: root/url-rewrite.el
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-11-01 23:31:25 +1100
committerYuchen Pei <id@ypei.org>2023-11-01 23:31:25 +1100
commit4868ad66a1e2b1442b5c64ce94250e9b18889f2f (patch)
tree6e26bdfee7c3ad22c4c2e5b0b1e335073a7af82b /url-rewrite.el
parent871c39fcf3a6b35e8df4013d60e43a8bccadb672 (diff)
Add an example to download google docs as odtHEADmaster
Diffstat (limited to 'url-rewrite.el')
-rw-r--r--url-rewrite.el13
1 files changed, 13 insertions, 0 deletions
diff --git a/url-rewrite.el b/url-rewrite.el
index 8fd2028..e3d2f2b 100644
--- a/url-rewrite.el
+++ b/url-rewrite.el
@@ -129,6 +129,13 @@ QUERIES-TO-REMOVE is a regexp."
"Replace host in URLOBJ with NEW-HOST in place."
(setf (url-host urlobj) new-host))
+(defun url-rw-replace-path-regexp (urlobj regexp rep)
+ "Replace REGEXP in the path of URLOBJ with REP in place."
+ (pcase-let ((`(,path . ,query) (url-path-and-query urlobj)))
+ (setf (url-filename urlobj)
+ (concat (replace-regexp-in-string regexp rep path)
+ (when query (concat "?" query))))))
+
(defun url-rw-replace-path (urlobj new-path)
"Replace the path of URLOBJ with NEW-PATH in place."
(pcase-let ((`(_ . ,query) (url-path-and-query urlobj)))
@@ -229,6 +236,12 @@ has exceeded `url-rw-max-rewrites', stop."
:match (concat url-rw-www-re (rx "google.com/search?q="))
:actions ((replace-host "html.duckduckgo.com")
(replace-path "/html")))
+ (:name google-docs-odt
+ :description "Download Google docs document as odt."
+ :match (concat url-rw-www-re (rx "docs.google.com/document/d/"))
+ :actions ((replace-path-regexp "\\(/document/d/.*?\\)/.*"
+ "\\1/export")
+ (put-query "format" "odt")))
(:name reddit-to-old
:description "Reddit to old Reddit"
:match (concat url-rw-www-re (rx "reddit.com"))