diff options
| -rw-r--r-- | url-rewrite.el | 13 | 
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"))  | 
